From f2d9359fb7299c49cb3b6bf8dfdfbda935eca9fb Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Fri, 18 Nov 2022 10:00:45 -0800 Subject: [PATCH] Add --containing-lat-lon and --containing-lon-lat decode options --- README.md | 2 ++ decode.cpp | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 41f40e28..1346a7c9 100644 --- a/README.md +++ b/README.md @@ -891,6 +891,8 @@ resolutions. * `-f` or `--force`: Decode tiles even if polygon ring order or closure problems are detected * `-I` or `--integer`: Report coordinates in integer tile coordinates * `-F` or `--fraction`: Report coordinates as a fraction of the tile extent + * `-m` _lat_,_lon_ or `--containing-lat-lon`=_lat_,_lon_: Decode only tiles containing the specified point + * `-M` _lon_,_lat_ or `--containing-lon-lat`=_lon_,_lat_: Decode only tiles containing the specified point tippecanoe-json-tool ==================== diff --git a/decode.cpp b/decode.cpp index 9a7869b2..6d69b9ec 100644 --- a/decode.cpp +++ b/decode.cpp @@ -28,6 +28,9 @@ int minzoom = 0; int maxzoom = 32; bool force = false; +double containing_lon = -500; +double containing_lat = -500; + void do_stats(mvt_tile &tile, size_t size, bool compressed, int z, unsigned x, unsigned y, json_writer &state) { state.json_write_hash(); @@ -425,7 +428,18 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set co exit(EXIT_SQLITE); } - handle(std::string(s, len), tz, tx, ty, to_decode, pipeline, stats, state, coordinate_mode); + bool contains = true; + if (containing_lat > -500 && containing_lon > -500) { + long long ctx, cty; + lonlat2tile(containing_lon, containing_lat, tz, &ctx, &cty); + if (tx != ctx || ty != cty) { + contains = false; + } + } + + if (contains) { + handle(std::string(s, len), tz, tx, ty, to_decode, pipeline, stats, state, coordinate_mode); + } } sqlite3_finalize(stmt); @@ -514,6 +528,8 @@ int main(int argc, char **argv) { {"stats", no_argument, 0, 'S'}, {"force", no_argument, 0, 'f'}, {"exclude-metadata-row", required_argument, 0, 'x'}, + {"containing-lat-lon", required_argument, 0, 'm'}, + {"containing-lon-lat", required_argument, 0, 'M'}, {0, 0, 0, 0}, }; @@ -573,6 +589,20 @@ int main(int argc, char **argv) { exclude_meta.insert(optarg); break; + case 'm': + if (sscanf(optarg, "%lf,%lf", &containing_lat, &containing_lon) != 2) { + fprintf(stderr, "-m option is lat,lon\n"); + exit(EXIT_FAILURE); + } + break; + + case 'M': + if (sscanf(optarg, "%lf,%lf", &containing_lon, &containing_lat) != 2) { + fprintf(stderr, "-m option is lon,lat\n"); + exit(EXIT_FAILURE); + } + break; + default: usage(argv); }