]> granicus.if.org Git - postgis/commitdiff
ST_AsMVTGeom: Clip using tile coordinates
authorRaúl Marín Rodríguez <rmrodriguez@carto.com>
Tue, 10 Jul 2018 14:25:07 +0000 (14:25 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Tue, 10 Jul 2018 14:25:07 +0000 (14:25 +0000)
Closes #4120
Closes https://github.com/postgis/postgis/pull/267

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

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

diff --git a/NEWS b/NEWS
index 442c562460f5e7da49f26035483eb669fe9fd07b..2e66607cd8bf468fb5651cc624e3dab06c3eaa07 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ PostGIS 2.5.0beta2
 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 @@ PostGIS 2.5.0
   - #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
index 2a94eed3db60b64d0f810e1841859d1a3d555288..2cdb2e86c2cd382ffa9025a296d19e8f794578c6 100644 (file)
@@ -701,7 +701,6 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buf
        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 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buf
 
        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;
index 4b05483668723297fa35988738d1e39c8083fe8d..a4bb0aad4b71b49a4dcc319c762835f30ee80fe0 100644 (file)
@@ -138,6 +138,72 @@ SELECT 'PG25', ST_AsText(ST_AsMVTGeom(
        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)'),
index 0a1148684151a6e20bd7ea6a32392d9f49e023b8..35926ccf311c4efe50fc6c1839921737a65c69cb 100644 (file)
@@ -23,6 +23,19 @@ PG22|
 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==