From: Raúl Marín Rodríguez Date: Wed, 16 Jan 2019 10:48:55 +0000 (+0000) Subject: ST_AsMVTGeom: Always return the simplest geometry X-Git-Tag: 3.0.0alpha1~201 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=69219285ff671a6b2e69df53b4670886595da954;p=postgis ST_AsMVTGeom: Always return the simplest geometry References #4300 git-svn-id: http://svn.osgeo.org/postgis/trunk@17160 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 48bf79521..53304fbc7 100644 --- a/NEWS +++ b/NEWS @@ -62,6 +62,7 @@ PostGIS 3.0.0 - #4262, Document MULTISURFACE compatibility of ST_LineToCurve (Steven Ottens) - #4276, ST_AsGeoJSON documentation refresh (Darafei Praliaskouski) - #4292, ST_AsMVT: parse JSON numeric values with decimals as doubles (Raúl Marín) + - #4300, ST_AsMVTGeom: Always return the simplest geometry (Raúl Marín) PostGIS 2.5.0 2018/09/23 diff --git a/postgis/mvt.c b/postgis/mvt.c index 0b50b1f62..651f9dbea 100644 --- a/postgis/mvt.c +++ b/postgis/mvt.c @@ -810,15 +810,28 @@ lwgeom_get_basic_type(LWGEOM *geom) * geom be lost? Sure, but your MVT renderer couldn't * draw it anyways. */ -static void +static inline LWGEOM * lwgeom_to_basic_type(LWGEOM *geom, uint8 original_type) { + LWGEOM *geom_out = geom; if (lwgeom_get_type(geom) == COLLECTIONTYPE) { LWCOLLECTION *g = (LWCOLLECTION*)geom; - LWCOLLECTION *gc = lwcollection_extract(g, original_type); - *g = *gc; + geom_out = (LWGEOM *)lwcollection_extract(g, original_type); } + + /* If a collection only contains 1 geometry return than instead */ + if (lwgeom_is_collection(geom_out)) + { + LWCOLLECTION *g = (LWCOLLECTION *)geom_out; + if (g->ngeoms == 1) + { + geom_out = g->geoms[0]; + } + } + + geom_out->srid = geom->srid; + return geom_out; } /** @@ -936,8 +949,7 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buf } /* if geometry collection extract highest dimensional geometry type */ - if (lwgeom->type == COLLECTIONTYPE) - lwgeom_to_basic_type(lwgeom, basic_type); + lwgeom = lwgeom_to_basic_type(lwgeom, basic_type); if (basic_type != lwgeom_get_basic_type(lwgeom)) { diff --git a/regress/core/mvt_expected b/regress/core/mvt_expected index 5cab796ab..24c0ead7b 100644 --- a/regress/core/mvt_expected +++ b/regress/core/mvt_expected @@ -22,7 +22,7 @@ PG16|POLYGON((0 10,0 0,10 0,10 10,0 10),(1 9,9 9,9 1,1 1,1 9)) PG17|MULTIPOLYGON(((0 10,0 0,10 0,10 10,0 10),(1 9,9 9,9 1,1 1,1 9)),((2 8,2 2,8 2,8 8,2 8),(3 7,7 7,7 3,3 3,3 7))) PG18|MULTIPOINT(1 9,3 8) PG19|MULTIPOINT(25 4079,26 4078) -PG20|MULTIPOINT(10 4086) +PG20|POINT(10 4086) PG21|LINESTRING(1 9,5 5) PG22| PG23|MULTILINESTRING((1 9,5 5),(2 2,5 5)) @@ -53,7 +53,7 @@ PG43 - ON |MULTIPOLYGON(((5 5,0 0,10 0,5 5)),((0 10,5 5,10 10,0 10))) PG43 - OFF|MULTIPOLYGON(((5 5,-1 -1,11 -1,5 5)),((5 5,11 11,-1 11,5 5))) PG44| PG45| -PG46|SRID=3857;MULTIPOLYGON(((3245 2224,3262 2030,3253 2158,3245 2224))) +PG46|SRID=3857;POLYGON((3245 2224,3262 2030,3253 2158,3245 2224)) PG47| TG1|GiEKBHRlc3QSDBICAAAYASIECTLePxoCYzEiAigBKIAgeAI= TG2|GiMKBHRlc3QSDhICAAAYASIGETLePwIBGgJjMSICKAEogCB4Ag== @@ -104,7 +104,7 @@ D7|POINT(1 4094) TU2 ERROR: pgis_asmvt_transfn: parameter row cannot be other than a rowtype TU3| -#3922|MULTIPOLYGON(((2613 3664,2615 3662,2616 3662,2617 3665,2615 3665,2615 3664,2613 3664))) +#3922|POLYGON((2613 3664,2615 3662,2616 3662,2617 3665,2615 3665,2615 3664,2613 3664)) FI1|GicKBHRlc3QSDggBEgIAABgBIgQJMt4/GgJjMiIGCgRhYmNkKIAgeAI= FI2|GicKBHRlc3QSDggBEgIAABgBIgQJMt4/GgJjMiIGCgRhYmNkKIAgeAI= FI3|GicKBHRlc3QSDggBEgIAABgBIgQJMt4/GgJjMiIGCgRhYmNkKIAgeAI=