]> granicus.if.org Git - postgis/commitdiff
GeometryN and InteriorRingN changed to use LWGEOM format (and the
authorSandro Santilli <strk@keybit.net>
Fri, 31 Dec 2004 12:44:41 +0000 (12:44 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 31 Dec 2004 12:44:41 +0000 (12:44 +0000)
latter made OGC-strict).

git-svn-id: http://svn.osgeo.org/postgis/trunk@1211 b70326c6-7e19-0410-871a-916f4a2858ee

lwgeom/BBOXCACHE_BEHAVIOURS
lwgeom/lwgeom_ogc.c

index e9cecb1002f76a8151aa72059a10c45eb457a47b..b273fd29c52256e0f29f2d333435bc975671167c 100644 (file)
@@ -67,8 +67,8 @@ points where some BBOX caching strategies could be enforced).
        PointOnSurface(geometry) *LWG*
 
 [ TAINING ]
-       GeometryN(geometry,integer) *SRL*
-       InteriorRingN(geometry,integer) *SRL*
+       GeometryN(geometry,integer) *LWG*
+       InteriorRingN(geometry,integer) *LWG*
        simplify(geometry, float8) *SRL* *EXP*
 
        #### could use WHEN_SIMPLE
index 34d9a7f5bd976973fcfb61ce55b92bdbbc508f76..f939e3f58a79d0b52a2af5340d9b1ccf40ce7db2 100644 (file)
@@ -222,8 +222,8 @@ Datum LWGEOM_geometryn_collection(PG_FUNCTION_ARGS)
        PG_LWGEOM *result;
        int type = lwgeom_getType(geom->type);
        int32 idx;
-       char *serialized;
-       char *subgeom;
+       LWCOLLECTION *coll;
+       LWGEOM *subgeom;
 
        //elog(NOTICE, "GeometryN called");
 
@@ -235,25 +235,23 @@ Datum LWGEOM_geometryn_collection(PG_FUNCTION_ARGS)
        }
 
        idx = PG_GETARG_INT32(1);
-       serialized = SERIALIZED_FORM(geom);
-
        idx -= 1; // index is 1-based
+
+       coll = lwcollection_deserialize(SERIALIZED_FORM(geom));
+
        if ( idx < 0 ) PG_RETURN_NULL();
-       if ( idx >= lwgeom_getnumgeometries(serialized) ) PG_RETURN_NULL();
+       if ( idx >= coll->ngeoms ) PG_RETURN_NULL();
 
-       subgeom = lwgeom_getsubgeometry(serialized, idx);
-       if ( subgeom == NULL )
-       {
-               //elog(NOTICE, "geometryn: subgeom %d does not exist", idx);
-               PG_RETURN_NULL();
-       }
+       subgeom = coll->geoms[idx];
+       subgeom->SRID = coll->SRID;
+
+       //COMPUTE_BBOX==TAINTING
+       if ( coll->bbox ) lwgeom_addBBOX(subgeom);
 
-       // we have it, not it's time to make an PG_LWGEOM
+       result = pglwgeom_serialize(subgeom);
 
-       // Here is the actual of the line
-       result = PG_LWGEOM_construct(subgeom, lwgeom_getSRID(geom), lwgeom_hasBBOX(geom->type));
+       lwgeom_release((LWGEOM *)coll);
 
-       //elog(NOTICE, "geomtryN about to return");
        PG_RETURN_POINTER(result);
 
 }
@@ -412,45 +410,42 @@ Datum LWGEOM_interiorringn_polygon(PG_FUNCTION_ARGS)
 
        wanted_index = PG_GETARG_INT32(1);
        if ( wanted_index < 1 )
+       {
+               //elog(ERROR, "InteriorRingN: ring number is 1-based");
                PG_RETURN_NULL(); // index out of range
+       }
 
        geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-       inspected = lwgeom_inspect(SERIALIZED_FORM(geom));
 
-       for (i=0; i<inspected->ngeometries; i++)
+       poly = lwpoly_deserialize(SERIALIZED_FORM(geom));
+       if ( ! poly )
        {
-               poly = lwgeom_getpoly_inspected(inspected, i);
-               if ( poly ) break;
+               elog(ERROR, "InteriorRingN: geom is not a polygon");
+               PG_RETURN_NULL();
        }
 
-       if ( poly == NULL ) PG_RETURN_NULL();
-
        // Ok, now we have a polygon. Let's see if it has enough holes
        if ( wanted_index >= poly->nrings )
        {
-               pfree_inspected(inspected);
+               lwgeom_release((LWGEOM *)poly);
                PG_RETURN_NULL();
        }
-       pfree_inspected(inspected);
 
        ring = poly->rings[wanted_index];
 
-       // If input geometry did have a bounding box
-       // compute the new one
-       if ( TYPE_HASBBOX(geom->type) ) bbox = ptarray_compute_bbox(ring);
+       // COMPUTE_BBOX==TAINTING
+       if ( poly->bbox ) bbox = ptarray_compute_bbox(ring);
 
        // This is a LWLINE constructed by interior ring POINTARRAY
        line = lwline_construct(poly->SRID, bbox, ring);
 
-       // Now we serialized it (copying data)
-       serializedline = lwline_serialize(line);
+       // Copy SRID from polygon
+       line->SRID = poly->SRID;
 
-       // And we construct the line (copy again)
-       result = PG_LWGEOM_construct(serializedline, lwgeom_getSRID(geom),
-               bbox?1:0);
+       result = pglwgeom_serialize(line);
 
-       pfree(serializedline);
-       pfree(line);
+       lwgeom_release((LWGEOM *)line);
+       lwgeom_release((LWGEOM *)poly);
 
        PG_RETURN_POINTER(result);
 }