[postgis-tickets] r16640 - ST_AsMVTGeom: Clip using tile coordinates

Raul raul at rmr.ninja
Tue Jul 10 07:25:07 PDT 2018


Author: algunenano
Date: 2018-07-10 07:25:07 -0700 (Tue, 10 Jul 2018)
New Revision: 16640

Modified:
   trunk/NEWS
   trunk/postgis/mvt.c
   trunk/regress/mvt.sql
   trunk/regress/mvt_expected
Log:
ST_AsMVTGeom: Clip using tile coordinates

Closes #4120
Closes https://github.com/postgis/postgis/pull/267


Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2018-07-10 13:42:23 UTC (rev 16639)
+++ trunk/NEWS	2018-07-10 14:25:07 UTC (rev 16640)
@@ -3,6 +3,7 @@
 New since PostGIS 2.5.0beta1
   - #4115, Fix a bug that created MVTs with incorrect property values under
     parallel plans (Raúl Marín).
+  - #4120, ST_AsMVTGeom: Clip using tile coordinates (Raúl Marín).
 
   See PostGIS 2.5.0 section for full details
 
@@ -103,6 +104,9 @@
   - #4103, ST_PointOnSurface can handle invalid (Darafei Praliaskouski)
   - #4027, Remove duplicated code in lwgeom_geos (Darafei Praliaskouski,
            Daniel Baston)
+  - #4115, Fix a bug that created MVTs with incorrect property values under
+    parallel plans (Raúl Marín).
+  - #4120, ST_AsMVTGeom: Clip using tile coordinates (Raúl Marín).
 
 PostGIS 2.4.4
 2018/04/08

Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2018-07-10 13:42:23 UTC (rev 16639)
+++ trunk/postgis/mvt.c	2018-07-10 14:25:07 UTC (rev 16640)
@@ -701,7 +701,6 @@
 	double res = (resx < resy ? resx : resy)/2;
 	double fx = extent / width;
 	double fy = -(extent / height);
-	double buffer_map_xunits = resx * buffer;
 	int preserve_collapsed = LW_TRUE;
 	POSTGIS_DEBUG(2, "mvt_geom called");
 
@@ -725,6 +724,10 @@
 
 	if (clip_geom)
 	{
+		// 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);
 		GBOX bgbox;
 		const GBOX *lwgeom_gbox = lwgeom_get_bbox(lwgeom);;
 		bgbox = *gbox;

Modified: trunk/regress/mvt.sql
===================================================================
--- trunk/regress/mvt.sql	2018-07-10 13:42:23 UTC (rev 16639)
+++ trunk/regress/mvt.sql	2018-07-10 14:25:07 UTC (rev 16640)
@@ -138,6 +138,72 @@
 	ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)),
 	4096, 0, false));
 
+-- Clipping right in the borders
+SELECT 'PG26', ST_AsText(ST_AsMVTGeom(
+	ST_Point(-1, -1),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
+	10, 1, true));
+
+SELECT 'PG27', ST_AsText(ST_AsMVTGeom(
+	ST_Point(-1, 11),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
+	10, 1, true));
+
+SELECT 'PG28', ST_AsText(ST_AsMVTGeom(
+	ST_Point(11, -1),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
+	10, 1, true));
+
+SELECT 'PG29', ST_AsText(ST_AsMVTGeom(
+	ST_Point(11, 11),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
+	10, 1, true));
+
+SELECT 'PG30', ST_AsText(ST_AsMVTGeom(
+	ST_Point(11.5, 11.5),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
+	10, 1, true));
+
+SELECT 'PG31', ST_AsText(ST_AsMVTGeom(
+	ST_Point(11.49, 11.49),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
+	10, 1, true));
+
+SELECT 'PG32', ST_AsText(ST_AsMVTGeom(
+	ST_Point(-1.5, -1.5),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
+	10, 1, true));
+
+SELECT 'PG33', ST_AsText(ST_AsMVTGeom(
+	ST_Point(-1.49, -1.49),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
+	10, 1, true));
+
+SELECT 'PG34', ST_AsText(ST_AsMVTGeom(
+	ST_Point(-1.5, 11.5),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
+	10, 1, true));
+
+SELECT 'PG35', ST_AsText(ST_AsMVTGeom(
+	ST_Point(4352.49, -256.49),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)),
+	4096, 256, true));
+
+SELECT 'PG36', ST_AsText(ST_AsMVTGeom(
+	ST_Point(4352.49, -256.50),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)),
+	4096, 256, true));
+
+SELECT 'PG37', ST_AsText(ST_AsMVTGeom(
+	ST_Point(4352.50, -256.49),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)),
+	4096, 256, true));
+
+SELECT 'PG38', ST_AsText(ST_AsMVTGeom(
+	ST_Point(4352.50, -256.50),
+	ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)),
+	4096, 256, true));
+
 -- 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-10 13:42:23 UTC (rev 16639)
+++ trunk/regress/mvt_expected	2018-07-10 14:25:07 UTC (rev 16640)
@@ -23,6 +23,19 @@
 PG23|MULTILINESTRING((1 9,5 5),(2 2,5 5))
 PG24|MULTILINESTRING((1 9,5 5),(1 9,5 5))
 PG25|MULTILINESTRING((1 4095,1001 3095),(2 4094,1002 3094))
+PG26|POINT(-1 11)
+PG27|POINT(-1 -1)
+PG28|POINT(11 11)
+PG29|POINT(11 -1)
+PG30|
+PG31|POINT(11 -1)
+PG32|
+PG33|POINT(-1 11)
+PG34|
+PG35|POINT(4352 4352)
+PG36|
+PG37|
+PG38|
 TG1|GiEKBHRlc3QSDBICAAAYASIECTLePxoCYzEiAigBKIAgeAI=
 TG2|GiMKBHRlc3QSDhICAAAYASIGETLePwIBGgJjMSICKAEogCB4Ag==
 TG3|GiYKBHRlc3QSERICAAAYAiIJCQCAQArQD88PGgJjMSICKAEogCB4Ag==



More information about the postgis-tickets mailing list