Switch back ST_CollectionExtract to return EMPTY rather than NULL on no matches (#835)

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
This commit is contained in:
Sandro Santilli 2012-01-09 17:01:54 +00:00
parent c532c9b846
commit 965a39d011
3 changed files with 27 additions and 22 deletions

View 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);
}

View 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

View 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