Skip to content

Commit

Permalink
Add a flag to retain multiplier features by minimum distance
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Oct 8, 2024
1 parent 71cf446 commit 01f14a4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ size_t limit_tile_feature_count_at_maxzoom = 0;
unsigned int drop_denser = 0;
std::map<std::string, serial_val> set_attributes;
unsigned long long preserve_point_density_threshold = 0;
unsigned long long preserve_multiplier_density_threshold = 0;
long long extend_zooms_max = 0;
int retain_points_multiplier = 1;
std::vector<std::string> unidecode_data;
Expand Down Expand Up @@ -3109,6 +3110,7 @@ int main(int argc, char **argv) {
{"cluster-distance", required_argument, 0, 'K'},
{"cluster-maxzoom", required_argument, 0, 'k'},
{"preserve-point-density-threshold", required_argument, 0, '~'},
{"preserve-multiplier-density-threshold", required_argument, 0, '~'},

{"Dropping or merging a fraction of features to keep under tile size limits", 0, 0, 0},
{"drop-densest-as-needed", no_argument, &additional[A_DROP_DENSEST_AS_NEEDED], 1},
Expand Down Expand Up @@ -3320,6 +3322,8 @@ int main(int argc, char **argv) {
}
} else if (strcmp(opt, "preserve-point-density-threshold") == 0) {
preserve_point_density_threshold = atoll_require(optarg, "Preserve point density threshold");
} else if (strcmp(opt, "preserve-multiplier-density-threshold") == 0) {
preserve_multiplier_density_threshold = atoll_require(optarg, "Preserve multiplier density threshold");
} else if (strcmp(opt, "extend-zooms-if-still-dropping-maximum") == 0) {
extend_zooms_max = atoll_require(optarg, "Maximum number by which to extend zooms");
} else if (strcmp(opt, "retain-points-multiplier") == 0) {
Expand Down
1 change: 1 addition & 0 deletions main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ extern long long extend_zooms_max;
extern int retain_points_multiplier;
extern size_t maximum_string_attribute_length;
extern std::string accumulate_numeric;
extern unsigned long long preserve_multiplier_density_threshold;

struct order_field {
std::string name;
Expand Down
1 change: 1 addition & 0 deletions serial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ struct serial_feature {

#define FEATURE_DROPPED -1
#define FEATURE_KEPT 0
#define FEATURE_NO_REALLY_KEEP_IT_AROUND INT_MAX
// <0: dropped
// 0: kept
// >0: sequence number of additional feature kept by retain-points-multiplier
Expand Down
10 changes: 9 additions & 1 deletion tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,9 @@ static serial_feature next_feature(decompressor *geoms, std::atomic<long long> *
} else if (z + extra_multiplier_zooms >= feature_minzoom && count->second + 1 < retain_points_multiplier) {
count->second++;
sf.dropped = count->second;
} else if (preserve_multiplier_density_threshold > 0 &&
sf.gap > ((1LL << (32 - z)) / preserve_multiplier_density_threshold) * ((1LL << (32 - z)) / preserve_multiplier_density_threshold)) {
sf.dropped = FEATURE_NO_REALLY_KEEP_IT_AROUND;
} else {
sf.dropped = FEATURE_DROPPED;
}
Expand Down Expand Up @@ -1898,8 +1901,11 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
} else {
can_stop_early = false;

if (sf.dropped != FEATURE_DROPPED) {
if (sf.dropped != FEATURE_DROPPED && sf.dropped != FEATURE_NO_REALLY_KEEP_IT_AROUND) {
// Does the current multiplier cluster already have too many features?
// (Because we are dropping dynamically, and we have already filled the
// cluster with features that were dynamically dropped from being
// primary features)
// If so, we have to drop this one, even if it would potentially qualify
// as a secondary feature to be exposed by filtering
if (layer.multiplier_cluster_size >= (size_t) retain_points_multiplier) {
Expand Down Expand Up @@ -2146,6 +2152,8 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
if (sf.dropped == FEATURE_KEPT) {
layer.multiplier_cluster_size = 1;
lead_features_count++;
} else if (sf.dropped == FEATURE_NO_REALLY_KEEP_IT_AROUND) {
other_multiplier_cluster_features_count++;
} else {
layer.multiplier_cluster_size++;
other_multiplier_cluster_features_count++;
Expand Down

0 comments on commit 01f14a4

Please sign in to comment.