Make the current multiplier cluster size per-layer

This commit is contained in:
Erica Fischer
2024-02-13 12:14:38 -08:00
parent 40793a4212
commit 65a1d0a25f
5 changed files with 13571 additions and 13660 deletions
+20 -15
View File
@@ -1460,6 +1460,11 @@ return;
}
}
struct layer_features {
std::vector<serial_feature> features;
size_t multiplier_cluster_size = 0;
};
long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, char *global_stringpool, int z, const unsigned tx, const unsigned ty, const int detail, int min_detail, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, compressor **geomfile, int minzoom, int maxzoom, double todo, std::atomic<long long> *along, long long alongminus, double gamma, int child_shards, long long *pool_off, unsigned *initial_x, unsigned *initial_y, std::atomic<int> *running, double simplification, std::vector<std::map<std::string, layermap_entry>> *layermaps, std::vector<std::vector<std::string>> *layer_unmaps, size_t tiling_seg, size_t pass, unsigned long long mingap, long long minextent, unsigned long long mindrop_sequence, const char *prefilter, const char *postfilter, json_object *filter, write_tile_args *arg, atomic_strategy *strategy, bool compressed_input, node *shared_nodes_map, size_t nodepos) {
double merge_fraction = 1;
double mingap_fraction = 1;
@@ -1506,7 +1511,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
long long original_features = 0;
long long unclipped_features = 0;
std::map<std::string, std::vector<serial_feature>> layers;
std::map<std::string, layer_features> layers;
std::vector<unsigned long long> indices;
std::vector<long long> extents;
@@ -1524,7 +1529,6 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
size_t unsimplified_geometry_size = 0;
size_t simplified_geometry_through = 0;
size_t multiplier_cluster_size = 0; // of current cluster. should this be per-layer?
size_t lead_features_count = 0; // of the tile so far
size_t other_multiplier_cluster_features_count = 0; // of the tile so far
@@ -1647,9 +1651,10 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
std::string &layername = (*layer_unmaps)[sf.segment][sf.layer];
if (layers.count(layername) == 0) {
layers.emplace(layername, std::vector<serial_feature>());
layers.emplace(layername, layer_features());
}
std::vector<serial_feature> &features = layers.find(layername)->second;
struct layer_features &layer = layers.find(layername)->second;
std::vector<serial_feature> &features = layer.features;
if (sf.t == VT_POINT) {
if (extent_previndex >= sf.index) {
@@ -1675,7 +1680,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
// that were dropped because the previous lead feature was dropped
drop_rest = false;
} else if (sf.dropped != FEATURE_DROPPED) {
if (multiplier_cluster_size >= (size_t) retain_points_multiplier) {
if (layer.multiplier_cluster_size >= (size_t) retain_points_multiplier) {
sf.dropped = FEATURE_DROPPED;
}
}
@@ -1741,10 +1746,10 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
indices.push_back(sf.index);
}
if (sf.index - merge_previndex < mingap && find_feature_to_accumulate_onto(features, sf, which_serial_feature, layer_unmaps, LLONG_MAX, multiplier_seq)) {
if (multiplier_cluster_size < (size_t) retain_points_multiplier) {
if (layer.multiplier_cluster_size < (size_t) retain_points_multiplier) {
// we have capacity to keep this feature as part of an existing multiplier cluster that isn't full yet
// so do that instead of dropping it
sf.dropped = multiplier_cluster_size + 1;
sf.dropped = layer.multiplier_cluster_size + 1;
} else {
preserve_attributes(arg->attribute_accum, sf, features[which_serial_feature]);
strategy->dropped_as_needed++;
@@ -1770,10 +1775,10 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
// search here is for LLONG_MAX, not minextent, because we are dropping features, not coalescing them,
// so we shouldn't expect to find anything small that we can related this feature to.
if (minextent != 0 && sf.extent + coalesced_area <= minextent && find_feature_to_accumulate_onto(features, sf, which_serial_feature, layer_unmaps, LLONG_MAX, multiplier_seq)) {
if (multiplier_cluster_size < (size_t) retain_points_multiplier) {
if (layer.multiplier_cluster_size < (size_t) retain_points_multiplier) {
// we have capacity to keep this feature as part of an existing multiplier cluster that isn't full yet
// so do that instead of dropping it
sf.dropped = multiplier_cluster_size + 1;
sf.dropped = layer.multiplier_cluster_size + 1;
} else {
preserve_attributes(arg->attribute_accum, sf, features[which_serial_feature]);
strategy->dropped_as_needed++;
@@ -1797,10 +1802,10 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
// search here is for LLONG_MAX, not minextent, because we are dropping features, not coalescing them,
// so we shouldn't expect to find anything small that we can related this feature to.
if (mindrop_sequence != 0 && drop_sequence <= mindrop_sequence && find_feature_to_accumulate_onto(features, sf, which_serial_feature, layer_unmaps, LLONG_MAX, multiplier_seq)) {
if (multiplier_cluster_size < (size_t) retain_points_multiplier) {
if (layer.multiplier_cluster_size < (size_t) retain_points_multiplier) {
// we have capacity to keep this feature as part of an existing multiplier cluster that isn't full yet
// so do that instead of dropping it
sf.dropped = multiplier_cluster_size + 1;
sf.dropped = layer.multiplier_cluster_size + 1;
} else {
preserve_attributes(arg->attribute_accum, sf, features[which_serial_feature]);
strategy->dropped_as_needed++;
@@ -1876,10 +1881,10 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
}
if (sf.dropped == FEATURE_KEPT) {
multiplier_cluster_size = 1;
layer.multiplier_cluster_size = 1;
lead_features_count++;
} else {
multiplier_cluster_size++;
layer.multiplier_cluster_size++;
other_multiplier_cluster_features_count++;
}
@@ -1998,7 +2003,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
for (auto &kv : layers) {
std::string const &layername = kv.first;
std::vector<serial_feature> &features = kv.second;
std::vector<serial_feature> &features = kv.second.features;
if (retain_points_multiplier > 1) {
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "tippecanoe:retain_points_multiplier_first", serial_val(mvt_bool, "true"));
@@ -2225,7 +2230,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
size_t totalsize = 0;
for (auto layer_iterator = layers.begin(); layer_iterator != layers.end(); ++layer_iterator) {
std::vector<serial_feature> &layer_features = layer_iterator->second;
std::vector<serial_feature> &layer_features = layer_iterator->second.features;
totalsize += layer_features.size();
mvt_layer layer;