Skip to content

Commit

Permalink
Add attribute stripping; don't generate layers if they have no features
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Jul 24, 2023
1 parent 4dbff83 commit ae07c45
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions overzoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <stdlib.h>
#include <getopt.h>
#include <string>
#include <set>
#include "errors.hpp"
#include "mvt.hpp"
#include "geometry.hpp"
Expand All @@ -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<std::string> 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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
Expand Down

0 comments on commit ae07c45

Please sign in to comment.