From 6a6d47eb07cde480c231533033e0c3e45b8ddc7c Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Wed, 6 Nov 2024 16:59:53 -0800 Subject: [PATCH] Add a tippecanoe-decode option to restrict which attributes to decode --- decode.cpp | 8 +++++++- plugin.cpp | 2 +- tile.cpp | 2 +- write_json.cpp | 6 +++++- write_json.hpp | 3 ++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/decode.cpp b/decode.cpp index dedb4053f..c19e1e595 100644 --- a/decode.cpp +++ b/decode.cpp @@ -28,6 +28,7 @@ int minzoom = 0; int maxzoom = 32; bool force = false; +std::set include_attr; bool progress_time() { return false; @@ -217,7 +218,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::setlayers->size(); i++) { - layer_to_geojson((*(wa->layers))[i], wa->z, wa->x, wa->y, false, true, false, true, 0, 0, 0, true, state, 0); + layer_to_geojson((*(wa->layers))[i], wa->z, wa->x, wa->y, false, true, false, true, 0, 0, 0, true, state, 0, std::set()); } if (fclose(fp) != 0) { diff --git a/tile.cpp b/tile.cpp index 4387537bb..108da5347 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1358,7 +1358,7 @@ void *run_prefilter(void *v) { decode_meta(sf, tmp_layer, tmp_feature); tmp_layer.features.push_back(tmp_feature); - layer_to_geojson(tmp_layer, 0, 0, 0, false, true, false, true, sf.index, sf.seq, sf.extent, true, state, 0); + layer_to_geojson(tmp_layer, 0, 0, 0, false, true, false, true, sf.index, sf.seq, sf.extent, true, state, 0, std::set()); } if (fclose(rpa->prefilter_fp) != 0) { diff --git a/write_json.cpp b/write_json.cpp index 307428e99..eae5a2f06 100644 --- a/write_json.cpp +++ b/write_json.cpp @@ -268,7 +268,7 @@ void write_coords(json_writer &state, lonlat const &ll, double scale) { } } -void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool write_dropped, unsigned long long index, long long sequence, long long extent, bool complain, json_writer &state, double scale) { +void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool write_dropped, unsigned long long index, long long sequence, long long extent, bool complain, json_writer &state, double scale, std::set const &include_attr) { for (size_t f = 0; f < layer.features.size(); f++) { mvt_feature const &feat = layer.features[f]; @@ -334,6 +334,10 @@ void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y exit(EXIT_IMPOSSIBLE); } + if (include_attr.size() > 0 && include_attr.find(layer.keys[feat.tags[t]]) == include_attr.end()) { + continue; + } + const char *key = layer.keys[feat.tags[t]].c_str(); mvt_value const &val = layer.values[feat.tags[t + 1]]; diff --git a/write_json.hpp b/write_json.hpp index 523b027b3..a2ae56bca 100644 --- a/write_json.hpp +++ b/write_json.hpp @@ -4,6 +4,7 @@ #include #include #include +#include enum json_write_tok { JSON_WRITE_HASH, @@ -61,7 +62,7 @@ struct json_writer { void adds(std::string const &s); }; -void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, unsigned long long index, long long sequence, long long extent, bool complain, json_writer &state, double scale); +void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, unsigned long long index, long long sequence, long long extent, bool complain, json_writer &state, double scale, std::set const &include_attr); void fprintq(FILE *f, const char *s); #endif