From 86b856720117f9b54230461d6f8eee6b61ddc348 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 18 Apr 2016 15:46:07 -0700 Subject: [PATCH] Clean up polygon geometry again after coalescing --- CHANGELOG.md | 4 ++++ README.md | 4 +++- man/tippecanoe.1 | 4 +++- tests/overlap/in.json | 1 + tests/overlap/out/-z0.json | 20 ++++++++++++++++++++ tests/overlap/out/-z0_--coalesce.json | 18 ++++++++++++++++++ tile.cc | 9 ++++++++- version.h | 2 +- 8 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 tests/overlap/in.json create mode 100644 tests/overlap/out/-z0.json create mode 100644 tests/overlap/out/-z0_--coalesce.json diff --git a/CHANGELOG.md b/CHANGELOG.md index a312786..1aff50e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.9.14 + +* Clean up polygons after coalescing, if necessary + ## 1.9.13 * Don't trust the OS so much about how many files can be open diff --git a/README.md b/README.md index 1a1d795..60a4e12 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,9 @@ resolution is obtained than by using a smaller _maxzoom_ or _detail_. ### Doing more - * -ac or --coalesce: Coalesce adjacent line and polygon features that have the same properties + * -ac or --coalesce: Coalesce adjacent line and polygon features that have the same properties. + Note that when overlapping polygons are coalesced, the overlapping region is treated as a hole, + which may not be what you want. * -ar or --reverse: Try reversing the directions of lines to make them coalesce and compress better * -ao or --reorder: Reorder features to put ones with the same properties in sequence, to try to get them to coalesce * -al or --drop-lines: Let "dot" dropping at lower zooms apply to lines too diff --git a/man/tippecanoe.1 b/man/tippecanoe.1 index 793e490..8f54e9d 100644 --- a/man/tippecanoe.1 +++ b/man/tippecanoe.1 @@ -134,7 +134,9 @@ compensate for the larger marker, or \-rf\fInumber\fP to allow at most \fInumber .SS Doing more .RS .IP \(bu 2 -\-ac or \-\-coalesce: Coalesce adjacent line and polygon features that have the same properties +\-ac or \-\-coalesce: Coalesce adjacent line and polygon features that have the same properties. +Note that when overlapping polygons are coalesced, the overlapping region is treated as a hole, +which may not be what you want. .IP \(bu 2 \-ar or \-\-reverse: Try reversing the directions of lines to make them coalesce and compress better .IP \(bu 2 diff --git a/tests/overlap/in.json b/tests/overlap/in.json new file mode 100644 index 0000000..b0fa6b4 --- /dev/null +++ b/tests/overlap/in.json @@ -0,0 +1 @@ +{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-81.5625,63.39152174400882],[-113.90625,53.12040528310657],[-135.703125,29.22889003019423],[-118.125,-9.79567758282973],[-75.9375,-31.353636941500987],[-17.578125,-22.593726063929296],[-5.625,8.407168163601076],[-10.1953125,50.51342652633956],[-28.125,59.712097173322924],[-81.5625,63.39152174400882]]]}},{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-93.515625,75.32002523220804],[-113.90625,69.41124235697256],[-117.0703125,60.06484046010452],[-103.35937499999999,39.36827914916011],[-71.3671875,29.84064389983444],[-37.265625,34.88593094075317],[-3.515625,61.270232790000634],[-33.3984375,79.03843742487174],[-74.8828125,79.17133464081945],[-93.515625,75.32002523220804]]]}}]} \ No newline at end of file diff --git a/tests/overlap/out/-z0.json b/tests/overlap/out/-z0.json new file mode 100644 index 0000000..e1fa9b5 --- /dev/null +++ b/tests/overlap/out/-z0.json @@ -0,0 +1,20 @@ +{ "type": "FeatureCollection", "properties": { +"bounds": "-135.703125,-31.353637,-3.515625,79.171335", +"center": "-3.515625,0.000000,0", +"description": "tests/overlap/out/-z0.json.check.mbtiles", +"format": "pbf", +"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {} } ] }", +"maxzoom": "0", +"minzoom": "0", +"name": "tests/overlap/out/-z0.json.check.mbtiles", +"type": "overlay", +"version": "2" +}, "features": [ +{ "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [ +{ "type": "FeatureCollection", "properties": { "layer": "in" }, "features": [ +{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -33.398438, 79.038437 ], [ -3.515625, 61.312452 ], [ -37.265625, 34.957995 ], [ -71.367188, 29.916852 ], [ -103.359375, 39.368279 ], [ -117.070312, 60.108670 ], [ -113.906250, 69.442128 ], [ -93.515625, 75.342282 ], [ -74.882812, 79.171335 ], [ -33.398438, 79.038437 ] ] ] } } +, +{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -28.125000, 59.756395 ], [ -10.195312, 50.513427 ], [ -5.625000, 8.407168 ], [ -17.578125, -22.593726 ], [ -75.937500, -31.353637 ], [ -118.125000, -9.795678 ], [ -135.703125, 29.228890 ], [ -113.906250, 53.173119 ], [ -81.562500, 63.391522 ], [ -28.125000, 59.756395 ] ] ] } } +] } +] } +] } diff --git a/tests/overlap/out/-z0_--coalesce.json b/tests/overlap/out/-z0_--coalesce.json new file mode 100644 index 0000000..890b1d7 --- /dev/null +++ b/tests/overlap/out/-z0_--coalesce.json @@ -0,0 +1,18 @@ +{ "type": "FeatureCollection", "properties": { +"bounds": "-135.703125,-31.353637,-3.515625,79.171335", +"center": "-3.515625,0.000000,0", +"description": "tests/overlap/out/-z0_--coalesce.json.check.mbtiles", +"format": "pbf", +"json": "{\"vector_layers\": [ { \"id\": \"in\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {} } ] }", +"maxzoom": "0", +"minzoom": "0", +"name": "tests/overlap/out/-z0_--coalesce.json.check.mbtiles", +"type": "overlay", +"version": "2" +}, "features": [ +{ "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [ +{ "type": "FeatureCollection", "properties": { "layer": "in" }, "features": [ +{ "type": "Feature", "properties": { }, "geometry": { "type": "Polygon", "coordinates": [ [ [ -33.398438, 79.038437 ], [ -3.515625, 61.312452 ], [ -15.556641, 53.488046 ], [ -10.195312, 50.513427 ], [ -5.625000, 8.407168 ], [ -17.578125, -22.593726 ], [ -75.937500, -31.353637 ], [ -118.125000, -9.795678 ], [ -135.703125, 29.228890 ], [ -113.906250, 53.173119 ], [ -112.236328, 53.800651 ], [ -117.070312, 60.108670 ], [ -113.906250, 69.442128 ], [ -93.515625, 75.342282 ], [ -74.882812, 79.171335 ], [ -33.398438, 79.038437 ] ], [ [ -112.236328, 53.800651 ], [ -103.359375, 39.368279 ], [ -71.367188, 29.916852 ], [ -37.265625, 34.957995 ], [ -15.556641, 53.488046 ], [ -28.125000, 59.756395 ], [ -81.562500, 63.391522 ], [ -112.236328, 53.800651 ] ] ] } } +] } +] } +] } diff --git a/tile.cc b/tile.cc index 2db3201..c0bb031 100644 --- a/tile.cc +++ b/tile.cc @@ -538,7 +538,6 @@ void *partial_feature_worker(void *v) { // Give Clipper a chance to try to fix it. for (size_t i = 0; i < geoms.size(); i++) { geoms[i] = clean_or_clip_poly(geoms[i], 0, 0, 0, false); - geoms[i] = close_poly(geoms[i]); } } @@ -950,6 +949,14 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s features[j][x].geom = simplify_lines(features[j][x].geom, 32, 0); } + if (features[j][x].type == VT_POLYGON) { + if (features[j][x].coalesced) { + features[j][x].geom = clean_or_clip_poly(features[j][x].geom, 0, 0, 0, false); + } + + features[j][x].geom = close_poly(features[j][x].geom); + } + if (features[j][x].geom.size() > 0) { out.push_back(features[j][x]); } diff --git a/version.h b/version.h index 06899da..665a263 100644 --- a/version.h +++ b/version.h @@ -1 +1 @@ -#define VERSION "tippecanoe v1.9.13\n" +#define VERSION "tippecanoe v1.9.14\n"