]> granicus.if.org Git - postgis/commitdiff
Ensure ST_PointOnSurface always returns POINT (#2117)
authorSandro Santilli <strk@keybit.net>
Thu, 29 Nov 2012 18:13:47 +0000 (18:13 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 29 Nov 2012 18:13:47 +0000 (18:13 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@10755 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_geos.c
regress/tickets.sql
regress/tickets_expected

index 758e9c4ab6eebfda56d9a992e80f4b4bd77690a4..c1d5236a2dbff4fd544804f876c9ebed0a5c10df 100644 (file)
@@ -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);
 }
index 9c2d112d5cf682c13994339af0cd12e0fa23cdb8..d19f583023c3aff6cbab010d89a5c8d34879dc70 100644 (file)
@@ -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;
index b798bcb03a6d23e3615e24a3bd60fe66d614c0a2..d999778bb7e5a6231c47cec930f7c4c19d61ebce 100644 (file)
@@ -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