From e5c92b18ffad323b3996fd68f0b23f80dc5bca28 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ra=C3=BAl=20Mar=C3=ADn=20Rodr=C3=ADguez?= Date: Wed, 29 Aug 2018 13:21:10 +0000 Subject: [PATCH] MVT: Drop geometries smaller than the resolution Closes #4161 Closes https://github.com/postgis/postgis/pull/288 git-svn-id: http://svn.osgeo.org/postgis/trunk@16711 b70326c6-7e19-0410-871a-916f4a2858ee --- NEWS | 1 + postgis/mvt.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/NEWS b/NEWS index f15fefe42..d9c82b749 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,7 @@ PostGIS 3.0.0 - #4162, ST_DWithin documentation examples for storing geometry and radius in table (Darafei Praliaskouski, github user Boscop). - #4163, MVT: Fix resource leak when the first geometry is NULL (Raúl Marín) + - #4161, MVT: Drop geometries smaller than the resolution (Raúl Marín) PostGIS 2.5.0rc1 2018/08/19 diff --git a/postgis/mvt.c b/postgis/mvt.c index cdca7e68d..2b21d8dd5 100644 --- a/postgis/mvt.c +++ b/postgis/mvt.c @@ -794,6 +794,17 @@ LWGEOM *mvt_geom(LWGEOM *lwgeom, const GBOX *gbox, uint32_t extent, uint32_t buf fx = extent / width; fy = -(extent / height); + if (FLAGS_GET_BBOX(lwgeom->flags) && lwgeom->bbox && + (lwgeom->type == LINETYPE || lwgeom->type == MULTILINETYPE || + lwgeom->type == POLYGONTYPE || lwgeom->type == MULTIPOLYGONTYPE)) + { + // Shortcut to drop geometries smaller than the resolution + double bbox_width = lwgeom->bbox->xmax - lwgeom->bbox->xmin; + double bbox_height = lwgeom->bbox->ymax - lwgeom->bbox->ymin; + if (bbox_height * bbox_height + bbox_width * bbox_width < res * res) + return NULL; + } + /* 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); -- 2.40.0