mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
Keep features at the attribute threshold instead of dropping them (384 follow up) (#385)
Keep features at the attribute threshold instead of dropping them
This commit is contained in:
@@ -833,12 +833,9 @@ static double choose_minattribute(std::vector<double> &attribute_values, double
|
|||||||
std::stable_sort(attribute_values.begin(), attribute_values.end());
|
std::stable_sort(attribute_values.begin(), attribute_values.end());
|
||||||
|
|
||||||
if (descending) {
|
if (descending) {
|
||||||
// For descending: threshold moves down, drop features >= threshold
|
// For descending: drop features > threshold, keep features <= threshold
|
||||||
// Use ceil so ix points at the first value to drop, not the last to keep
|
// ix points at the last value to keep
|
||||||
size_t ix = (size_t)ceil((double)(attribute_values.size() - 1) * f);
|
size_t ix = (size_t)((attribute_values.size() - 1) * f);
|
||||||
if (ix >= attribute_values.size()) {
|
|
||||||
ix = attribute_values.size() - 1;
|
|
||||||
}
|
|
||||||
while (ix > 0 && attribute_values[ix] >= existing_attribute) {
|
while (ix > 0 && attribute_values[ix] >= existing_attribute) {
|
||||||
ix--;
|
ix--;
|
||||||
}
|
}
|
||||||
@@ -849,8 +846,12 @@ static double choose_minattribute(std::vector<double> &attribute_values, double
|
|||||||
|
|
||||||
return attribute_values[ix];
|
return attribute_values[ix];
|
||||||
} else {
|
} else {
|
||||||
// For ascending: threshold moves up, drop features <= threshold
|
// For ascending: drop features < threshold, keep features >= threshold
|
||||||
size_t ix = (attribute_values.size() - 1) * (1 - f);
|
// ix points at the first value to keep
|
||||||
|
size_t ix = (size_t)ceil((double)(attribute_values.size() - 1) * (1 - f));
|
||||||
|
if (ix >= attribute_values.size()) {
|
||||||
|
ix = attribute_values.size() - 1;
|
||||||
|
}
|
||||||
while (ix + 1 < attribute_values.size() && attribute_values[ix] <= existing_attribute) {
|
while (ix + 1 < attribute_values.size() && attribute_values[ix] <= existing_attribute) {
|
||||||
ix++;
|
ix++;
|
||||||
}
|
}
|
||||||
@@ -2109,8 +2110,8 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
|
|||||||
if (attr_valid) {
|
if (attr_valid) {
|
||||||
add_sample_to(attribute_values, attr_numeric, attribute_values_increment, seq);
|
add_sample_to(attribute_values, attr_numeric, attribute_values_increment, seq);
|
||||||
bool should_drop = arg->drop_by_attribute_descending
|
bool should_drop = arg->drop_by_attribute_descending
|
||||||
? (minattribute != HUGE_VAL && attr_numeric >= minattribute)
|
? (minattribute != HUGE_VAL && attr_numeric > minattribute)
|
||||||
: (minattribute != -HUGE_VAL && attr_numeric <= minattribute);
|
: (minattribute != -HUGE_VAL && attr_numeric < minattribute);
|
||||||
if (should_drop) {
|
if (should_drop) {
|
||||||
can_stop_early = false;
|
can_stop_early = false;
|
||||||
if (drop_feature_unless_it_can_be_added_to_a_multiplier_cluster(layer, sf, layer_unmaps, strategy, drop_rest, arg->attribute_accum, key_pool)) {
|
if (drop_feature_unless_it_can_be_added_to_a_multiplier_cluster(layer, sf, layer_unmaps, strategy, drop_rest, arg->attribute_accum, key_pool)) {
|
||||||
@@ -2801,7 +2802,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Trying to keep features with '%s' %s %.6f to make it fit\n",
|
"Trying to keep features with '%s' %s %.6f to make it fit\n",
|
||||||
arg->drop_by_attribute_as_needed_attribute->c_str(),
|
arg->drop_by_attribute_as_needed_attribute->c_str(),
|
||||||
desc ? "<" : ">",
|
desc ? "<=" : ">=",
|
||||||
minattribute);
|
minattribute);
|
||||||
}
|
}
|
||||||
line_detail++;
|
line_detail++;
|
||||||
@@ -2970,7 +2971,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
|
|||||||
arg->still_dropping = true;
|
arg->still_dropping = true;
|
||||||
}
|
}
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
fprintf(stderr, "Going to try keeping features with attribute '%s' %s %0.6f to make it fit\n", arg->drop_by_attribute_as_needed_attribute->c_str(), desc2 ? "<" : ">", minattribute);
|
fprintf(stderr, "Going to try keeping features with attribute '%s' %s %0.6f to make it fit\n", arg->drop_by_attribute_as_needed_attribute->c_str(), desc2 ? "<=" : ">=", minattribute);
|
||||||
}
|
}
|
||||||
line_detail++;
|
line_detail++;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user