]> granicus.if.org Git - postgis/commitdiff
ST_AsMVTGeom: Fix bug that oversimplified vertical or horizontal lines
authorRaúl Marín Rodríguez <rmrodriguez@carto.com>
Wed, 30 Jan 2019 13:35:17 +0000 (13:35 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Wed, 30 Jan 2019 13:35:17 +0000 (13:35 +0000)
References #4294
Closes https://github.com/postgis/postgis/pull/367

git-svn-id: http://svn.osgeo.org/postgis/trunk@17219 b70326c6-7e19-0410-871a-916f4a2858ee

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

index 61660119937fa6289bf3d0e079b92570338524f5..6e992b00e92792f61cbe9810cf4f1edfd621f8a3 100644 (file)
@@ -95,15 +95,12 @@ Datum ST_AsMVTGeom(PG_FUNCTION_ARGS)
                        /* Shortcut to drop geometries smaller than the resolution */
                        double geom_width = gserialized_box.xmax - gserialized_box.xmin;
                        double geom_height = gserialized_box.ymax - gserialized_box.ymin;
-                       double geom_area = geom_width * geom_height;
 
-                       double bounds_width = (bounds->xmax - bounds->xmin) / extent;
-                       double bounds_height = (bounds->ymax - bounds->ymin) / extent;
-
-                       /* We use 1/4th of the grid square area as the minimum resolution */
-                       double min_resolution_area = bounds_width * bounds_height / 4.0;
-
-                       if (geom_area < min_resolution_area)
+                       /* We use half of the square height and width as limit: We use this
+                        * and not area so it works properly with lines */
+                       double bounds_width = ((bounds->xmax - bounds->xmin) / extent) / 2.0;
+                       double bounds_height = ((bounds->ymax - bounds->ymin) / extent) / 2.0;
+                       if (geom_width < bounds_width && geom_height < bounds_height)
                        {
                                PG_RETURN_NULL();
                        }
index 9b5507a74bc12539bc755db1fb3e2783d53431ec..2a21c037572c3149fe9e9613439662399c561476 100644 (file)
@@ -569,6 +569,15 @@ SELECT '#3922', St_Area(ST_AsMVTGeom(
                true
                ));
 
+SELECT '#4294_Horizontal', ST_AsText(ST_AsMVTGeom(
+       ST_GeomFromText('MULTILINESTRING((0 0, 0 5))'),
+       ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
+       10, 0, true));
+
+SELECT '#4294_Vertical', ST_AsText(ST_AsMVTGeom(
+       ST_GeomFromText('MULTILINESTRING((0 0, 5 0))'),
+       ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
+       10, 0, true));
 
 -- Feature id encoding tests
 SELECT 'FI1', encode(ST_AsMVT(q, 'test', 4096, 'geom', 'c1'), 'base64') FROM (
index c0e7771826b016fff1ce8f6a53229555fa5ef0a9..fe13e239581e8dce93c83ddc4002a744db32d4d8 100644 (file)
@@ -123,6 +123,8 @@ TU2
 ERROR:  pgis_asmvt_transfn: parameter row cannot be other than a rowtype
 TU3|
 #3922|6.5
+#4294_Horizontal|LINESTRING(0 10,0 5)
+#4294_Vertical|LINESTRING(0 10,5 10)
 FI1|GicKBHRlc3QSDggBEgIAABgBIgQJMt4/GgJjMiIGCgRhYmNkKIAgeAI=
 FI2|GicKBHRlc3QSDggBEgIAABgBIgQJMt4/GgJjMiIGCgRhYmNkKIAgeAI=
 FI3|GicKBHRlc3QSDggBEgIAABgBIgQJMt4/GgJjMiIGCgRhYmNkKIAgeAI=