[postgis-tickets] r15337 - Also consider multi variants when extracting from collections

bjorn at wololo.org bjorn at wololo.org
Fri Mar 17 13:52:35 PDT 2017


Author: bjornharrtell
Date: 2017-03-17 13:52:35 -0700 (Fri, 17 Mar 2017)
New Revision: 15337

Modified:
   trunk/postgis/mvt.c
   trunk/regress/mvt.sql
   trunk/regress/mvt_expected
Log:
Also consider multi variants when extracting from collections

Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2017-03-17 00:28:07 UTC (rev 15336)
+++ trunk/postgis/mvt.c	2017-03-17 20:52:35 UTC (rev 15337)
@@ -444,6 +444,19 @@
 	ctx->feature->tags = tags;
 }
 
+int max_dim(LWCOLLECTION *lwcoll)
+{
+	int i, dim = 1;
+	for (i = 0; i < lwcoll->ngeoms; i++) {
+		uint8_t type = lwcoll->geoms[i]->type;
+		if (type == POLYGONTYPE || type == MULTIPOLYGONTYPE)
+			return 3;
+		else if (type == LINETYPE || type == MULTILINETYPE)
+			dim = 2;
+	}
+	return dim;
+}
+
 /**
  * Transform a geometry into vector tile coordinate space.
  *
@@ -507,21 +520,10 @@
 	lwgeom_force_clockwise(lwgeom_out);
 	lwgeom_out = lwgeom_make_valid(lwgeom_out);
 
-	int type = lwgeom_out->type;
-	int i, extract_type = 1;
-	if (type == COLLECTIONTYPE) {
+	if (lwgeom_out->type == COLLECTIONTYPE) {
 		LWCOLLECTION *lwcoll = (LWCOLLECTION*) lwgeom_out;
-		for (i = 0; i < lwcoll->ngeoms; i++) {
-			LWGEOM *geom = lwcoll->geoms[i];
-			if (geom->type == POLYGONTYPE) {
-				extract_type = 3;
-				break;
-			} else if (geom->type == LINETYPE) {
-				extract_type = 2;
-			}
-		}
 		lwgeom_out = lwcollection_as_lwgeom(
-			lwcollection_extract(lwcoll, extract_type));
+			lwcollection_extract(lwcoll, max_dim(lwcoll)));
 		lwgeom_out = lwgeom_homogenize(lwgeom_out);
 	}
 

Modified: trunk/regress/mvt.sql
===================================================================
--- trunk/regress/mvt.sql	2017-03-17 00:28:07 UTC (rev 15336)
+++ trunk/regress/mvt.sql	2017-03-17 20:52:35 UTC (rev 15337)
@@ -31,8 +31,11 @@
         -7797789.63692662 1417736.81850415,-7793160.38395328 1412417.61222784,-7792023.4539488 1411512.60791779))'),
         ST_MakeBox2D(ST_Point(-20037508.34, 20037508.34), ST_Point(20037508.34, -20037508.34)),
         4096, 10, true));
+select 'PG8', ST_AsText(ST_AsMVTGeom(
+    ST_GeomFromText('GEOMETRYCOLLECTION(MULTIPOLYGON (((0 0, 10 0, 10 5, 0 -5, 0 0))))'),
+    ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)),
+    4096, 0, false));
 
-
 -- geometry encoding tests
 SELECT 'TG1', encode(ST_AsMVT('test', 4096, 'geom', q), 'base64') FROM (SELECT 1 AS c1,
     ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'),

Modified: trunk/regress/mvt_expected
===================================================================
--- trunk/regress/mvt_expected	2017-03-17 00:28:07 UTC (rev 15336)
+++ trunk/regress/mvt_expected	2017-03-17 20:52:35 UTC (rev 15337)
@@ -5,6 +5,7 @@
 PG5|POINT(0 4096)
 PG6|POLYGON((894 2704,2791 594,600 594,894 2704))
 PG7|POLYGON((1252 1904,1251 1904,1252 1905,1253 1906,1253 1905,1252 1904))
+PG8|MULTIPOLYGON(((5 4096,10 4096,10 4091,5 4096)),((0 4096,0 4101,5 4096,0 4096)))
 TG1|GiEKBHRlc3QSDBICAAAYASIECTLePxoCYzEiAigBKIAgeAI=
 TG2|GiMKBHRlc3QSDhICAAAYASIGETLePwIBGgJjMSICKAEogCB4Ag==
 TG3|GiYKBHRlc3QSERICAAAYAiIJCQCAQArQD88PGgJjMSICKAEogCB4Ag==



More information about the postgis-tickets mailing list