From aaad2e3af8f7b4b7a997fc6fef60d0430939eb31 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Mon, 18 Nov 2024 16:12:33 -0800 Subject: [PATCH] Plumb a clip bounding box around through overzoom --- clip.cpp | 10 ++++++---- geometry.hpp | 18 ++++++++++++++++-- main.hpp | 12 ------------ overzoom.cpp | 18 +++++++++++++++++- tile-join.cpp | 3 ++- 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/clip.cpp b/clip.cpp index 06d29c12..eb4a2b66 100644 --- a/clip.cpp +++ b/clip.cpp @@ -1087,7 +1087,8 @@ std::string overzoom(std::vector const &tiles, int nz, int nx, int n std::vector const &unidecode_data, double simplification, double tiny_polygon_size, std::vector const &bins, std::string const &bin_by_id_list, - std::string const &accumulate_numeric, size_t feature_limit) { + std::string const &accumulate_numeric, size_t feature_limit, + std::vector const &clipbboxes) { std::vector decoded; for (auto const &t : tiles) { @@ -1113,7 +1114,7 @@ std::string overzoom(std::vector const &tiles, int nz, int nx, int n decoded.push_back(out); } - return overzoom(decoded, nz, nx, ny, detail_or_unspecified, buffer, keep, exclude, exclude_prefix, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, bin_by_id_list, accumulate_numeric, feature_limit); + return overzoom(decoded, nz, nx, ny, detail_or_unspecified, buffer, keep, exclude, exclude_prefix, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, bin_by_id_list, accumulate_numeric, feature_limit, clipbboxes); } // like a minimal serial_feature, but with mvt_feature-style attributes @@ -1776,7 +1777,8 @@ std::string overzoom(std::vector const &tiles, int nz, int nx, int std::vector const &unidecode_data, double simplification, double tiny_polygon_size, std::vector const &bins, std::string const &bin_by_id_list, - std::string const &accumulate_numeric, size_t feature_limit) { + std::string const &accumulate_numeric, size_t feature_limit, + std::vector const &clipbboxes) { mvt_tile outtile; key_pool key_pool; @@ -2003,7 +2005,7 @@ std::string overzoom(std::vector const &tiles, int nz, int nx, int detail_or_unspecified, buffer, keep, exclude, exclude_prefix, false, NULL, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, bin_by_id_list, accumulate_numeric, - 1); + 1, clipbboxes); if (child.size() > 0) { next_overzoomed_tiles->emplace_back(nx * 2 + x, ny * 2 + y); } diff --git a/geometry.hpp b/geometry.hpp index 7d8d81f0..2284ab95 100644 --- a/geometry.hpp +++ b/geometry.hpp @@ -115,6 +115,18 @@ struct source_tile { int y; }; +struct clipbbox { + double lon1; + double lat1; + double lon2; + double lat2; + + long long minx; + long long miny; + long long maxx; + long long maxy; +}; + std::string overzoom(std::vector const &tiles, int nz, int nx, int ny, int detail, int buffer, std::set const &keep, @@ -127,7 +139,8 @@ std::string overzoom(std::vector const &tiles, int nz, int nx, int std::vector const &unidecode_data, double simplification, double tiny_polygon_size, std::vector const &bins, std::string const &bin_by_id_list, - std::string const &accumulate_numeric, size_t feature_limit); + std::string const &accumulate_numeric, size_t feature_limit, + std::vector const &clipbboxes); std::string overzoom(std::vector const &tiles, int nz, int nx, int ny, int detail, int buffer, @@ -141,7 +154,8 @@ std::string overzoom(std::vector const &tiles, int nz, int nx, int n std::vector const &unidecode_data, double simplification, double tiny_polygon_size, std::vector const &bins, std::string const &bin_by_id_list, - std::string const &accumulate_numeric, size_t feature_limit); + std::string const &accumulate_numeric, size_t feature_limit, + std::vector const &clipbboxes); draw center_of_mass_mp(const drawvec &dv); diff --git a/main.hpp b/main.hpp index cc28df3c..714af5c3 100644 --- a/main.hpp +++ b/main.hpp @@ -24,18 +24,6 @@ struct index { } }; -struct clipbbox { - double lon1; - double lat1; - double lon2; - double lat2; - - long long minx; - long long miny; - long long maxx; - long long maxy; -}; - extern std::vector clipbboxes; void checkdisk(std::vector *r); diff --git a/overzoom.cpp b/overzoom.cpp index 37fdbaeb..514c7669 100644 --- a/overzoom.cpp +++ b/overzoom.cpp @@ -10,6 +10,7 @@ #include "attribute.hpp" #include "text.hpp" #include "read_json.hpp" +#include "projection.hpp" extern char *optarg; extern int optind; @@ -29,6 +30,7 @@ std::string accumulate_numeric; std::set keep; std::set exclude; std::vector exclude_prefix; +std::vector clipbboxes; void usage(char **argv) { fprintf(stderr, "Usage: %s -o newtile.pbf.gz tile.pbf.gz oz/ox/oy nz/nx/ny\n", argv[0]); @@ -67,7 +69,9 @@ int main(int argc, char **argv) { {"assign-to-bins", required_argument, 0, 'b' & 0x1F}, {"bin-by-id-list", required_argument, 0, 'c' & 0x1F}, {"accumulate-numeric-attributes", required_argument, 0, 'a' & 0x1F}, + {"numeric-attributes", required_argument, 0, 'a' & 0x1F}, {"no-tile-compression", no_argument, 0, 'd' & 0x1F}, + {"clip-bounding-box", required_argument, 0, 'k' & 0x1F}, {0, 0, 0, 0}, }; @@ -158,6 +162,18 @@ int main(int argc, char **argv) { do_compress = false; break; + case 'k' & 0x1F: + clipbbox clip; + if (sscanf(optarg, "%lf,%lf,%lf,%lf", &clip.lon1, &clip.lat1, &clip.lon2, &clip.lat2) == 4) { + projection->project(clip.lon1, clip.lat1, 32, &clip.minx, &clip.maxy); + projection->project(clip.lon2, clip.lat2, 32, &clip.maxx, &clip.miny); + clipbboxes.push_back(clip); + } else { + fprintf(stderr, "%s: Can't parse bounding box --clip-bounding-box=%s\n", argv[0], optarg); + exit(EXIT_ARGS); + } + break; + default: fprintf(stderr, "Unrecognized flag -%c\n", i); usage(argv); @@ -262,7 +278,7 @@ int main(int argc, char **argv) { its.push_back(std::move(t)); } - 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); + 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) { diff --git a/tile-join.cpp b/tile-join.cpp index 3fa3d412..6d8d2523 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -716,7 +716,8 @@ struct tileset_reader { std::set(), std::set(), std::vector(), false, &next_overzoomed_tiles, false, NULL, false, std::unordered_map(), unidecode_data, 0, 0, - std::vector(), "", "", SIZE_MAX); + std::vector(), "", "", SIZE_MAX, + std::vector()); return ret; }