From 2ec618000364ee537aafe8da2cb3272235d3c5c4 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Tue, 29 Aug 2023 10:54:39 -0700 Subject: [PATCH] Fix "strategies" accounting for 0-length linestrings and degenerate polygons (#137) * Dropping a 0-length feature doesn't count as dropping-as-needed * Add an option not to reduce tiny polygons to dust at maxzoom * Add test for prevention of tiny polygon reduction at maxzoom * Fix accounting for tiny polygons not to include degenerate geometries * Revert "Add test for prevention of tiny polygon reduction at maxzoom" This reverts commit f931bbd73e568881e4068b8f6882e599084313df. * Revert "Add an option not to reduce tiny polygons to dust at maxzoom" This reverts commit 03f0882bb618471384274e0019bb6bdeda2545ce. * Fix tests * Another test that no longer has any really tiny polygons * Oops, that broke LineString simplification * This time for sure! * Update changelog and version --- CHANGELOG.md | 4 ++++ geometry.cpp | 17 ++++++++------- geometry.hpp | 2 +- tests/allow-existing/both.mbtiles.json | 1 - .../out/-z1_--detect-shared-borders.json | 1 + .../out/-z1_--coalesce_--reorder.json | 1 - ..._-y_STATEFP10_-y_COUNTYFP10_-l_merged.json | 1 - tests/curve/out/-z2.json | 1 - tests/curve/out/-z2_--no-clipping.json | 1 - tests/curve/out/-z2_--no-duplication.json | 1 - tests/dateline/out/-z5.json | 1 - tests/dateline/out/-z5_-b0.json | 1 - ...2falg_-Lalbania%3atests%2fnamed%2falb.json | 1 + ...bania%3atests%2fnamed%2falb_-lunified.json | 1 + .../out/-R5%2f17%2f11.json | 1 - ...e_-zg_-M5000_--drop-densest-as-needed.json | 2 +- ..._-zg_-M5000_--drop-fraction-as-needed.json | 2 +- ..._-zg_-M5000_--drop-smallest-as-needed.json | 2 +- .../-ae_-zg_-M5000_--force-feature-limit.json | 2 +- .../out/-z0_--tiny-polygon-size_100.json | 2 +- ...polygon-size_50_--order-largest-first.json | 2 +- ...y-polygon-size_50_--simplification_50.json | 2 +- ...z2_--convert-polygons-to-label-points.json | 2 +- .../out/-z3_-ai.json | 2 +- .../out/-z4_-yname.json | 2 +- .../out/-z4_-yname_--drop-polygons.json | 2 +- .../out/-z4_-yname_-S4.json | 2 +- ...S4_--simplification-at-maximum-zoom_2.json | 2 +- .../out/-z4_-yname_-S4_--visvalingam.json | 2 +- .../out/-z4_-yname_-pD.json | 1 - .../out/-z4_-yname_-pc.json | 1 - ...5_-M5000_--coalesce-densest-as-needed.json | 2 +- ..._-M5000_--coalesce-fraction-as-needed.json | 2 +- ..._-M5000_--coalesce-smallest-as-needed.json | 2 +- .../-z5_-M5000_--drop-smallest-as-needed.json | 2 +- tests/ne_110m_ocean/join/joined.mbtiles.json | 2 +- tests/nullisland/out/-b0_-z4.json | 2 +- .../nullisland/out/-b0_-z4_-ANullIsland.json | 2 +- .../nullisland/out/-b0_-z4_-NNullIsland.json | 2 +- .../-z0_--reverse-source-polygon-winding.json | 1 + tile.cpp | 21 ++++++++++++------- version.hpp | 2 +- 42 files changed, 56 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b3f272f..0d405875 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.30.1 + +* Fix spurious reports of tiny polygons and 0-length LineStrings in "strategies" + # 2.30.0 * Add --extend-zooms-if-still-dropping-maximum option diff --git a/geometry.cpp b/geometry.cpp index a080012a..8c859e37 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -186,14 +186,15 @@ void check_polygon(drawvec &geom) { } } -drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area, serial_feature *this_feature, serial_feature *tiny_feature) { +drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *still_needs_simplification, bool *reduced_away, double *accum_area, serial_feature *this_feature, serial_feature *tiny_feature) { drawvec out; const double pixel = (1LL << (32 - detail - z)) * (double) tiny_polygon_size; bool includes_real = false; bool includes_dust = false; - *reduced = true; bool included_last_outer = false; + *still_needs_simplification = false; + *reduced_away = false; for (size_t i = 0; i < geom.size(); i++) { if (geom[i].op == VT_MOVETO) { @@ -223,9 +224,9 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double // cut out of, so we are just subtracting its area from the tiny polygon // rather than trying to deal with it geometrically if ((area > 0 && area <= pixel * pixel) || (area < 0 && !included_last_outer)) { - // printf("area is only %f vs %lld so using square\n", area, pixel * pixel); - *accum_area += area; + *reduced_away = true; + if (area > 0 && *accum_area > pixel * pixel) { // XXX use centroid; @@ -248,21 +249,23 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double // as a real geometry because otherwise we can accumulate enough tiny holes // that we will drop the next several outer rings getting back up to 0. else { - // printf("area is %f so keeping instead of %lld\n", area, pixel * pixel); - for (size_t k = i; k < j && k < geom.size(); k++) { out.push_back(geom[k]); } // which means that the overall polygon has a real geometry, // which means that it gets to be simplified. - *reduced = false; + *still_needs_simplification = true; includes_real = true; if (area > 0) { included_last_outer = true; } } + } else { + // area is 0: doesn't count as either having been reduced away, + // since it was probably just degenerate from having been clipped, + // or as needing simplification, since it produces no output. } i = j - 1; diff --git a/geometry.hpp b/geometry.hpp index 6a648789..1cff1768 100644 --- a/geometry.hpp +++ b/geometry.hpp @@ -68,7 +68,7 @@ drawvec clip_point(drawvec &geom, int z, long long buffer); drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip); drawvec simple_clip_poly(drawvec &geom, int z, int buffer); drawvec close_poly(drawvec &geom); -drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area, serial_feature *this_feature, serial_feature *tiny_feature); +drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *still_needs_simplification, bool *reduced_away, double *accum_area, serial_feature *this_feature, serial_feature *tiny_feature); int clip(double *x0, double *y0, double *x1, double *y1, double xmin, double ymin, double xmax, double ymax); drawvec clip_lines(drawvec &geom, int z, long long buffer); drawvec stairstep(drawvec &geom, int z, int detail); diff --git a/tests/allow-existing/both.mbtiles.json b/tests/allow-existing/both.mbtiles.json index b098b036..38f894e8 100644 --- a/tests/allow-existing/both.mbtiles.json +++ b/tests/allow-existing/both.mbtiles.json @@ -8,7 +8,6 @@ "maxzoom": "9", "minzoom": "8", "name": "tests/allow-existing/both.mbtiles", -"strategies": "[{},{},{},{},{},{},{},{},{\"tiny_polygons\":1},{}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/border/out/-z1_--detect-shared-borders.json b/tests/border/out/-z1_--detect-shared-borders.json index da06458f..d253c62b 100644 --- a/tests/border/out/-z1_--detect-shared-borders.json +++ b/tests/border/out/-z1_--detect-shared-borders.json @@ -9,6 +9,7 @@ "maxzoom": "1", "minzoom": "0", "name": "tests/border/out/-z1_--detect-shared-borders.json.check.mbtiles", +"strategies": "[{\"tiny_polygons\":1},{\"tiny_polygons\":1}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/coalesce-id/out/-z1_--coalesce_--reorder.json b/tests/coalesce-id/out/-z1_--coalesce_--reorder.json index 8b211745..71745aee 100644 --- a/tests/coalesce-id/out/-z1_--coalesce_--reorder.json +++ b/tests/coalesce-id/out/-z1_--coalesce_--reorder.json @@ -9,7 +9,6 @@ "maxzoom": "1", "minzoom": "0", "name": "tests/coalesce-id/out/-z1_--coalesce_--reorder.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":2}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/coalesce-tract/out/-P_--coalesce_--reorder_-z11_-Z11_-y_STATEFP10_-y_COUNTYFP10_-l_merged.json b/tests/coalesce-tract/out/-P_--coalesce_--reorder_-z11_-Z11_-y_STATEFP10_-y_COUNTYFP10_-l_merged.json index 5559db60..0f3abcfc 100644 --- a/tests/coalesce-tract/out/-P_--coalesce_--reorder_-z11_-Z11_-y_STATEFP10_-y_COUNTYFP10_-l_merged.json +++ b/tests/coalesce-tract/out/-P_--coalesce_--reorder_-z11_-Z11_-y_STATEFP10_-y_COUNTYFP10_-l_merged.json @@ -9,7 +9,6 @@ "maxzoom": "11", "minzoom": "11", "name": "tests/coalesce-tract/out/-P_--coalesce_--reorder_-z11_-Z11_-y_STATEFP10_-y_COUNTYFP10_-l_merged.json.check.mbtiles", -"strategies": "[{},{},{},{},{},{},{},{},{},{},{},{\"tiny_polygons\":5}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/curve/out/-z2.json b/tests/curve/out/-z2.json index 729fe6b2..9c176390 100644 --- a/tests/curve/out/-z2.json +++ b/tests/curve/out/-z2.json @@ -9,7 +9,6 @@ "maxzoom": "2", "minzoom": "0", "name": "tests/curve/out/-z2.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":4}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/curve/out/-z2_--no-clipping.json b/tests/curve/out/-z2_--no-clipping.json index 0a37140a..efe45048 100644 --- a/tests/curve/out/-z2_--no-clipping.json +++ b/tests/curve/out/-z2_--no-clipping.json @@ -9,7 +9,6 @@ "maxzoom": "2", "minzoom": "0", "name": "tests/curve/out/-z2_--no-clipping.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":10}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/curve/out/-z2_--no-duplication.json b/tests/curve/out/-z2_--no-duplication.json index 1db93917..13ef3f5e 100644 --- a/tests/curve/out/-z2_--no-duplication.json +++ b/tests/curve/out/-z2_--no-duplication.json @@ -9,7 +9,6 @@ "maxzoom": "2", "minzoom": "0", "name": "tests/curve/out/-z2_--no-duplication.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":6},{\"tiny_polygons\":6}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/dateline/out/-z5.json b/tests/dateline/out/-z5.json index 7f174dda..aa7e55d1 100644 --- a/tests/dateline/out/-z5.json +++ b/tests/dateline/out/-z5.json @@ -9,7 +9,6 @@ "maxzoom": "5", "minzoom": "0", "name": "tests/dateline/out/-z5.json.check.mbtiles", -"strategies": "[{},{},{},{\"tiny_polygons\":1},{},{\"tiny_polygons\":1}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/dateline/out/-z5_-b0.json b/tests/dateline/out/-z5_-b0.json index 951fdf90..748392ea 100644 --- a/tests/dateline/out/-z5_-b0.json +++ b/tests/dateline/out/-z5_-b0.json @@ -9,7 +9,6 @@ "maxzoom": "5", "minzoom": "0", "name": "tests/dateline/out/-z5_-b0.json.check.mbtiles", -"strategies": "[{},{},{},{\"tiny_polygons\":1},{},{}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb.json b/tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb.json index ae9c7c82..b055ea39 100644 --- a/tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb.json +++ b/tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb.json @@ -9,6 +9,7 @@ "maxzoom": "0", "minzoom": "0", "name": "tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb.json.check.mbtiles", +"strategies": "[{\"tiny_polygons\":1}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb_-lunified.json b/tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb_-lunified.json index e6f5c128..9df10d2c 100644 --- a/tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb_-lunified.json +++ b/tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb_-lunified.json @@ -9,6 +9,7 @@ "maxzoom": "0", "minzoom": "0", "name": "tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb_-lunified.json.check.mbtiles", +"strategies": "[{\"tiny_polygons\":1}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-R5%2f17%2f11.json b/tests/ne_110m_admin_0_countries/out/-R5%2f17%2f11.json index 2802a761..eb6aa275 100644 --- a/tests/ne_110m_admin_0_countries/out/-R5%2f17%2f11.json +++ b/tests/ne_110m_admin_0_countries/out/-R5%2f17%2f11.json @@ -9,7 +9,6 @@ "maxzoom": "5", "minzoom": "5", "name": "tests/ne_110m_admin_0_countries/out/-R5%2f17%2f11.json.check.mbtiles", -"strategies": "[{},{},{},{},{},{\"tiny_polygons\":1}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-densest-as-needed.json b/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-densest-as-needed.json index 685dab86..2c51e8fc 100644 --- a/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-densest-as-needed.json +++ b/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-densest-as-needed.json @@ -9,7 +9,7 @@ "maxzoom": "5", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-densest-as-needed.json.check.mbtiles", -"strategies": "[{\"dropped_as_needed\":171,\"tile_size_desired\":39209},{\"dropped_as_needed\":189,\"tiny_polygons\":1,\"tile_size_desired\":25164},{\"dropped_as_needed\":161,\"tiny_polygons\":2,\"tile_size_desired\":21198},{\"dropped_as_needed\":134,\"tiny_polygons\":12,\"tile_size_desired\":10761},{\"dropped_as_needed\":62,\"tiny_polygons\":20,\"tile_size_desired\":6604},{\"tiny_polygons\":47}]", +"strategies": "[{\"dropped_as_needed\":171,\"tile_size_desired\":39209},{\"dropped_as_needed\":189,\"tile_size_desired\":25164},{\"dropped_as_needed\":161,\"tile_size_desired\":21198},{\"dropped_as_needed\":134,\"tile_size_desired\":10761},{\"dropped_as_needed\":62,\"tile_size_desired\":6604},{\"tiny_polygons\":2}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-fraction-as-needed.json b/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-fraction-as-needed.json index 4740f3ce..a36cc700 100644 --- a/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-fraction-as-needed.json +++ b/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-fraction-as-needed.json @@ -9,7 +9,7 @@ "maxzoom": "5", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-fraction-as-needed.json.check.mbtiles", -"strategies": "[{\"dropped_as_needed\":160,\"tile_size_desired\":39209},{\"dropped_as_needed\":188,\"tile_size_desired\":25164},{\"dropped_as_needed\":190,\"tiny_polygons\":2,\"tile_size_desired\":21198},{\"dropped_as_needed\":180,\"tiny_polygons\":9,\"tile_size_desired\":10761},{\"dropped_as_needed\":145,\"tiny_polygons\":17,\"tile_size_desired\":6604},{\"tiny_polygons\":47}]", +"strategies": "[{\"dropped_as_needed\":160,\"tile_size_desired\":39209},{\"dropped_as_needed\":188,\"tile_size_desired\":25164},{\"dropped_as_needed\":190,\"tile_size_desired\":21198},{\"dropped_as_needed\":180,\"tile_size_desired\":10761},{\"dropped_as_needed\":145,\"tile_size_desired\":6604},{\"tiny_polygons\":2}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-smallest-as-needed.json b/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-smallest-as-needed.json index b726de3f..83c820d8 100644 --- a/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-smallest-as-needed.json +++ b/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-smallest-as-needed.json @@ -9,7 +9,7 @@ "maxzoom": "5", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-smallest-as-needed.json.check.mbtiles", -"strategies": "[{\"dropped_as_needed\":174,\"tile_size_desired\":39209},{\"dropped_as_needed\":202,\"tile_size_desired\":25164},{\"dropped_as_needed\":190,\"tiny_polygons\":2,\"tile_size_desired\":21198},{\"dropped_as_needed\":156,\"tiny_polygons\":12,\"tile_size_desired\":10761},{\"dropped_as_needed\":80,\"tiny_polygons\":20,\"tile_size_desired\":6604},{\"tiny_polygons\":47}]", +"strategies": "[{\"dropped_as_needed\":174,\"tile_size_desired\":39209},{\"dropped_as_needed\":202,\"tile_size_desired\":25164},{\"dropped_as_needed\":190,\"tile_size_desired\":21198},{\"dropped_as_needed\":156,\"tile_size_desired\":10761},{\"dropped_as_needed\":80,\"tile_size_desired\":6604},{\"tiny_polygons\":2}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--force-feature-limit.json b/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--force-feature-limit.json index a0ce79b3..298a2ad8 100644 --- a/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--force-feature-limit.json +++ b/tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--force-feature-limit.json @@ -9,7 +9,7 @@ "maxzoom": "5", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--force-feature-limit.json.check.mbtiles", -"strategies": "[{\"dropped_as_needed\":316,\"tile_size_desired\":39209},{\"dropped_as_needed\":287,\"tiny_polygons\":4,\"tile_size_desired\":25164},{\"dropped_as_needed\":223,\"tiny_polygons\":4,\"tile_size_desired\":21198},{\"dropped_as_needed\":93,\"tiny_polygons\":14,\"tile_size_desired\":10761},{\"dropped_as_needed\":9,\"tiny_polygons\":21,\"tile_size_desired\":6604},{\"tiny_polygons\":47}]", +"strategies": "[{\"dropped_as_needed\":316,\"tile_size_desired\":39209},{\"dropped_as_needed\":287,\"tiny_polygons\":3,\"tile_size_desired\":25164},{\"dropped_as_needed\":223,\"tiny_polygons\":2,\"tile_size_desired\":21198},{\"dropped_as_needed\":93,\"tile_size_desired\":10761},{\"dropped_as_needed\":9,\"tile_size_desired\":6604},{\"tiny_polygons\":2}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_100.json b/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_100.json index e430efea..b36b2236 100644 --- a/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_100.json +++ b/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_100.json @@ -9,7 +9,7 @@ "maxzoom": "0", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_100.json.check.mbtiles", -"strategies": "[{\"tiny_polygons\":138}]", +"strategies": "[{\"tiny_polygons\":150}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--order-largest-first.json b/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--order-largest-first.json index 841f5ca2..2c949e5c 100644 --- a/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--order-largest-first.json +++ b/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--order-largest-first.json @@ -9,7 +9,7 @@ "maxzoom": "0", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--order-largest-first.json.check.mbtiles", -"strategies": "[{\"tiny_polygons\":90}]", +"strategies": "[{\"tiny_polygons\":109}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--simplification_50.json b/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--simplification_50.json index 001d425e..e95bc206 100644 --- a/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--simplification_50.json +++ b/tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--simplification_50.json @@ -9,7 +9,7 @@ "maxzoom": "0", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--simplification_50.json.check.mbtiles", -"strategies": "[{\"tiny_polygons\":90}]", +"strategies": "[{\"tiny_polygons\":109}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z2_--convert-polygons-to-label-points.json b/tests/ne_110m_admin_0_countries/out/-z2_--convert-polygons-to-label-points.json index 3bc88d86..66254af7 100644 --- a/tests/ne_110m_admin_0_countries/out/-z2_--convert-polygons-to-label-points.json +++ b/tests/ne_110m_admin_0_countries/out/-z2_--convert-polygons-to-label-points.json @@ -9,7 +9,7 @@ "maxzoom": "2", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z2_--convert-polygons-to-label-points.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3}]", +"strategies": "[{},{},{\"tiny_polygons\":1}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z3_-ai.json b/tests/ne_110m_admin_0_countries/out/-z3_-ai.json index 65b7bcd4..ead9bfb7 100644 --- a/tests/ne_110m_admin_0_countries/out/-z3_-ai.json +++ b/tests/ne_110m_admin_0_countries/out/-z3_-ai.json @@ -9,7 +9,7 @@ "maxzoom": "3", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z3_-ai.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3},{\"tiny_polygons\":12}]", +"strategies": "[{},{},{\"tiny_polygons\":1},{}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z4_-yname.json b/tests/ne_110m_admin_0_countries/out/-z4_-yname.json index a1142d3a..5bf67b0e 100644 --- a/tests/ne_110m_admin_0_countries/out/-z4_-yname.json +++ b/tests/ne_110m_admin_0_countries/out/-z4_-yname.json @@ -9,7 +9,7 @@ "maxzoom": "4", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z4_-yname.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3},{\"tiny_polygons\":12},{\"tiny_polygons\":20}]", +"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":1},{},{}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z4_-yname_--drop-polygons.json b/tests/ne_110m_admin_0_countries/out/-z4_-yname_--drop-polygons.json index efe6c2ea..53da3cee 100644 --- a/tests/ne_110m_admin_0_countries/out/-z4_-yname_--drop-polygons.json +++ b/tests/ne_110m_admin_0_countries/out/-z4_-yname_--drop-polygons.json @@ -9,7 +9,7 @@ "maxzoom": "4", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_--drop-polygons.json.check.mbtiles", -"strategies": "[{\"dropped_by_rate\":172},{\"dropped_by_rate\":205,\"tiny_polygons\":1},{\"dropped_by_rate\":189},{\"dropped_by_rate\":166,\"tiny_polygons\":7},{\"tiny_polygons\":20}]", +"strategies": "[{\"dropped_by_rate\":172},{\"dropped_by_rate\":205},{\"dropped_by_rate\":189},{\"dropped_by_rate\":166},{}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4.json b/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4.json index 7c1b41c9..4600509f 100644 --- a/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4.json +++ b/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4.json @@ -9,7 +9,7 @@ "maxzoom": "4", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3},{\"tiny_polygons\":12},{\"tiny_polygons\":20}]", +"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":1},{},{}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--simplification-at-maximum-zoom_2.json b/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--simplification-at-maximum-zoom_2.json index 85ecf832..e4c33cc4 100644 --- a/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--simplification-at-maximum-zoom_2.json +++ b/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--simplification-at-maximum-zoom_2.json @@ -9,7 +9,7 @@ "maxzoom": "4", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--simplification-at-maximum-zoom_2.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3},{\"tiny_polygons\":12},{\"tiny_polygons\":20}]", +"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":1},{},{}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--visvalingam.json b/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--visvalingam.json index 5c185e56..dc19a314 100644 --- a/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--visvalingam.json +++ b/tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--visvalingam.json @@ -9,7 +9,7 @@ "maxzoom": "4", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--visvalingam.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3},{\"tiny_polygons\":12},{\"tiny_polygons\":20}]", +"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":1},{},{}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z4_-yname_-pD.json b/tests/ne_110m_admin_0_countries/out/-z4_-yname_-pD.json index f2af6fc6..d2f2b3de 100644 --- a/tests/ne_110m_admin_0_countries/out/-z4_-yname_-pD.json +++ b/tests/ne_110m_admin_0_countries/out/-z4_-yname_-pD.json @@ -9,7 +9,6 @@ "maxzoom": "4", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_-pD.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":45},{\"tiny_polygons\":29},{\"tiny_polygons\":70},{\"tiny_polygons\":120}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z4_-yname_-pc.json b/tests/ne_110m_admin_0_countries/out/-z4_-yname_-pc.json index ea076b58..f4a1c705 100644 --- a/tests/ne_110m_admin_0_countries/out/-z4_-yname_-pc.json +++ b/tests/ne_110m_admin_0_countries/out/-z4_-yname_-pc.json @@ -9,7 +9,6 @@ "maxzoom": "4", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_-pc.json.check.mbtiles", -"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":8},{\"tiny_polygons\":32},{\"tiny_polygons\":63}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-densest-as-needed.json b/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-densest-as-needed.json index bb43352e..2396c0e8 100644 --- a/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-densest-as-needed.json +++ b/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-densest-as-needed.json @@ -9,7 +9,7 @@ "maxzoom": "5", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-densest-as-needed.json.check.mbtiles", -"strategies": "[{\"coalesced_as_needed\":528,\"detail_reduced\":2,\"tile_size_desired\":39204},{\"coalesced_as_needed\":212,\"tile_size_desired\":25156},{\"coalesced_as_needed\":192,\"tiny_polygons\":3,\"tile_size_desired\":21207},{\"coalesced_as_needed\":156,\"tiny_polygons\":11,\"tile_size_desired\":10753},{\"coalesced_as_needed\":65,\"tiny_polygons\":20,\"tile_size_desired\":6588},{\"tiny_polygons\":46}]", +"strategies": "[{\"coalesced_as_needed\":528,\"detail_reduced\":2,\"tiny_polygons\":2,\"tile_size_desired\":39204},{\"coalesced_as_needed\":212,\"tile_size_desired\":25156},{\"coalesced_as_needed\":192,\"tiny_polygons\":1,\"tile_size_desired\":21207},{\"coalesced_as_needed\":156,\"tile_size_desired\":10753},{\"coalesced_as_needed\":65,\"tile_size_desired\":6588},{\"tiny_polygons\":1}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-fraction-as-needed.json b/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-fraction-as-needed.json index 130b09ae..3b2a17ea 100644 --- a/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-fraction-as-needed.json +++ b/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-fraction-as-needed.json @@ -9,7 +9,7 @@ "maxzoom": "5", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-fraction-as-needed.json.check.mbtiles", -"strategies": "[{\"coalesced_as_needed\":528,\"detail_reduced\":2,\"tile_size_desired\":39204},{\"coalesced_as_needed\":217,\"tile_size_desired\":25156},{\"coalesced_as_needed\":218,\"tiny_polygons\":2,\"tile_size_desired\":21207},{\"coalesced_as_needed\":227,\"tiny_polygons\":4,\"tile_size_desired\":10753},{\"coalesced_as_needed\":192,\"tiny_polygons\":13,\"tile_size_desired\":6588},{\"tiny_polygons\":46}]", +"strategies": "[{\"coalesced_as_needed\":528,\"detail_reduced\":2,\"tiny_polygons\":2,\"tile_size_desired\":39204},{\"coalesced_as_needed\":217,\"tile_size_desired\":25156},{\"coalesced_as_needed\":218,\"tile_size_desired\":21207},{\"coalesced_as_needed\":227,\"tile_size_desired\":10753},{\"coalesced_as_needed\":192,\"tile_size_desired\":6588},{\"tiny_polygons\":1}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-smallest-as-needed.json b/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-smallest-as-needed.json index 00e5e1ba..d61aa42f 100644 --- a/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-smallest-as-needed.json +++ b/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-smallest-as-needed.json @@ -9,7 +9,7 @@ "maxzoom": "5", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-smallest-as-needed.json.check.mbtiles", -"strategies": "[{\"coalesced_as_needed\":1272,\"tile_size_desired\":39204},{\"coalesced_as_needed\":1191,\"tiny_polygons\":1,\"tile_size_desired\":25156},{\"coalesced_as_needed\":731,\"tiny_polygons\":3,\"tile_size_desired\":21207},{\"coalesced_as_needed\":178,\"tiny_polygons\":8,\"tile_size_desired\":10753},{\"coalesced_as_needed\":74,\"tiny_polygons\":20,\"tile_size_desired\":6588},{\"tiny_polygons\":46}]", +"strategies": "[{\"coalesced_as_needed\":1272,\"tiny_polygons\":5,\"tile_size_desired\":39204},{\"coalesced_as_needed\":1191,\"tile_size_desired\":25156},{\"coalesced_as_needed\":731,\"tiny_polygons\":1,\"tile_size_desired\":21207},{\"coalesced_as_needed\":178,\"tile_size_desired\":10753},{\"coalesced_as_needed\":74,\"tile_size_desired\":6588},{\"tiny_polygons\":1}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--drop-smallest-as-needed.json b/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--drop-smallest-as-needed.json index 3ea3bfc2..d7b303a3 100644 --- a/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--drop-smallest-as-needed.json +++ b/tests/ne_110m_admin_0_countries/out/-z5_-M5000_--drop-smallest-as-needed.json @@ -9,7 +9,7 @@ "maxzoom": "5", "minzoom": "0", "name": "tests/ne_110m_admin_0_countries/out/-z5_-M5000_--drop-smallest-as-needed.json.check.mbtiles", -"strategies": "[{\"dropped_as_needed\":174,\"tile_size_desired\":39204},{\"dropped_as_needed\":202,\"tile_size_desired\":25156},{\"dropped_as_needed\":190,\"tiny_polygons\":2,\"tile_size_desired\":21207},{\"dropped_as_needed\":156,\"tiny_polygons\":12,\"tile_size_desired\":10753},{\"dropped_as_needed\":78,\"tiny_polygons\":20,\"tile_size_desired\":6588},{\"tiny_polygons\":46}]", +"strategies": "[{\"dropped_as_needed\":174,\"tile_size_desired\":39204},{\"dropped_as_needed\":202,\"tile_size_desired\":25156},{\"dropped_as_needed\":190,\"tile_size_desired\":21207},{\"dropped_as_needed\":156,\"tile_size_desired\":10753},{\"dropped_as_needed\":78,\"tile_size_desired\":6588},{\"tiny_polygons\":1}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/ne_110m_ocean/join/joined.mbtiles.json b/tests/ne_110m_ocean/join/joined.mbtiles.json index 8f81b5cb..ca0059b9 100644 --- a/tests/ne_110m_ocean/join/joined.mbtiles.json +++ b/tests/ne_110m_ocean/join/joined.mbtiles.json @@ -9,7 +9,7 @@ "maxzoom": "4", "minzoom": "0", "name": "tests/ne_110m_ocean/join/ocean.mbtiles + tests/ne_110m_ocean/join/countries.mbtiles", -"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3},{\"tiny_polygons\":12},{\"tiny_polygons\":23}]", +"strategies": "[{},{},{},{},{\"tiny_polygons\":4}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/nullisland/out/-b0_-z4.json b/tests/nullisland/out/-b0_-z4.json index 3e54ff83..fa01a450 100644 --- a/tests/nullisland/out/-b0_-z4.json +++ b/tests/nullisland/out/-b0_-z4.json @@ -9,7 +9,7 @@ "maxzoom": "4", "minzoom": "0", "name": "tests/nullisland/out/-b0_-z4.json.check.mbtiles", -"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8,\"tiny_polygons\":12},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]", +"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/nullisland/out/-b0_-z4_-ANullIsland.json b/tests/nullisland/out/-b0_-z4_-ANullIsland.json index 2478bb9d..5df2343f 100644 --- a/tests/nullisland/out/-b0_-z4_-ANullIsland.json +++ b/tests/nullisland/out/-b0_-z4_-ANullIsland.json @@ -10,7 +10,7 @@ "maxzoom": "4", "minzoom": "0", "name": "tests/nullisland/out/-b0_-z4_-ANullIsland.json.check.mbtiles", -"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8,\"tiny_polygons\":12},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]", +"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/nullisland/out/-b0_-z4_-NNullIsland.json b/tests/nullisland/out/-b0_-z4_-NNullIsland.json index 6e89f8e2..4e30ff72 100644 --- a/tests/nullisland/out/-b0_-z4_-NNullIsland.json +++ b/tests/nullisland/out/-b0_-z4_-NNullIsland.json @@ -9,7 +9,7 @@ "maxzoom": "4", "minzoom": "0", "name": "tests/nullisland/out/-b0_-z4_-NNullIsland.json.check.mbtiles", -"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8,\"tiny_polygons\":12},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]", +"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tests/polygon-winding/out/-z0_--reverse-source-polygon-winding.json b/tests/polygon-winding/out/-z0_--reverse-source-polygon-winding.json index fcbc8b14..c8a96de1 100644 --- a/tests/polygon-winding/out/-z0_--reverse-source-polygon-winding.json +++ b/tests/polygon-winding/out/-z0_--reverse-source-polygon-winding.json @@ -9,6 +9,7 @@ "maxzoom": "0", "minzoom": "0", "name": "tests/polygon-winding/out/-z0_--reverse-source-polygon-winding.json.check.mbtiles", +"strategies": "[{\"tiny_polygons\":1}]", "type": "overlay", "version": "2" }, "features": [ diff --git a/tile.cpp b/tile.cpp index 7c2dad24..d3b40618 100644 --- a/tile.cpp +++ b/tile.cpp @@ -2138,14 +2138,14 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch add_sample_to(extents, sf.extent, extents_increment, seq); // search here is for LLONG_MAX, not minextent, because we are dropping features, not coalescing them, // so we shouldn't expect to find anything small that we can related this feature to. - if (sf.extent + coalesced_area <= minextent && find_partial(partials, sf, which_partial, layer_unmaps, LLONG_MAX)) { + if (minextent != 0 && sf.extent + coalesced_area <= minextent && find_partial(partials, sf, which_partial, layer_unmaps, LLONG_MAX)) { preserve_attributes(arg->attribute_accum, sf, stringpool, pool_off, partials[which_partial]); strategy->dropped_as_needed++; continue; } } else if (additional[A_COALESCE_SMALLEST_AS_NEEDED]) { add_sample_to(extents, sf.extent, extents_increment, seq); - if (sf.extent + coalesced_area <= minextent && find_partial(partials, sf, which_partial, layer_unmaps, minextent)) { + if (minextent != 0 && sf.extent + coalesced_area <= minextent && find_partial(partials, sf, which_partial, layer_unmaps, minextent)) { partials[which_partial].geoms.push_back(sf.geometry); partials[which_partial].coalesced = true; coalesced_area += sf.extent; @@ -2182,18 +2182,25 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch } fraction_accum -= 1; - bool reduced = false; - if (sf.t == VT_POLYGON) { + bool still_need_simplification_after_reduction = false; + if (sf.t == VT_POLYGON && sf.geometry.size() > 0) { + bool simplified_away_by_reduction = false; + if (!prevent[P_TINY_POLYGON_REDUCTION] && !additional[A_GRID_LOW_ZOOMS]) { - sf.geometry = reduce_tiny_poly(sf.geometry, z, line_detail, &reduced, &accum_area, &sf, &tiny_feature); - if (reduced) { + sf.geometry = reduce_tiny_poly(sf.geometry, z, line_detail, &still_need_simplification_after_reduction, &simplified_away_by_reduction, &accum_area, &sf, &tiny_feature); + if (simplified_away_by_reduction) { strategy->tiny_polygons++; } if (sf.geometry.size() == 0) { continue; } + } else { + still_need_simplification_after_reduction = true; // reduction skipped, so always simplify } + } else { + still_need_simplification_after_reduction = true; // not a polygon, so simplify } + if (sf.t == VT_POLYGON || sf.t == VT_LINE) { if (line_is_too_small(sf.geometry, z, line_detail)) { continue; @@ -2220,7 +2227,7 @@ long long write_tile(decompressor *geoms, std::atomic *geompos_in, ch p.t = sf.t; p.segment = sf.segment; p.original_seq = sf.seq; - p.reduced = reduced; + p.reduced = !still_need_simplification_after_reduction; p.coalesced = false; p.z = z; p.tx = tx; diff --git a/version.hpp b/version.hpp index 4a532e6b..77b92426 100644 --- a/version.hpp +++ b/version.hpp @@ -1,6 +1,6 @@ #ifndef VERSION_HPP #define VERSION_HPP -#define VERSION "v2.30.0" +#define VERSION "v2.30.1" #endif