]> granicus.if.org Git - postgis/commitdiff
Add support for simple geometries in ST_GeometryN and ST_NumGeometries
authorSandro Santilli <strk@keybit.net>
Fri, 12 Mar 2010 13:50:22 +0000 (13:50 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 12 Mar 2010 13:50:22 +0000 (13:50 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@5423 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_ogc.c
regress/regress_ogc.sql
regress/regress_ogc_expected

index 63d9257d563c3a74be35e4408cf5d17f2c19d409..20d029763b3e06ced2bdf8c99f23c5a97a9aba44 100644 (file)
@@ -303,7 +303,7 @@ Datum LWGEOM_numgeometries_collection(PG_FUNCTION_ARGS)
                PG_RETURN_INT32(ret);
        }
        PG_FREE_IF_COPY(geom, 0);
-       PG_RETURN_NULL();
+       PG_RETURN_INT32(1);
 }
 
 /** 1-based offset */
@@ -321,17 +321,17 @@ Datum LWGEOM_geometryn_collection(PG_FUNCTION_ARGS)
 
        /* elog(NOTICE, "GeometryN called"); */
 
+       idx = PG_GETARG_INT32(1);
+       idx -= 1; /* index is 1-based */
+
        /* call is valid on multi* geoms only */
        if (type==POINTTYPE || type==LINETYPE || type==CIRCSTRINGTYPE ||
                type==COMPOUNDTYPE || type==POLYGONTYPE || type==CURVEPOLYTYPE)
        {
-               /* elog(NOTICE, "geometryn: geom is of type %d, requires >=4", type); */
+               if ( idx == 0 ) PG_RETURN_POINTER(geom);
                PG_RETURN_NULL();
        }
 
-       idx = PG_GETARG_INT32(1);
-       idx -= 1; /* index is 1-based */
-
        coll = (LWCOLLECTION *)lwgeom_deserialize(SERIALIZED_FORM(geom));
 
        if ( idx < 0 ) PG_RETURN_NULL();
index aff71d292d9761e8c68ae8a00518aefc0935a720..4928a98f97c81f40cd548dae192903230453f95e 100644 (file)
@@ -260,4 +260,8 @@ select 'intersects', ST_intersects(
       ST_polygonfromtext('POLYGON((0.0 2.0,1.0 2.0,1.0 3.0,0.0 3.0,0.0 2.0))')
       );
 
+select 'ST_GeometryN', ST_asewkt(ST_GeometryN('LINESTRING(0 0, 1 1)'::geometry, 1));
+select 'ST_NumGeometries', ST_NumGeometries('LINESTRING(0 0, 1 1)'::geometry);
+
+
 
index ac40d9297019c369e70c7d1639a0c2960018a242..949b721e2a3b4721bfa855e8d085aa05c8cdaca9 100644 (file)
@@ -150,3 +150,5 @@ polygonize_garray|GEOMETRYCOLLECTION EMPTY
 polygonize_garray|POLYGON((10 0,0 0,0 10,10 10,10 0))
 linemerge149|LINESTRING(-5 -5,0 0,1 1,4 4)
 intersects|f
+ST_GeometryN|LINESTRING(0 0,1 1)
+ST_NumGeometries|1