[postgis-tickets] r17219 - ST_AsMVTGeom: Fix bug that oversimplified vertical or horizontal lines

Raul raul at rmr.ninja
Wed Jan 30 05:35:17 PST 2019


Author: algunenano
Date: 2019-01-30 05:35:17 -0800 (Wed, 30 Jan 2019)
New Revision: 17219

Modified:
   trunk/postgis/lwgeom_out_mvt.c
   trunk/regress/core/mvt.sql
   trunk/regress/core/mvt_expected
Log:
ST_AsMVTGeom: Fix bug that oversimplified vertical or horizontal lines

References #4294
Closes https://github.com/postgis/postgis/pull/367



Modified: trunk/postgis/lwgeom_out_mvt.c
===================================================================
--- trunk/postgis/lwgeom_out_mvt.c	2019-01-26 23:22:52 UTC (rev 17218)
+++ trunk/postgis/lwgeom_out_mvt.c	2019-01-30 13:35:17 UTC (rev 17219)
@@ -95,15 +95,12 @@
 			/* 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();
 			}

Modified: trunk/regress/core/mvt.sql
===================================================================
--- trunk/regress/core/mvt.sql	2019-01-26 23:22:52 UTC (rev 17218)
+++ trunk/regress/core/mvt.sql	2019-01-30 13:35:17 UTC (rev 17219)
@@ -569,7 +569,16 @@
 		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 (
 	SELECT 1::smallint AS c1, 'abcd'::text AS c2,

Modified: trunk/regress/core/mvt_expected
===================================================================
--- trunk/regress/core/mvt_expected	2019-01-26 23:22:52 UTC (rev 17218)
+++ trunk/regress/core/mvt_expected	2019-01-30 13:35:17 UTC (rev 17219)
@@ -123,6 +123,8 @@
 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=



More information about the postgis-tickets mailing list