[postgis-tickets] r17160 - ST_AsMVTGeom: Always return the simplest geometry

Raul raul at rmr.ninja
Wed Jan 16 02:48:56 PST 2019


Author: algunenano
Date: 2019-01-16 02:48:55 -0800 (Wed, 16 Jan 2019)
New Revision: 17160

Modified:
   trunk/NEWS
   trunk/postgis/mvt.c
   trunk/regress/core/mvt_expected
Log:
ST_AsMVTGeom: Always return the simplest geometry

References #4300


Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2019-01-16 09:04:13 UTC (rev 17159)
+++ trunk/NEWS	2019-01-16 10:48:55 UTC (rev 17160)
@@ -62,6 +62,7 @@
   - #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

Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2019-01-16 09:04:13 UTC (rev 17159)
+++ trunk/postgis/mvt.c	2019-01-16 10:48:55 UTC (rev 17160)
@@ -810,15 +810,28 @@
  * 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 @@
 	}
 
 	/* 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))
 	{

Modified: trunk/regress/core/mvt_expected
===================================================================
--- trunk/regress/core/mvt_expected	2019-01-16 09:04:13 UTC (rev 17159)
+++ trunk/regress/core/mvt_expected	2019-01-16 10:48:55 UTC (rev 17160)
@@ -22,7 +22,7 @@
 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 - 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 @@
 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=



More information about the postgis-tickets mailing list