From: Sandro Santilli Date: Thu, 29 Nov 2012 17:49:27 +0000 (+0000) Subject: Ensure ST_Centroid always returns POINT (#2109) X-Git-Tag: 2.1.0beta2~350 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=460eab4e820ba363df33227eae19f45abaf1bf9a;p=postgis Ensure ST_Centroid always returns POINT (#2109) git-svn-id: http://svn.osgeo.org/postgis/trunk@10751 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c index cd31cf643..333fadaf1 100644 --- a/postgis/lwgeom_geos.c +++ b/postgis/lwgeom_geos.c @@ -1548,14 +1548,19 @@ Datum pointonsurface(PG_FUNCTION_ARGS) PG_FUNCTION_INFO_V1(centroid); Datum centroid(PG_FUNCTION_ARGS) { + LWGEOM *lwg; GSERIALIZED *geom, *result; GEOSGeometry *geosgeom, *geosresult; geom = (GSERIALIZED *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - /* Empty.Centroid() == Empty */ + /* Empty.Centroid() == Point Empty */ if ( gserialized_is_empty(geom) ) - PG_RETURN_POINTER(geom); + { + lwg = lwpoint_construct_empty(gserialized_get_srid(geom), gserialized_has_z(geom), gserialized_has_m(geom)); + result = geometry_serialize(lwpoint_as_lwgeom(lwg)); + PG_RETURN_POINTER(result); + } initGEOS(lwnotice, lwgeom_geos_error); diff --git a/regress/tickets.sql b/regress/tickets.sql index d9bf56c0b..9c2d112d5 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -346,8 +346,9 @@ SELECT '#682', ST_Buffer(ST_GeomFromText('POLYGON EMPTY',4326) , 0.5); -- #683 -- SELECT '#683', ST_BuildArea(ST_GeomFromText('POINT EMPTY',4326)); --- #684 -- -SELECT '#684', ST_Centroid(ST_GeomFromText('POLYGON EMPTY',4326)); +-- #684,#2109 -- +SELECT '#684,#2109', ST_AsEWKT(ST_Centroid(ST_GeomFromText('POLYGON EMPTY',4326))); +SELECT '#2109', ST_AsEWKT(ST_Centroid(ST_GeomFromText('MULTILINESTRING ZM EMPTY',3395))); -- #685 -- SELECT '#685', ST_ConvexHull(ST_GeomFromText('POLYGON EMPTY',4326)); diff --git a/regress/tickets_expected b/regress/tickets_expected index 387c95abe..b798bcb03 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -107,7 +107,8 @@ NOTICE: IllegalArgumentException: Invalid number of points in LinearRing found #681g| #682|0103000020E610000000000000 #683|0103000020E610000000000000 -#684|0103000020E610000000000000 +#684,#2109|SRID=4326;POINT EMPTY +#2109|SRID=3395;POINT EMPTY #685|0103000020E610000000000000 #686|0107000020E610000000000000 #687|f