Cluster onto the previous feature instead of onto the next

This also allows doing the attribute and tilestats all at once
at the end of the tile instead of having to update a feature
to handle the last cluster.
This commit is contained in:
Eric Fischer
2018-02-23 12:26:58 -08:00
parent 30a277a43e
commit 27154c8f06
3 changed files with 3893 additions and 3929 deletions
File diff suppressed because it is too large Load Diff
+2967 -2967
View File
File diff suppressed because it is too large Load Diff
+18 -54
View File
@@ -343,6 +343,7 @@ struct partial {
bool has_id = 0; bool has_id = 0;
ssize_t renamed = 0; ssize_t renamed = 0;
long long extent = 0; long long extent = 0;
long long clustered = 0;
}; };
struct partial_arg { struct partial_arg {
@@ -1503,7 +1504,6 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
double scale = (double) (1LL << (64 - 2 * (z + 8))); double scale = (double) (1LL << (64 - 2 * (z + 8)));
double gap = 0, density_gap = 0; double gap = 0, density_gap = 0;
double spacing = 0; double spacing = 0;
size_t clustered = 0;
long long original_features = 0; long long original_features = 0;
long long unclipped_features = 0; long long unclipped_features = 0;
@@ -1614,30 +1614,9 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
if (additional[A_CLUSTER_DENSEST_AS_NEEDED] || cluster_distance != 0) { if (additional[A_CLUSTER_DENSEST_AS_NEEDED] || cluster_distance != 0) {
indices.push_back(sf.index); indices.push_back(sf.index);
if ((sf.index < merge_previndex || sf.index - merge_previndex < mingap) && find_partial(partials, sf, which_partial)) { if ((sf.index < merge_previndex || sf.index - merge_previndex < mingap) && find_partial(partials, sf, which_partial)) {
clustered++; partials[which_partial].clustered++;
preserve_attributes(arg->attribute_accum, attribute_accum_state, sf, stringpool); preserve_attributes(arg->attribute_accum, attribute_accum_state, sf, stringpool);
continue; continue;
} else {
if (clustered > 0) {
std::string layername = (*layer_unmaps)[sf.segment][sf.layer];
serial_val sv, sv2;
sf.full_keys.push_back("clustered");
sv.type = mvt_bool;
sv.s = "true";
sf.full_values.push_back(sv);
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "clustered", sv);
sf.full_keys.push_back("point_count");
sv2.type = mvt_double;
sv2.s = std::to_string(clustered + 1);
sf.full_values.push_back(sv2);
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "point_count", sv2);
}
clustered = 0;
} }
} else if (additional[A_DROP_DENSEST_AS_NEEDED]) { } else if (additional[A_DROP_DENSEST_AS_NEEDED]) {
indices.push_back(sf.index); indices.push_back(sf.index);
@@ -1723,6 +1702,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
p.index = sf.index; p.index = sf.index;
p.renamed = -1; p.renamed = -1;
p.extent = sf.extent; p.extent = sf.extent;
p.clustered = 0;
partials.push_back(p); partials.push_back(p);
} }
@@ -1730,42 +1710,26 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
coalesced_area = 0; coalesced_area = 0;
} }
// Attach the leftover cluster count to the last feature that did make it for (size_t i = 0; i < partials.size(); i++) {
// XXX Cluster onto the previous feature instead if (partials[i].clustered > 0) {
if (clustered > 0) { partial &p = partials[i];
if (partials.size() > 0) {
size_t n = partials.size() - 1;
size_t i; std::string layername = (*layer_unmaps)[p.segment][p.layer];
for (i = 0; i < partials[n].full_keys.size(); i++) { serial_val sv, sv2;
if (partials[n].full_keys[i] == std::string("point_count")) {
break;
}
}
std::string layername = (*layer_unmaps)[partials[n].segment][partials[n].layer]; p.full_keys.push_back("clustered");
if (i < partials[n].full_keys.size()) { sv.type = mvt_bool;
size_t sum = strtoul(partials[n].full_values[i].s.c_str(), NULL, 10) + clustered; sv.s = "true";
partials[n].full_values[i].s = std::to_string(sum); p.full_values.push_back(sv);
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "point_count", partials[n].full_values[i]); add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "clustered", sv);
} else {
serial_val sv, sv2;
partials[n].full_keys.push_back("clustered"); p.full_keys.push_back("point_count");
sv.type = mvt_bool; sv2.type = mvt_double;
sv.s = "true"; sv2.s = std::to_string(p.clustered + 1);
partials[n].full_values.push_back(sv); p.full_values.push_back(sv2);
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "clustered", sv); add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "point_count", sv2);
partials[n].full_keys.push_back("point_count");
sv2.type = mvt_double;
sv2.s = std::to_string(clustered + 1);
partials[n].full_values.push_back(sv2);
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "point_count", sv2);
}
} }
} }