Skip to content

Commit

Permalink
Plumbing for exclude and exclude-prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Sep 19, 2024
1 parent 5e95095 commit 5ec93a1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 13 deletions.
32 changes: 23 additions & 9 deletions clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,11 @@ bool pnpoly_mp(std::vector<mvt_geometry> const &geom, long long x, long long y)
}

std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int ny,
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
int detail, int buffer,
std::set<std::string> const &keep,
std::set<std::string> const &exclude,
std::vector<std::string> const &exclude_prefix,
bool do_compress,
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
bool demultiply, json_object *filter, bool preserve_input_order,
std::unordered_map<std::string, attribute_op> const &attribute_accum,
Expand Down Expand Up @@ -1108,7 +1112,7 @@ std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int n
decoded.push_back(out);
}

return overzoom(decoded, nz, nx, ny, detail, buffer, keep, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, accumulate_numeric);
return overzoom(decoded, nz, nx, ny, detail, buffer, keep, exclude, exclude_prefix, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, accumulate_numeric);
}

// like a minimal serial_feature, but with mvt_feature-style attributes
Expand Down Expand Up @@ -1237,6 +1241,8 @@ static void preserve_numeric(const std::string &key, const mvt_value &val, /

static void feature_out(std::vector<tile_feature> const &features, mvt_layer &outlayer,
std::set<std::string> const &keep,
std::set<std::string> const &exclude,
std::vector<std::string> const &exclude_prefix,
std::unordered_map<std::string, attribute_op> const &attribute_accum,
std::shared_ptr<std::string> const &tile_stringpool,
std::string const &accumulate_numeric) {
Expand Down Expand Up @@ -1452,7 +1458,10 @@ static bool bbox_intersects(long long x1min, long long y1min, long long x1max, l

mvt_tile assign_to_bins(mvt_tile const &features, std::vector<mvt_layer> const &bins, int z, int x, int y, int detail,
std::unordered_map<std::string, attribute_op> const &attribute_accum,
std::string const &accumulate_numeric) {
std::string const &accumulate_numeric,
std::set<std::string> keep,
std::set<std::string> exclude,
std::vector<std::string> exclude_prefix) {
std::vector<index_event> events;

// Index bins
Expand Down Expand Up @@ -1548,7 +1557,7 @@ mvt_tile assign_to_bins(mvt_tile const &features, std::vector<mvt_layer> const &
if (found != active.end()) {
if (outfeatures[found->outfeature].size() > 1) {
feature_out(outfeatures[found->outfeature], outlayer,
std::set<std::string>(), attribute_accum,
keep, exclude, exclude_prefix, attribute_accum,
tile_stringpool, accumulate_numeric);
mvt_feature &nfeature = outlayer.features.back();
mvt_value val;
Expand Down Expand Up @@ -1578,7 +1587,11 @@ mvt_tile assign_to_bins(mvt_tile const &features, std::vector<mvt_layer> const &
}

std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int ny,
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
int detail, int buffer,
std::set<std::string> const &keep,
std::set<std::string> const &exclude,
std::vector<std::string> const &exclude_prefix,
bool do_compress,
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
bool demultiply, json_object *filter, bool preserve_input_order,
std::unordered_map<std::string, attribute_op> const &attribute_accum,
Expand Down Expand Up @@ -1710,7 +1723,7 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int

if (flush_multiplier_cluster) {
if (pending_tile_features.size() > 0) {
feature_out(pending_tile_features, *outlayer, keep, attribute_accum, tile_stringpool, accumulate_numeric);
feature_out(pending_tile_features, *outlayer, keep, exclude, exclude_prefix, attribute_accum, tile_stringpool, accumulate_numeric);
pending_tile_features.clear();
}
}
Expand Down Expand Up @@ -1767,7 +1780,7 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
}

if (pending_tile_features.size() > 0) {
feature_out(pending_tile_features, *outlayer, keep, attribute_accum, tile_stringpool, accumulate_numeric);
feature_out(pending_tile_features, *outlayer, keep, exclude, exclude_prefix, attribute_accum, tile_stringpool, accumulate_numeric);
pending_tile_features.clear();
}

Expand Down Expand Up @@ -1799,7 +1812,7 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int

std::string child = overzoom(sts,
nz + 1, nx * 2 + x, ny * 2 + y,
detail, buffer, keep, false, NULL,
detail, buffer, keep, exclude, exclude_prefix, false, NULL,
demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, accumulate_numeric);
if (child.size() > 0) {
next_overzoomed_tiles->emplace_back(nx * 2 + x, ny * 2 + y);
Expand All @@ -1810,7 +1823,8 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
}

if (bins.size() > 0) {
outtile = assign_to_bins(outtile, bins, nz, nx, ny, detail, attribute_accum, accumulate_numeric);
outtile = assign_to_bins(outtile, bins, nz, nx, ny, detail, attribute_accum, accumulate_numeric,
keep, exclude, exclude_prefix);
}

for (ssize_t i = outtile.layers.size() - 1; i >= 0; i--) {
Expand Down
12 changes: 10 additions & 2 deletions geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ struct source_tile {
};

std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int ny,
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
int detail, int buffer,
std::set<std::string> const &keep,
std::set<std::string> const &exclude,
std::vector<std::string> const &exclude_prefix,
bool do_compress,
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
bool demultiply, json_object *filter, bool preserve_input_order,
std::unordered_map<std::string, attribute_op> const &attribute_accum,
Expand All @@ -125,7 +129,11 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
std::string const &accumulate_numeric);

std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int ny,
int detail, int buffer, std::set<std::string> const &keep, bool do_compress,
int detail, int buffer,
std::set<std::string> const &keep,
std::set<std::string> const &exclude,
std::vector<std::string> const &exclude_prefix,
bool do_compress,
std::vector<std::pair<unsigned, unsigned>> *next_overzoomed_tiles,
bool demultiply, json_object *filter, bool preserve_input_order,
std::unordered_map<std::string, attribute_op> const &attribute_accum,
Expand Down
14 changes: 13 additions & 1 deletion overzoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ std::vector<mvt_layer> bins;
std::string accumulate_numeric;

std::set<std::string> keep;
std::set<std::string> exclude;
std::vector<std::string> exclude_prefix;

void usage(char **argv) {
fprintf(stderr, "Usage: %s -o newtile.pbf.gz tile.pbf.gz oz/ox/oy nz/nx/ny\n", argv[0]);
Expand All @@ -46,6 +48,8 @@ int main(int argc, char **argv) {

struct option long_options[] = {
{"include", required_argument, 0, 'y'},
{"exclude", required_argument, 0, 'x'},
{"exclude-prefix", required_argument, 0, 'x' & 0x1F},
{"full-detail", required_argument, 0, 'd'},
{"buffer", required_argument, 0, 'b'},
{"output", required_argument, 0, 'o'},
Expand Down Expand Up @@ -81,6 +85,14 @@ int main(int argc, char **argv) {
keep.insert(optarg);
break;

case 'x':
exclude.insert(optarg);
break;

case 'x' & 0x1F:
exclude_prefix.push_back(optarg);
break;

case 'o':
outfile = optarg;
break;
Expand Down Expand Up @@ -233,7 +245,7 @@ int main(int argc, char **argv) {
its.push_back(std::move(t));
}

std::string out = overzoom(its, nz, nx, ny, detail, buffer, keep, true, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, accumulate_numeric);
std::string out = overzoom(its, nz, nx, ny, detail, buffer, keep, exclude, exclude_prefix, true, NULL, demultiply, json_filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, accumulate_numeric);

FILE *f = fopen(outfile, "wb");
if (f == NULL) {
Expand Down
4 changes: 3 additions & 1 deletion tile-join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,9 @@ struct tileset_reader {
t.y = parent_tile.y;
tv.push_back(std::move(t));

std::string ret = overzoom(tv, tile.z, tile.x, tile.y, -1, buffer, std::set<std::string>(), false, &next_overzoomed_tiles, false, NULL, false, std::unordered_map<std::string, attribute_op>(), unidecode_data, 0, 0, std::vector<mvt_layer>(), "");
std::string ret = overzoom(tv, tile.z, tile.x, tile.y, -1, buffer,
std::set<std::string>(), std::set<std::string>(), std::vector<std::string>(),
false, &next_overzoomed_tiles, false, NULL, false, std::unordered_map<std::string, attribute_op>(), unidecode_data, 0, 0, std::vector<mvt_layer>(), "");
return ret;
}

Expand Down

0 comments on commit 5ec93a1

Please sign in to comment.