[postgis-tickets] r16648 - ST_AsMVTGeom: Clip using tile coordinates also for buffer 0

Raul raul at rmr.ninja
Tue Jul 17 02:02:11 PDT 2018


Author: algunenano
Date: 2018-07-17 02:02:10 -0700 (Tue, 17 Jul 2018)
New Revision: 16648

Modified:
   trunk/postgis/mvt.c
   trunk/regress/mvt.sql
   trunk/regress/mvt_expected
Log:
ST_AsMVTGeom: Clip using tile coordinates also for buffer 0

Closes https://github.com/postgis/postgis/pull/272
References #4120



Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2018-07-16 20:32:14 UTC (rev 16647)
+++ trunk/postgis/mvt.c	2018-07-17 09:02:10 UTC (rev 16648)
@@ -696,11 +696,7 @@
 	gridspec grid;
 	double width = gbox->xmax - gbox->xmin;
 	double height = gbox->ymax - gbox->ymin;
-	double resx = width / extent;
-	double resy = height / extent;
-	double res = (resx < resy ? resx : resy)/2;
-	double fx = extent / width;
-	double fy = -(extent / height);
+	double resx, resy, res, fx, fy;
 	int preserve_collapsed = LW_TRUE;
 	POSTGIS_DEBUG(2, "mvt_geom called");
 
@@ -714,6 +710,12 @@
 	if (extent == 0)
 		elog(ERROR, "mvt_geom: extent cannot be 0");
 
+	resx = width / extent;
+	resy = height / extent;
+	res = (resx < resy ? resx : resy)/2;
+	fx = extent / width;
+	fy = -(extent / height);
+
 	/* Remove all non-essential points (under the output resolution) */
 	lwgeom_remove_repeated_points_in_place(lwgeom, res);
 	lwgeom_simplify_in_place(lwgeom, res, preserve_collapsed);
@@ -726,10 +728,9 @@
 	{
 		// We need to add an extra half pixel to include the points that
 		// fall into the bbox only after the coordinate transformation
-		double buffer_map_xunits = !buffer ?
-			0.0 : nextafterf(resx * (buffer + 0.5), 0.0);
+		double buffer_map_xunits = nextafterf(res, 0.0) + resx * buffer;
 		GBOX bgbox;
-		const GBOX *lwgeom_gbox = lwgeom_get_bbox(lwgeom);;
+		const GBOX *lwgeom_gbox = lwgeom_get_bbox(lwgeom);
 		bgbox = *gbox;
 		gbox_expand(&bgbox, buffer_map_xunits);
 		if (!gbox_overlaps_2d(lwgeom_gbox, &bgbox))

Modified: trunk/regress/mvt.sql
===================================================================
--- trunk/regress/mvt.sql	2018-07-16 20:32:14 UTC (rev 16647)
+++ trunk/regress/mvt.sql	2018-07-17 09:02:10 UTC (rev 16648)
@@ -204,6 +204,59 @@
 	ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)),
 	4096, 256, true));
 
+SELECT 'PG39 - ON ', ST_AsText(ST_AsMVTGeom(
+	ST_GeomFromText('POLYGON((0 100, 100 100, 100 90, 94 90, 94 96, 90 96, 90 80, 100 80, 100 0, 0 0, 0 100))'),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(100, 100)),
+	10, 0, true));
+
+SELECT 'PG39 - OFF', ST_AsText(ST_AsMVTGeom(
+	ST_GeomFromText('POLYGON((0 100, 100 100, 100 90, 94 90, 94 96, 90 96, 90 80, 100 80, 100 0, 0 0, 0 100))'),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(100, 100)),
+	10, 0, false));
+
+-- Clipping isn't done since all points fall into the tile after grid
+SELECT 'PG40 - ON ', ST_AsText(ST_AsMVTGeom(
+	ST_GeomFromText('LINESTRING(0 0, 2 20, -2 40, -4 60, 4 80, 0 100)'),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(100, 100)),
+	10, 0, true));
+
+SELECT 'PG40 - OFF', ST_AsText(ST_AsMVTGeom(
+	ST_GeomFromText('LINESTRING(0 0, 2 20, -2 40, -4 60, 4 80, 0 100)'),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(100, 100)),
+	10, 0, false));
+
+-- Clipping isn't done since all points fall into the tile after grid
+SELECT 'PG41 - ON ', ST_AsText(ST_AsMVTGeom(
+	ST_GeomFromText('LINESTRING(0 0, 2 20, -2 40, -4 60, 4 80, 0 100, 10 100)'),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(100, 100)),
+	10, 0, true));
+
+SELECT 'PG41 - OFF', ST_AsText(ST_AsMVTGeom(
+	ST_GeomFromText('LINESTRING(0 0, 2 20, -2 40, -4 60, 4 80, 0 100, 10 100)'),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(100, 100)),
+	10, 0, false));
+
+SELECT 'PG42 - ON ', ST_AsText(ST_AsMVTGeom(
+	ST_GeomFromText('LINESTRING(0 0, 2 20, -2 40, -4 60, 4 80, 0 100, 11 100)'),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(100, 100)),
+	10, 0, true));
+
+SELECT 'PG42 - OFF', ST_AsText(ST_AsMVTGeom(
+	ST_GeomFromText('LINESTRING(0 0, 2 20, -2 40, -4 60, 4 80, 0 100, 11 100)'),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(100, 100)),
+	10, 0, false));
+
+-- Invalid polygon (intersection)
+SELECT 'PG43 - ON ', ST_AsText(ST_AsMVTGeom(
+	ST_GeomFromText('POLYGON((-10 -10, 110 110, -10 110, 110 -10, -10 -10))'),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(100, 100)),
+	10, 0, true));
+
+SELECT 'PG43 - OFF', ST_AsText(ST_AsMVTGeom(
+	ST_GeomFromText('POLYGON((-10 -10, 110 110, -10 110, 110 -10, -10 -10))'),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(100, 100)),
+	10, 0, false));
+
 -- geometry encoding tests
 SELECT 'TG1', encode(ST_AsMVT(q, 'test', 4096, 'geom'), 'base64') FROM (SELECT 1 AS c1,
 	ST_AsMVTGeom(ST_GeomFromText('POINT(25 17)'),

Modified: trunk/regress/mvt_expected
===================================================================
--- trunk/regress/mvt_expected	2018-07-16 20:32:14 UTC (rev 16647)
+++ trunk/regress/mvt_expected	2018-07-17 09:02:10 UTC (rev 16648)
@@ -36,6 +36,20 @@
 PG36|
 PG37|
 PG38|
+PG39 - ON |POLYGON((0 0,10 0,9 2,10 2,10 10,0 10,0 0))
+PG39 - OFF|POLYGON((0 0,10 0,9 2,10 2,10 10,0 10,0 0))
+PG40 - ON |LINESTRING(0 10,0 0)
+PG40 - OFF|LINESTRING(0 10,0 0)
+PG41 - ON |LINESTRING(0 10,0 4,0 2,0 0,1 0)
+PG41 - OFF|LINESTRING(0 10,0 4,0 2,0 0,1 0)
+PG42 - ON |LINESTRING(0 10,0 0,1 0)
+PG42 - OFF|LINESTRING(0 10,0 0,1 0)
+NOTICE:  lwgeom_intersection: GEOS Error: TopologyException: Input geom 0 is invalid: Self-intersection
+NOTICE:  Self-intersection
+NOTICE:  Your geometry dataset is not valid per OGC Specification. Please fix it with manual review of entries that are not ST_IsValid(geom). Retrying GEOS operation with ST_MakeValid of your input.
+NOTICE:  Self-intersection
+PG43 - ON |MULTIPOLYGON(((0 10,5 5,10 10,0 10)),((5 5,0 0,10 0,5 5)))
+PG43 - OFF|MULTIPOLYGON(((5 5,-1 -1,11 -1,5 5)),((5 5,11 11,-1 11,5 5)))
 TG1|GiEKBHRlc3QSDBICAAAYASIECTLePxoCYzEiAigBKIAgeAI=
 TG2|GiMKBHRlc3QSDhICAAAYASIGETLePwIBGgJjMSICKAEogCB4Ag==
 TG3|GiYKBHRlc3QSERICAAAYAiIJCQCAQArQD88PGgJjMSICKAEogCB4Ag==



More information about the postgis-tickets mailing list