]> granicus.if.org Git - postgis/commitdiff
Switch back ST_CollectionExtract to return EMPTY rather than NULL on no matches ...
authorSandro Santilli <strk@keybit.net>
Mon, 9 Jan 2012 17:01:54 +0000 (17:01 +0000)
committerSandro Santilli <strk@keybit.net>
Mon, 9 Jan 2012 17:01:54 +0000 (17:01 +0000)
This behavior seems closer to the one requested in original #457
testcase, and is still consistent. Is also closer to documentation.

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

postgis/lwgeom_functions_basic.c
regress/regress_expected
regress/tickets_expected

index bb169e424315c6f460a4b7396fa9324cbff782ba..dea38ea3c715cf80cd6e5ffa9f274200ee37b289 100644 (file)
@@ -2510,7 +2510,7 @@ Datum ST_CollectionExtract(PG_FUNCTION_ARGS)
        GSERIALIZED *input = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
        GSERIALIZED *output;
        LWGEOM *lwgeom = lwgeom_from_gserialized(input);
-       LWCOLLECTION *lwcol = NULL;
+       LWGEOM *lwcol = NULL;
        int type = PG_GETARG_INT32(1);
        int lwgeom_type = lwgeom->type;
 
@@ -2525,28 +2525,33 @@ Datum ST_CollectionExtract(PG_FUNCTION_ARGS)
        /* Mirror non-collections right back */
        if ( ! lwgeom_is_collection(lwgeom) )
        {
-               lwgeom_free(lwgeom);
                /* Non-collections of the matching type go back */
                if(lwgeom_type == type)
                {
+                       lwgeom_free(lwgeom);
                        PG_RETURN_POINTER(input);
                }
-               /* Others go back as NULL */
+               /* Others go back as EMPTY */
                else
                {
-                       PG_RETURN_NULL();
+                       lwcol = lwgeom_construct_empty(type, lwgeom->srid, FLAGS_GET_Z(lwgeom->flags), FLAGS_GET_M(lwgeom->flags));
                }
        }
+       else
+       {
+               lwcol = lwcollection_as_lwgeom(lwcollection_extract((LWCOLLECTION*)lwgeom, type));
+       }
 
-       lwcol = lwcollection_extract((LWCOLLECTION*)lwgeom, type);
+#if 0
        if (lwgeom_is_empty(lwcollection_as_lwgeom(lwcol)))
        {
                lwgeom_free(lwgeom);
                PG_RETURN_NULL();
        }
-
+#endif
        output = geometry_serialize((LWGEOM*)lwcol);
        lwgeom_free(lwgeom);
+       lwgeom_free(lwcol);
 
        PG_RETURN_POINTER(output);
 }
index f90dc52c58eb3d289609961e565de78dd97268a8..59bb715e21d0ef723e57cf7b75165b304b39e0ce 100644 (file)
@@ -177,7 +177,7 @@ HINT:  "MULTIPOINT(1 1, 2 2" <-- parse error at position 19 within geometry
 156|MULTIPOINT(1 1)
 157|MULTILINESTRING((0 0,1 1))
 158|MULTILINESTRING((0 0,1 1),(2 2,3 3))
-159|
+159|MULTIPOLYGON EMPTY
 160|MULTIPOINT(1 1)
 161|MULTILINESTRING((0 0,1 1),(2 2,3 3))
 ERROR:  Input geometries must be points
index b200039b7af7db148b9c7d04062efcbf9406d879..b2533b991cf1c8b5b7af7f47c4af797c3ff777c7 100644 (file)
@@ -73,26 +73,26 @@ NOTICE:  IllegalArgumentException: Invalid number of points in LinearRing found
 #408.3|f
 #408.4|IllegalArgumentException: Invalid number of points in LinearRing found 2 - must be 0 or >= 4
 #457.1|POINT(0 0)
-#457.2|
-#457.3|
-#457.4|
+#457.2|LINESTRING EMPTY
+#457.3|POLYGON EMPTY
+#457.4|POINT EMPTY
 #457.5|LINESTRING(0 0,1 1)
-#457.6|
-#457.7|
-#457.8|
+#457.6|POLYGON EMPTY
+#457.7|POINT EMPTY
+#457.8|LINESTRING EMPTY
 #457.9|POLYGON((0 0,1 0,1 1,0 1,0 0))
-#835.1|
-#835.2|
+#835.1|POINT EMPTY
+#835.2|LINESTRING EMPTY
 #835.3|POLYGON EMPTY
-#835.4|
+#835.4|POINT EMPTY
 #835.5|LINESTRING EMPTY
-#835.6|
+#835.6|POLYGON EMPTY
 #835.7|POINT EMPTY
-#835.8|
-#835.9|
-#835.10|
-#835.11|
-#835.12|
+#835.8|LINESTRING EMPTY
+#835.9|POLYGON EMPTY
+#835.10|MULTIPOINT EMPTY
+#835.11|MULTILINESTRING EMPTY
+#835.12|MULTIPOLYGON EMPTY
 #650|MULTIPOINT(0 0,1 1,2 2)
 #667|SRID=4326;CURVEPOLYGON(CIRCULARSTRING(30 40,18.2842712474619 11.7157287525381,-9.99999999999994 0,-38.284271247462 68.2842712474618,30 40))
 #677|1121395