From: Sandro Santilli Date: Thu, 29 Nov 2012 18:13:47 +0000 (+0000) Subject: Ensure ST_PointOnSurface always returns POINT (#2117) X-Git-Tag: 2.1.0beta2~348 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=58a11eb5af1580e37c52c37a59f57d0882c7a604;p=postgis Ensure ST_PointOnSurface always returns POINT (#2117) git-svn-id: http://svn.osgeo.org/postgis/trunk@10755 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/lwgeom_geos.c b/postgis/lwgeom_geos.c index 758e9c4ab..c1d5236a2 100644 --- a/postgis/lwgeom_geos.c +++ b/postgis/lwgeom_geos.c @@ -1494,19 +1494,25 @@ Datum difference(PG_FUNCTION_ARGS) PG_FUNCTION_INFO_V1(pointonsurface); Datum pointonsurface(PG_FUNCTION_ARGS) { - GSERIALIZED *geom1; + LWGEOM *lwg; + GSERIALIZED *geom; GEOSGeometry *g1, *g3; GSERIALIZED *result; - geom1 = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); + geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); - /* Empty.PointOnSurface == Empty */ - if ( gserialized_is_empty(geom1) ) - PG_RETURN_POINTER(geom1); + /* Empty.PointOnSurface == Point Empty */ + if ( gserialized_is_empty(geom) ) + { + lwg = lwpoint_construct_empty(gserialized_get_srid(geom), gserialized_has_z(geom), gserialized_has_m(geom)); + result = geometry_serialize(lwpoint_as_lwgeom(lwg)); + lwgeom_free(lwg); + PG_RETURN_POINTER(result); + } initGEOS(lwnotice, lwgeom_geos_error); - g1 = (GEOSGeometry *)POSTGIS2GEOS(geom1); + g1 = (GEOSGeometry *)POSTGIS2GEOS(geom); if ( 0 == g1 ) /* exception thrown at construction */ { @@ -1525,9 +1531,9 @@ Datum pointonsurface(PG_FUNCTION_ARGS) POSTGIS_DEBUGF(3, "result: %s", GEOSGeomToWKT(g3) ) ; - GEOSSetSRID(g3, gserialized_get_srid(geom1)); + GEOSSetSRID(g3, gserialized_get_srid(geom)); - result = GEOS2POSTGIS(g3, gserialized_has_z(geom1)); + result = GEOS2POSTGIS(g3, gserialized_has_z(geom)); if (result == NULL) { @@ -1540,7 +1546,7 @@ Datum pointonsurface(PG_FUNCTION_ARGS) GEOSGeom_destroy(g1); GEOSGeom_destroy(g3); - PG_FREE_IF_COPY(geom1, 0); + PG_FREE_IF_COPY(geom, 0); PG_RETURN_POINTER(result); } diff --git a/regress/tickets.sql b/regress/tickets.sql index 9c2d112d5..d19f58302 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -788,5 +788,7 @@ FROM (SELECT 'POLYGON((1 1 1, 5 1 1,5 5 1, 1 5 1,1 1 1))'::geometry as a, 'LINES ) as foo; -- 2112 -- End +SELECT '#2117', ST_AsEWKT(ST_PointOnSurface('SRID=3395;MULTIPOLYGON M EMPTY'::geometry)); + -- Clean up DELETE FROM spatial_ref_sys; diff --git a/regress/tickets_expected b/regress/tickets_expected index b798bcb03..d999778bb 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -240,3 +240,4 @@ ERROR: invalid GML representation #2048|3|f|f #2112a|0|LINESTRING(2.5 2.5 1,2.5 2.5 1) #2112b|1|LINESTRING(1 1 1,1 0 1) +#2117|SRID=3395;POINTM EMPTY