From: Raúl Marín Rodríguez Date: Tue, 10 Jul 2018 14:25:07 +0000 (+0000) Subject: ST_AsMVTGeom: Clip using tile coordinates X-Git-Tag: 2.5.0beta2~46 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=edd91fb806bbc617ea0ec84261249a389502d0b7;p=postgis ST_AsMVTGeom: Clip using tile coordinates 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 --- diff --git a/NEWS b/NEWS index 442c56246..2e66607cd 100644 --- 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 diff --git a/postgis/mvt.c b/postgis/mvt.c index 2a94eed3d..2cdb2e86c 100644 --- a/postgis/mvt.c +++ b/postgis/mvt.c @@ -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; diff --git a/regress/mvt.sql b/regress/mvt.sql index 4b0548366..a4bb0aad4 100644 --- a/regress/mvt.sql +++ b/regress/mvt.sql @@ -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)'), diff --git a/regress/mvt_expected b/regress/mvt_expected index 0a1148684..35926ccf3 100644 --- a/regress/mvt_expected +++ b/regress/mvt_expected @@ -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==