diff --git a/CHANGELOG.md b/CHANGELOG.md index 81ef86c5..1fd1024b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.73.0 + +* Correctly clip features down to nothing when the clip region doesn't intersect the tile at all + # 2.72.0 * Add --clip-polygon-file and --feature-filter-file options to tippecanoe-overzoom diff --git a/Makefile b/Makefile index 8679691b..2f522d00 100644 --- a/Makefile +++ b/Makefile @@ -439,6 +439,10 @@ overzoom-test: tippecanoe-overzoom ./tippecanoe-decode tests/pbf/countries-8-135-86-bigclip.pbf 8 135 86 > tests/pbf/countries-8-135-86-bigclip.json.check cmp tests/pbf/countries-8-135-86-bigclip.json.check tests/pbf/countries-8-135-86-bigclip.json rm tests/pbf/countries-8-135-86-bigclip.pbf tests/pbf/countries-8-135-86-bigclip.json.check + # Clip region that does not intersect with the tile + ./tippecanoe-overzoom -o tests/pbf/squirrels-13-2413-3077-clip.pbf --clip-polygon-file tests/pbf/squirrels-clip.json tests/pbf/squirrels-13-2413-3077.pbf 13/2413/3077 13/2413/3077 + cmp tests/pbf/squirrels-13-2413-3077-clip.pbf /dev/null # clipped away + rm tests/pbf/squirrels-13-2413-3077-clip.pbf join-test: tippecanoe tippecanoe-decode tile-join ./tippecanoe -q -f -z12 -o tests/join-population/tabblock_06001420.mbtiles -YALAND10:'Land area' -L'{"file": "tests/join-population/tabblock_06001420.json", "description": "population"}' diff --git a/overzoom.cpp b/overzoom.cpp index 112f0187..c7eb922d 100644 --- a/overzoom.cpp +++ b/overzoom.cpp @@ -294,6 +294,7 @@ int main(int argc, char **argv) { // clip the clip polygons, if any, to the tile bounds, // to reduce their complexity + bool clipped_to_nothing = false; if (clipbboxes.size() > 0) { long long wx1 = (nx - buffer / 256.0) * (1LL << (32 - nz)); long long wy1 = (ny - buffer / 256.0) * (1LL << (32 - nz)); @@ -315,38 +316,47 @@ int main(int argc, char **argv) { if (c.dv.size() > 0) { c.dv = clip_poly_poly(c.dv, tile_bounds); + + if (c.dv.size() == 0) { + clipped_to_nothing = true; + break; + } } } } - json_object *json_filter = NULL; - if (filter.size() > 0) { - json_filter = parse_filter(filter.c_str()); - } - - for (auto const &s : sources) { - std::string tile; - char buf[1000]; - int len; + std::string out; - FILE *f = fopen(s.tile.c_str(), "rb"); - if (f == NULL) { - perror(s.tile.c_str()); - exit(EXIT_FAILURE); + if (!clipped_to_nothing) { + json_object *json_filter = NULL; + if (filter.size() > 0) { + json_filter = parse_filter(filter.c_str()); } - while ((len = fread(buf, sizeof(char), 1000, f)) > 0) { - tile.append(std::string(buf, len)); + for (auto const &s : sources) { + std::string tile; + char buf[1000]; + int len; + + FILE *f = fopen(s.tile.c_str(), "rb"); + if (f == NULL) { + perror(s.tile.c_str()); + exit(EXIT_FAILURE); + } + + while ((len = fread(buf, sizeof(char), 1000, f)) > 0) { + tile.append(std::string(buf, len)); + } + fclose(f); + + input_tile t = s; + t.tile = std::move(tile); + its.push_back(std::move(t)); } - fclose(f); - input_tile t = s; - t.tile = std::move(tile); - its.push_back(std::move(t)); + out = overzoom(its, nz, nx, ny, detail, buffer, keep, exclude, exclude_prefix, do_compress, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, bin_by_id_list, accumulate_numeric, SIZE_MAX, clipbboxes); } - std::string out = overzoom(its, nz, nx, ny, detail, buffer, keep, exclude, exclude_prefix, do_compress, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, bin_by_id_list, accumulate_numeric, SIZE_MAX, clipbboxes); - FILE *f = fopen(outfile, "wb"); if (f == NULL) { perror(outfile); diff --git a/platform.hpp b/platform.hpp index a62d1cb5..7fa4033b 100644 --- a/platform.hpp +++ b/platform.hpp @@ -11,6 +11,8 @@ size_t calc_memsize(); size_t get_max_open_files(); -constexpr const char *get_null_device() { return "/dev/null"; } +constexpr const char *get_null_device() { + return "/dev/null"; +} -#endif // PLATFORM_HPP \ No newline at end of file +#endif // PLATFORM_HPP \ No newline at end of file diff --git a/tests/pbf/squirrels-13-2413-3077.pbf b/tests/pbf/squirrels-13-2413-3077.pbf new file mode 100644 index 00000000..20e02168 Binary files /dev/null and b/tests/pbf/squirrels-13-2413-3077.pbf differ diff --git a/tests/pbf/squirrels-clip.json b/tests/pbf/squirrels-clip.json new file mode 100644 index 00000000..ef0e95fd --- /dev/null +++ b/tests/pbf/squirrels-clip.json @@ -0,0 +1 @@ +{"coordinates":[[[-73.9722549,40.7904659],[-73.9755817,40.7674848],[-73.938783,40.767022],[-73.9457082,40.7791562],[-73.9628855,40.7760201],[-73.9629534,40.7914425],[-73.9722549,40.7904659]]],"crs":{"properties":{"name":"EPSG:4326"},"type":"name"},"type":"Polygon"} diff --git a/version.hpp b/version.hpp index bf022696..fac06ade 100644 --- a/version.hpp +++ b/version.hpp @@ -1,6 +1,6 @@ #ifndef VERSION_HPP #define VERSION_HPP -#define VERSION "v2.72.0" +#define VERSION "v2.73.0" #endif