Add --containing-lat-lon and --containing-lon-lat decode options

This commit is contained in:
Erica Fischer
2022-11-18 10:00:45 -08:00
parent 8eec2be462
commit f2d9359fb7
2 changed files with 33 additions and 1 deletions
+2
View File
@@ -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
====================
+31 -1
View File
@@ -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<std::string> 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);
}