From ae07c4523970f416b8cfb9340782467f9559a2d0 Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Mon, 24 Jul 2023 06:15:07 -0700 Subject: [PATCH] Add attribute stripping; don't generate layers if they have no features --- overzoom.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/overzoom.cpp b/overzoom.cpp index 4d4c3e2df..08cb9fc6c 100644 --- a/overzoom.cpp +++ b/overzoom.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "errors.hpp" #include "mvt.hpp" #include "geometry.hpp" @@ -12,6 +13,8 @@ extern int optind; int detail = 12; // tippecanoe-style: mvt extent == 1 << detail int buffer = 16; // tippecanoe-style: mvt buffer == extent * buffer / 256; +std::set keep; + std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int ny) { mvt_tile tile, outtile; bool was_compressed; @@ -105,21 +108,29 @@ std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int } for (size_t i = 0; i + 1 < feature.tags.size(); i += 2) { - outlayer.tag(outfeature, layer.keys[feature.tags[i]], layer.values[feature.tags[i + 1]]); + if (keep.size() == 0 || keep.find(layer.keys[feature.tags[i]]) != keep.end()) { + outlayer.tag(outfeature, layer.keys[feature.tags[i]], layer.values[feature.tags[i + 1]]); + } } outlayer.features.push_back(outfeature); } } - outtile.layers.push_back(outlayer); + if (outlayer.features.size() > 0) { + outtile.layers.push_back(outlayer); + } } - std::string pbf = outtile.encode(); - std::string compressed; - compress(pbf, compressed, true); + if (outtile.layers.size() > 0) { + std::string pbf = outtile.encode(); + std::string compressed; + compress(pbf, compressed, true); - return compressed; + return compressed; + } else { + return ""; + } } void usage(char **argv) { @@ -131,8 +142,12 @@ void usage(char **argv) { int main(int argc, char **argv) { int i; - while ((i = getopt(argc, argv, "")) != -1) { + while ((i = getopt(argc, argv, "y:")) != -1) { switch (i) { + case 'y': + keep.insert(optarg); + break; + default: usage(argv); }