]> granicus.if.org Git - postgis/commitdiff
Don't let ST_Multi create collections of a single EMPTY (#1489)
authorSandro Santilli <strk@keybit.net>
Fri, 20 Jan 2012 14:47:24 +0000 (14:47 +0000)
committerSandro Santilli <strk@keybit.net>
Fri, 20 Jan 2012 14:47:24 +0000 (14:47 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8892 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwgeom.c
regress/tickets.sql
regress/tickets_expected

index cdea7bb7ddb7d5cbaa6d4f554d55d9a57c3ea879..409c0f8e92530a0b315b3afccbe3c65ac4a0ee9f 100644 (file)
@@ -289,8 +289,6 @@ lwgeom_as_multi(const LWGEOM *lwgeom)
        GBOX *box = NULL;
        int type;
 
-       ogeoms = lwalloc(sizeof(LWGEOM*));
-
        /*
        ** This funx is a no-op only if a bbox cache is already present
        ** in input.
@@ -302,8 +300,20 @@ lwgeom_as_multi(const LWGEOM *lwgeom)
 
        type = lwgeom->type;
 
-       if ( MULTITYPE[type] )
+       if ( ! MULTITYPE[type] ) return lwgeom_clone(lwgeom);
+
+       if( lwgeom_is_empty(lwgeom) )
+       {
+               ogeom = (LWGEOM *)lwcollection_construct_empty(
+                       MULTITYPE[type],
+                       lwgeom->srid,
+                       FLAGS_GET_Z(lwgeom->flags),
+                       FLAGS_GET_M(lwgeom->flags)
+               );
+       }
+       else
        {
+               ogeoms = lwalloc(sizeof(LWGEOM*));
                ogeoms[0] = lwgeom_clone(lwgeom);
 
                /* Sub-geometries are not allowed to have bboxes or SRIDs, move the bbox to the collection */
@@ -313,10 +323,6 @@ lwgeom_as_multi(const LWGEOM *lwgeom)
 
                ogeom = (LWGEOM *)lwcollection_construct(MULTITYPE[type], lwgeom->srid, box, 1, ogeoms);
        }
-       else
-       {
-               return lwgeom_clone(lwgeom);
-       }
 
        return ogeom;
 }
index 40c38c9b33740e3f03667fa91f91273bf348b354..331930c82aa3208d4f83c507bfc67423c655536e 100644 (file)
@@ -551,6 +551,19 @@ select '#852.2', id, -- first run is not cached, consequent are cached
   st_intersects(g, 'POLYGON((0 0, 1 1, 1 0, 0 0))'::geometry) from cacheable;
 DROP TABLE cacheable;
 
+-- #1489
+with inp AS ( SELECT
+       st_multi('POINT EMPTY'::geometry) as mp,
+       st_multi('LINESTRING EMPTY'::geometry) as ml, 
+       st_multi('POLYGON EMPTY'::geometry) as ma,
+       st_multi('GEOMETRYCOLLECTION EMPTY'::geometry) as mm
+) select '#1489',
+       st_astext(mp), st_numgeometries(mp),
+       st_astext(ml), st_numgeometries(ml),
+       st_astext(ma), st_numgeometries(ma),
+       st_astext(mm), st_numgeometries(mm)
+FROM inp;
+
 -- Clean up
 DELETE FROM spatial_ref_sys;
 
index da7dbff43cea0fd69bc64f689897710f01cf26d4..f85419f242d3a0e60b3bf679d3ea0425a2ce79b5 100644 (file)
@@ -183,3 +183,4 @@ ERROR:  MultiSurface cannot contain MultiPoint element
 #852.1|2|f|f
 #852.2|1|t|t
 #852.2|2|t|t
+#1489|MULTIPOINT EMPTY|0|MULTILINESTRING EMPTY|0|MULTIPOLYGON EMPTY|0|GEOMETRYCOLLECTION EMPTY|0