]> granicus.if.org Git - postgis/commitdiff
Also consider multi variants when extracting from collections
authorBjörn Harrtell <bjorn@wololo.org>
Fri, 17 Mar 2017 20:52:35 +0000 (20:52 +0000)
committerBjörn Harrtell <bjorn@wololo.org>
Fri, 17 Mar 2017 20:52:35 +0000 (20:52 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@15337 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/mvt.c
regress/mvt.sql
regress/mvt_expected

index d7070976d713d8f3bbd48bbfc730c25e31c4b5e8..f7ae39f6d2e5445d53b31f0ba585583520cf0ca7 100644 (file)
@@ -444,6 +444,19 @@ static void parse_values(struct mvt_agg_context *ctx)
        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 *mvt_geom(LWGEOM *lwgeom, GBOX *gbox, uint32_t extent, uint32_t buffer,
        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);
        }
 
index f32c22d230bdfaeaa80d7ec0518191225de6b208..42fe8657d7058085aa330f23b671262651826b34 100644 (file)
@@ -31,7 +31,10 @@ select 'PG7', ST_AsText(ST_AsMVTGeom(
         -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,
index 8e2598a9ef82dd76d2f12c664536377ae837ac43..5922be654e569fed73d130abd88b5261b8dfcdff 100644 (file)
@@ -5,6 +5,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))
+PG8|MULTIPOLYGON(((5 4096,10 4096,10 4091,5 4096)),((0 4096,0 4101,5 4096,0 4096)))
 TG1|GiEKBHRlc3QSDBICAAAYASIECTLePxoCYzEiAigBKIAgeAI=
 TG2|GiMKBHRlc3QSDhICAAAYASIGETLePwIBGgJjMSICKAEogCB4Ag==
 TG3|GiYKBHRlc3QSERICAAAYAiIJCQCAQArQD88PGgJjMSICKAEogCB4Ag==