mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 16:35:40 +02:00
Add --deduplicate-by-id option to tippecanoe-overzoom (#331)
* Add option to deduplicate by feature ID in overzoom * Add test, fix default * Update version and changelog
This commit is contained in:
@@ -1269,7 +1269,8 @@ std::string overzoom(std::vector<input_tile> const &tiles, int nz, int nx, int n
|
||||
double tiny_polygon_size,
|
||||
std::vector<mvt_layer> const &bins, std::string const &bin_by_id_list,
|
||||
std::string const &accumulate_numeric, size_t feature_limit,
|
||||
std::vector<clipbbox> const &clipbboxes) {
|
||||
std::vector<clipbbox> const &clipbboxes,
|
||||
bool deduplicate_by_id) {
|
||||
std::vector<source_tile> decoded;
|
||||
|
||||
for (auto const &t : tiles) {
|
||||
@@ -1295,7 +1296,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_or_unspecified, buffer, keep, exclude, exclude_prefix, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, bin_by_id_list, accumulate_numeric, feature_limit, clipbboxes);
|
||||
return overzoom(decoded, nz, nx, ny, detail_or_unspecified, buffer, keep, exclude, exclude_prefix, do_compress, next_overzoomed_tiles, demultiply, filter, preserve_input_order, attribute_accum, unidecode_data, simplification, tiny_polygon_size, bins, bin_by_id_list, accumulate_numeric, feature_limit, clipbboxes, deduplicate_by_id);
|
||||
}
|
||||
|
||||
// like a minimal serial_feature, but with mvt_feature-style attributes
|
||||
@@ -1499,7 +1500,8 @@ static bool feature_out(std::vector<tile_feature> const &features, mvt_layer &ou
|
||||
std::unordered_map<std::string, attribute_op> const &attribute_accum,
|
||||
std::string const &accumulate_numeric,
|
||||
key_pool &key_pool, int buffer, bool include_nonaggregate,
|
||||
std::vector<clipbbox> const &clipbboxes, int nz, int nx, int ny) {
|
||||
std::vector<clipbbox> const &clipbboxes, int nz, int nx, int ny,
|
||||
std::set<unsigned long long> *deduplicate_ids) {
|
||||
// Add geometry to output feature
|
||||
|
||||
drawvec geom = features[0].geom;
|
||||
@@ -1582,6 +1584,14 @@ static bool feature_out(std::vector<tile_feature> const &features, mvt_layer &ou
|
||||
|
||||
// ID and attributes, if it didn't get clipped away
|
||||
|
||||
if (features[0].has_id && deduplicate_ids != NULL) {
|
||||
if (deduplicate_ids->find(features[0].id) != deduplicate_ids->end()) {
|
||||
outfeature.geometry.clear();
|
||||
} else {
|
||||
deduplicate_ids->insert(features[0].id);
|
||||
}
|
||||
}
|
||||
|
||||
if (outfeature.geometry.size() > 0) {
|
||||
if (features[0].has_id) {
|
||||
outfeature.has_id = true;
|
||||
@@ -1973,7 +1983,7 @@ mvt_tile assign_to_bins(mvt_tile &features,
|
||||
if (feature_out(outfeatures[i], outlayer,
|
||||
keep, exclude, exclude_prefix, attribute_accum,
|
||||
accumulate_numeric, key_pool, buffer, true,
|
||||
clipbboxes, z, x, y)) {
|
||||
clipbboxes, z, x, y, NULL)) {
|
||||
mvt_feature &nfeature = outlayer.features.back();
|
||||
mvt_value val;
|
||||
val.type = mvt_uint;
|
||||
@@ -2010,10 +2020,14 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
double tiny_polygon_size,
|
||||
std::vector<mvt_layer> const &bins, std::string const &bin_by_id_list,
|
||||
std::string const &accumulate_numeric, size_t feature_limit,
|
||||
std::vector<clipbbox> const &clipbboxes) {
|
||||
std::vector<clipbbox> const &clipbboxes,
|
||||
bool deduplicate_by_id) {
|
||||
mvt_tile outtile;
|
||||
key_pool key_pool;
|
||||
|
||||
// map from layer name to ids used in that layer
|
||||
std::map<std::string, std::set<unsigned long long>> deduplicate_ids;
|
||||
|
||||
for (auto const &tile : tiles) {
|
||||
for (auto const &layer : tile.tile.layers) {
|
||||
mvt_layer *outlayer = NULL;
|
||||
@@ -2040,6 +2054,16 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
outlayer = &outtile.layers.back();
|
||||
}
|
||||
|
||||
std::set<unsigned long long> *deduplicate_by_id_set = NULL;
|
||||
if (deduplicate_by_id) {
|
||||
auto layer_deduplicate_ids = deduplicate_ids.find(layer.name);
|
||||
if (layer_deduplicate_ids == deduplicate_ids.end()) {
|
||||
deduplicate_ids.emplace(layer.name, std::set<unsigned long long>());
|
||||
layer_deduplicate_ids = deduplicate_ids.find(layer.name);
|
||||
}
|
||||
deduplicate_by_id_set = &layer_deduplicate_ids->second;
|
||||
}
|
||||
|
||||
std::vector<tile_feature> pending_tile_features;
|
||||
double accum_area = 0;
|
||||
|
||||
@@ -2161,7 +2185,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, exclude, exclude_prefix, attribute_accum, accumulate_numeric, key_pool, -1, bins.size() == 0, std::vector<clipbbox>(), nz, nx, ny);
|
||||
feature_out(pending_tile_features, *outlayer, keep, exclude, exclude_prefix, attribute_accum, accumulate_numeric, key_pool, -1, bins.size() == 0, std::vector<clipbbox>(), nz, nx, ny, deduplicate_by_id_set);
|
||||
if (outlayer->features.size() >= feature_limit) {
|
||||
break;
|
||||
}
|
||||
@@ -2221,7 +2245,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, exclude, exclude_prefix, attribute_accum, accumulate_numeric, key_pool, -1, bins.size() == 0, std::vector<clipbbox>(), nz, nx, ny);
|
||||
feature_out(pending_tile_features, *outlayer, keep, exclude, exclude_prefix, attribute_accum, accumulate_numeric, key_pool, -1, bins.size() == 0, std::vector<clipbbox>(), nz, nx, ny, deduplicate_by_id_set);
|
||||
pending_tile_features.clear();
|
||||
if (outlayer->features.size() >= feature_limit) {
|
||||
break;
|
||||
@@ -2261,7 +2285,7 @@ std::string overzoom(std::vector<source_tile> const &tiles, int nz, int nx, int
|
||||
detail_or_unspecified, buffer, keep, exclude, exclude_prefix, false, NULL,
|
||||
demultiply, filter, preserve_input_order, attribute_accum, unidecode_data,
|
||||
simplification, tiny_polygon_size, bins, bin_by_id_list, accumulate_numeric,
|
||||
1, clipbboxes);
|
||||
1, clipbboxes, deduplicate_by_id);
|
||||
if (child.size() > 0) {
|
||||
next_overzoomed_tiles->emplace_back(nx * 2 + x, ny * 2 + y);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user