From: Sandro Santilli Date: Fri, 20 Jan 2012 14:47:24 +0000 (+0000) Subject: Don't let ST_Multi create collections of a single EMPTY (#1489) X-Git-Tag: 2.0.0alpha2~29 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6ef84a957a94f281bb93bd0147f4ae50e6bc0965;p=postgis Don't let ST_Multi create collections of a single EMPTY (#1489) git-svn-id: http://svn.osgeo.org/postgis/trunk@8892 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index cdea7bb7d..409c0f8e9 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -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; } diff --git a/regress/tickets.sql b/regress/tickets.sql index 40c38c9b3..331930c82 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -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; diff --git a/regress/tickets_expected b/regress/tickets_expected index da7dbff43..f85419f24 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -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