]> granicus.if.org Git - postgis/commitdiff
Add ST_isCollection (see ticket #549)
authorSandro Santilli <strk@keybit.net>
Thu, 1 Jul 2010 13:20:43 +0000 (13:20 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 1 Jul 2010 13:20:43 +0000 (13:20 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@5718 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
postgis/lwgeom_functions_basic.c
postgis/postgis.sql.in.c
regress/Makefile.in
regress/iscollection.sql [new file with mode: 0644]
regress/iscollection_expected [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 5dcb028f854184d0469b00284efe80d7eef25298..aabecdd61e3c724bfe89b46ac632e3028345e8e9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,7 @@ YYYY/MM/DD
   - ST_RemoveRepeatedPoints (Sandro Santilli / Faunalia for RT-SIGTA)
   - ST_GeometryN and ST_NumGeometries support for non-collections
     (Sandro Santilli)
+  - ST_isCollection (Sandro Santilli, yabo)
 
  * Enhancements *
 
index 4c124758b69fbdef8aacd5484676052a352afd13..496157bd40a806560bdd21ac7fa8adc36ee8c6be 100644 (file)
@@ -84,6 +84,7 @@ Datum optimistic_overlap(PG_FUNCTION_ARGS);
 Datum ST_GeoHash(PG_FUNCTION_ARGS);
 Datum ST_MakeEnvelope(PG_FUNCTION_ARGS);
 Datum ST_CollectionExtract(PG_FUNCTION_ARGS);
+Datum ST_IsCollection(PG_FUNCTION_ARGS);
 
 void lwgeom_affine_ptarray(POINTARRAY *pa, double afac, double bfac, double cfac,
                            double dfac, double efac, double ffac, double gfac, double hfac, double ifac, double xoff, double yoff, double zoff);
@@ -2977,6 +2978,21 @@ Datum ST_MakeEnvelope(PG_FUNCTION_ARGS)
        PG_RETURN_POINTER(result);
 }
 
+PG_FUNCTION_INFO_V1(ST_IsCollection);
+Datum ST_IsCollection(PG_FUNCTION_ARGS)
+{
+       PG_LWGEOM* geom;
+       int type;
+
+        /* Pull only a small amount of the tuple,
+        * enough to get the type. size = header + type */
+       geom = (PG_LWGEOM*)PG_DETOAST_DATUM_SLICE(PG_GETARG_DATUM(0),
+                          0, VARHDRSZ + 1);
+
+       type = lwgeom_getType(SERIALIZED_FORM(geom)[0]);
+       PG_RETURN_BOOL(lwgeom_is_collection(type));
+}
+
 PG_FUNCTION_INFO_V1(LWGEOM_makepoint);
 Datum LWGEOM_makepoint(PG_FUNCTION_ARGS)
 {
index 4c455e7cd35cc7a0404419151dcedb8b1266dbbb..57af0b45ec4bcce64fcc3e0cc955a6636e4bf1f1 100644 (file)
@@ -4580,6 +4580,12 @@ CREATE OR REPLACE FUNCTION ST_IsSimple(geometry)
        AS 'MODULE_PATHNAME', 'issimple'
        LANGUAGE 'C' IMMUTABLE STRICT;
 
+-- Availability: 2.0.0
+CREATE OR REPLACE FUNCTION ST_IsCollection(geometry)
+       RETURNS boolean
+       AS 'MODULE_PATHNAME', 'ST_IsCollection'
+       LANGUAGE 'C' IMMUTABLE STRICT;
+
 -- Deprecation in 1.2.3
 CREATE OR REPLACE FUNCTION Equals(geometry,geometry)
        RETURNS boolean
index b1b092e35194dbfb77500cb15a2876a0142884d4..de5d3ef3ffb00fe6dc736ed5edbecd4d58165fc5 100644 (file)
@@ -60,6 +60,7 @@ TESTS = \
        out_geography \
        in_gml \
        in_kml \
+       iscollection \
        regress_ogc \
        regress_ogc_cover \
        regress_ogc_prep \
diff --git a/regress/iscollection.sql b/regress/iscollection.sql
new file mode 100644 (file)
index 0000000..7e630d3
--- /dev/null
@@ -0,0 +1,28 @@
+-- Ensure there are no false-positives
+SELECT 'point', ST_IsCollection('POINT(42 42)');
+SELECT 'poly', ST_IsCollection('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))');
+SELECT 'line', ST_IsCollection('LINESTRING(0 0, 10 10)');
+
+-- PostGIS doesn't support typed empties...
+--SELECT 'empty point', ST_IsCollection('POINT EMPTY');
+--SELECT 'empty poly', ST_IsCollection('POLYGON EMPTY');
+--SELECT 'empty line', ST_IsCollection('LINESTRING EMPTY');
+
+--Ensure that all collections return true (even if they contain a single geometry).
+SELECT 'empty multipoint', ST_IsCollection('MULTIPOINT EMPTY');
+SELECT 'multipoint', ST_IsCollection('MULTIPOINT((0 0))');
+SELECT 'multipoint+', ST_IsCollection('MULTIPOINT((0 0), (42 42))');
+
+SELECT 'empty multiline', ST_IsCollection('MULTILINESTRING EMPTY');
+SELECT 'multiline', ST_IsCollection('MULTILINESTRING((0 0, 10 10))');
+SELECT 'multiline+', ST_IsCollection('MULTILINESTRING((0 0, 10 10), (100 100, 142 142))');
+
+SELECT 'empty multipoly', ST_IsCollection('MULTIPOLYGON EMPTY');
+SELECT 'multipoly', ST_IsCollection('MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0)))');
+SELECT 'multipoly+', ST_IsCollection('MULTIPOLYGON(((0 0, 10 0, 10 10, 0 10, 0 0)), ((100 100, 110 100, 110 110, 100 110, 100 100)))');
+
+SELECT 'empty collection', ST_IsCollection('GEOMETRYCOLLECTION EMPTY');
+SELECT 'collection', ST_IsCollection('GEOMETRYCOLLECTION(POINT(0 0))');
+SELECT 'collection+', ST_IsCollection('GEOMETRYCOLLECTION(POINT(0 0), POINT(42 42))');
+
+
diff --git a/regress/iscollection_expected b/regress/iscollection_expected
new file mode 100644 (file)
index 0000000..d292b6d
--- /dev/null
@@ -0,0 +1,15 @@
+point|f
+poly|f
+line|f
+empty multipoint|t
+multipoint|t
+multipoint+|t
+empty multiline|t
+multiline|t
+multiline+|t
+empty multipoly|t
+multipoly|t
+multipoly+|t
+empty collection|t
+collection|t
+collection+|t