From: Raúl Marín Rodríguez Date: Sat, 22 Sep 2018 13:00:41 +0000 (+0000) Subject: St_AsMVTGeom: Avoid type changes due to validation X-Git-Tag: 3.0.0alpha1~391 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bcbf7b193f66f29afa983602cb537316b6c2fd79;p=postgis St_AsMVTGeom: Avoid type changes due to validation References #4181 Closes https://github.com/postgis/postgis/pull/304/ git-svn-id: http://svn.osgeo.org/postgis/trunk@16831 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index aac36ed56..9cc164ffd 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ PostGIS 3.0.0 - #4176, ST_Intersects supports GEOMETRYCOLLECTION (Darafei Praliaskouski) - #4177, Postgres 12 disallows variable length arrays in C (Laurenz Albe) - #4160, Use qualified names in topology extension install (Raúl Marín) + - #4181, St_AsMVTGeom: Avoid type changes due to validation (Raúl Marín) PostGIS 2.5.0rc1 2018/08/19 diff --git a/postgis/mvt.c b/postgis/mvt.c index 9ebc61882..8468b05a7 100644 --- a/postgis/mvt.c +++ b/postgis/mvt.c @@ -921,14 +921,24 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buf if (lwgeom == NULL || lwgeom_is_empty(lwgeom)) return NULL; - /* if polygon(s) make valid and force clockwise as per MVT spec */ + if (lwgeom->type == POLYGONTYPE || lwgeom->type == MULTIPOLYGONTYPE || lwgeom->type == COLLECTIONTYPE) { + /* Force validation as per MVT spec */ lwgeom = lwgeom_make_valid(lwgeom); - /* In image coordinates CW actually comes out a CCW, so */ - /* we also reverse. ¯\_(ツ)_/¯ */ + + /* Drop type changes tp play nice with MVT renderers */ + if (!(lwgeom->type == POLYGONTYPE || + lwgeom->type == MULTIPOLYGONTYPE || + lwgeom->type == COLLECTIONTYPE)) + { + lwgeom_free(lwgeom); + return NULL; + } + + /* In image coordinates CW actually comes out a CCW, so we reverse */ lwgeom_force_clockwise(lwgeom); lwgeom_reverse_in_place(lwgeom); } diff --git a/regress/mvt.sql b/regress/mvt.sql index 7b9b4e222..dcc237a79 100644 --- a/regress/mvt.sql +++ b/regress/mvt.sql @@ -257,6 +257,14 @@ SELECT 'PG43 - OFF', ST_AsText(ST_AsMVTGeom( ST_MakeBox2D(ST_Point(0, 0), ST_Point(100, 100)), 10, 0, false)); +-- Geometry type change +SELECT 'PG44', ST_AsEWKT(ST_AsMVTGeom( + 'SRID=3857;MULTIPOLYGON(((-8238038.43842083 4974073.00356281,-8238058.59985694 4974035.91194892,-8238046.74211362 4974077.68076013,-8238038.43842083 4974073.00356281)))'::geometry, + 'SRID=3857;POLYGON((-8242969.13027341 4975133.29702555,-8242969.13027341 4970241.3272153,-8238077.16046316 4970241.3272153,-8238077.16046316 4975133.29702555,-8242969.13027341 4975133.29702555))'::geometry, + 4096, + 16, + true)); + -- geometry encoding tests SELECT 'TG1', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1, ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), @@ -485,4 +493,4 @@ SELECT 'FI9', encode(ST_AsMVT(q, 'test', 4096, 'geom', 'c1'), 'base64') FROM ( SELECT 1::double precision AS c1, 'abcd'::text AS c2, 20::integer as c1, ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom -) AS q; \ No newline at end of file +) AS q; diff --git a/regress/mvt_expected b/regress/mvt_expected index 75b6cb95d..6b711466b 100644 --- a/regress/mvt_expected +++ b/regress/mvt_expected @@ -46,6 +46,7 @@ PG42 - ON |LINESTRING(0 10,0 0,1 0) PG42 - OFF|LINESTRING(0 10,0 0,1 0) 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| TG1|GiEKBHRlc3QSDBICAAAYASIECTLePxoCYzEiAigBKIAgeAI= TG2|GiMKBHRlc3QSDhICAAAYASIGETLePwIBGgJjMSICKAEogCB4Ag== TG3|GiYKBHRlc3QSERICAAAYAiIJCQCAQArQD88PGgJjMSICKAEogCB4Ag==