]> granicus.if.org Git - postgis/commitdiff
Maintain the buffer-returns-areal invariant on empty input (#322)
authorSandro Santilli <strk@keybit.net>
Tue, 13 Dec 2011 12:00:56 +0000 (12:00 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 13 Dec 2011 12:00:56 +0000 (12:00 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8382 b70326c6-7e19-0410-871a-916f4a2858ee

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

index 2f4380fad4c290c0766460848539e37ea698199d..974263a7916fe9abccc8070dd180f1b2cc8ebbe8 100644 (file)
@@ -925,13 +925,19 @@ Datum buffer(PG_FUNCTION_ARGS)
        int joinStyle  = DEFAULT_JOIN_STYLE;
        char *param;
        char *params = NULL;
+       LWGEOM *lwg;
 
        geom1 = (GSERIALIZED *)  PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
        size = PG_GETARG_FLOAT8(1);
 
-       /* Empty.Buffer() == Empty */
+       /* Empty.Buffer() == Empty[polygon] */
        if ( gserialized_is_empty(geom1) )
-               PG_RETURN_POINTER(geom1);
+       {
+               lwg = lwpoly_as_lwgeom(lwpoly_construct_empty(
+                       gserialized_get_srid(geom1),
+                       0, 0)); // buffer wouldn't give back z or m anyway
+               PG_RETURN_POINTER(geometry_serialize(lwg));
+       }
 
        nargs = PG_NARGS();
 
index 2dc7feeb43bff5b879c577b9382c3f12736fdc50..a75a7fef8787cd847199726c0eef02ccef1bf8ae 100644 (file)
@@ -279,6 +279,12 @@ SELECT '#304.b', Count(*) FROM utm_dots WHERE ST_DWithin(the_geog, 'POINT(0 0)':
 DROP FUNCTION utmzone(geometry);
 DROP TABLE utm_dots;
 
+SELECT '#322.1', ST_AsEWKT(ST_Buffer('SRID=4326;POINT EMPTY', 0));
+SELECT '#322.2', ST_AsEWKT(ST_Buffer('SRID=4326;LINESTRING EMPTY', 0));
+SELECT '#322.3', ST_AsEWKT(ST_Buffer('SRID=4326;MULTIPOLYGON EMPTY', 0));
+WITH b as ( SELECT ST_Buffer('SRID=4326;MULTIPOINT EMPTY', 1) as g )
+SELECT '#322.4', ST_Srid(g), GeometryType(g) from b;
+
 -- #408 --
 SELECT '#408', st_isvalidreason('0105000020E0670000010000000102000020E06700000100000016DA52BA62A04141FFF3AD290B735241');
 SELECT '#408.1', st_isvalid('0105000020E0670000010000000102000020E06700000100000016DA52BA62A04141FFF3AD290B735241');
index e40b973b2e6793ab1374d5ea57ca5972962f6fc3..94cb3c6e1f3d05acc8ff3ceeaab6b74b99dd2f98 100644 (file)
@@ -65,6 +65,10 @@ NOTICE:  No points in input array
 #304
 #304.a|21
 #304.b|1
+#322.1|SRID=4326;POLYGON EMPTY
+#322.2|SRID=4326;POLYGON EMPTY
+#322.3|SRID=4326;POLYGON EMPTY
+#322.4|4326|POLYGON
 #408|IllegalArgumentException: point array must contain 0 or >1 elements
 NOTICE:  IllegalArgumentException: point array must contain 0 or >1 elements
 #408.1|f