[postgis-tickets] r15335 - Only keep the highest dimension geometry for collections

bjorn at wololo.org bjorn at wololo.org
Thu Mar 16 06:08:38 PDT 2017


Author: bjornharrtell
Date: 2017-03-16 06:08:38 -0700 (Thu, 16 Mar 2017)
New Revision: 15335

Modified:
   trunk/postgis/mvt.c
   trunk/regress/mvt.sql
   trunk/regress/mvt_expected
Log:
Only keep the highest dimension geometry for collections

Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2017-03-15 15:10:01 UTC (rev 15334)
+++ trunk/postgis/mvt.c	2017-03-16 13:08:38 UTC (rev 15335)
@@ -507,6 +507,24 @@
 	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) {
+		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));
+		lwgeom_out = lwgeom_homogenize(lwgeom_out);
+	}
+
 	return lwgeom_out;
 }
 

Modified: trunk/regress/mvt.sql
===================================================================
--- trunk/regress/mvt.sql	2017-03-15 15:10:01 UTC (rev 15334)
+++ trunk/regress/mvt.sql	2017-03-16 13:08:38 UTC (rev 15335)
@@ -23,7 +23,16 @@
 	ST_GeomFromText('POLYGON ((762780 6474467, 717821 6797045, 1052826 6797045, 762780 6474467))'),
 	ST_MakeBox2D(ST_Point(626172.135625, 6261721.35625), ST_Point(1252344.27125, 6887893.49188)),
 	4096, 0, false));
+select 'PG7', ST_AsText(ST_AsMVTGeom(
+    ST_GeomFromText('POLYGON((-7792023.4539488 1411512.60791779,-7785283.40665468 1406282.69482469,-7783978.88137195 1404858.20373788,-7782986.89858399 1402324.91434802,-7779028.02672366 1397370.31802772,
+        -7778652.06985644 1394387.75452545,-7779906.76953697 1393279.22658385,-7782212.33678782 1393293.14086794,-7784631.14401331 1394225.4151684,-7786257.27108231 1395867.40241344,-7783978.88137195 1395867.40241344,
+        -7783978.88137195 1396646.68250521,-7787752.03959369 1398469.72134299,-7795443.30325373 1405280.43988858,-7797717.16326269 1406217.73286975,-7798831.44531677 1406904.48130551,-7799311.5830898 1408004.24038921,
+        -7799085.10302919 1409159.72782477,-7798052.35381919 1411108.84582812,-7797789.63692662 1412213.40365339,-7798224.47868753 1414069.89725829,-7799003.5701851 1415694.42577482,-7799166.63587328 1416966.26267896,
+        -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));
 
+
 -- 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-15 15:10:01 UTC (rev 15334)
+++ trunk/regress/mvt_expected	2017-03-16 13:08:38 UTC (rev 15335)
@@ -4,6 +4,7 @@
 PG4|MULTIPOLYGON(((5 4096,10 4096,10 4091,5 4096)),((0 4096,0 4101,5 4096,0 4096)))
 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))
 TG1|GiEKBHRlc3QSDBICAAAYASIECTLePxoCYzEiAigBKIAgeAI=
 TG2|GiMKBHRlc3QSDhICAAAYASIGETLePwIBGgJjMSICKAEogCB4Ag==
 TG3|GiYKBHRlc3QSERICAAAYAiIJCQCAQArQD88PGgJjMSICKAEogCB4Ag==



More information about the postgis-tickets mailing list