Compare commits

..
10 changed files with 224 additions and 205 deletions
-8
View File
@@ -1,11 +1,3 @@
# 2.75.1
* Further reduce memory consumption in attribute sorting and tilestats tracking
# 2.75.0
* Reduce memory consumption in attribute accumulation and feature sorting
# 2.74.0
* Add the option to join attributes from a sqlite database in tile-join
+4
View File
@@ -99,6 +99,7 @@ int retain_points_multiplier = 1;
std::vector<std::string> unidecode_data;
size_t maximum_string_attribute_length = 0;
std::string accumulate_numeric;
std::string use_h3_index;
std::vector<order_field> order_by;
bool order_reverse;
@@ -3128,6 +3129,7 @@ int main(int argc, char **argv) {
{"coalesce", no_argument, &additional[A_COALESCE], 1},
{"reverse", no_argument, &additional[A_REVERSE], 1},
{"hilbert", no_argument, &additional[A_HILBERT], 1},
{"use-h3-index", required_argument, 0, '~'},
{"order-by", required_argument, 0, '~'},
{"order-descending-by", required_argument, 0, '~'},
{"order-smallest-first", no_argument, 0, '~'},
@@ -3269,6 +3271,8 @@ int main(int argc, char **argv) {
fprintf(stderr, "%s: --extra-detail can be at most 30\n", argv[0]);
exit(EXIT_ARGS);
}
} else if (strcmp(opt, "use-h3-index") == 0) {
use_h3_index = optarg;
} else if (strcmp(opt, "order-by") == 0) {
order_by.push_back(order_field(optarg, false));
} else if (strcmp(opt, "order-descending-by") == 0) {
+1
View File
@@ -53,6 +53,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 std::string use_h3_index;
extern unsigned long long preserve_multiplier_density_threshold;
struct order_field {
+9 -17
View File
@@ -316,10 +316,6 @@ struct sorted_value {
return false;
}
bool operator()(const std::shared_ptr<sorted_value> &a, const std::shared_ptr<sorted_value> &b) {
return *a < *b;
}
};
std::string mvt_tile::encode() {
@@ -338,7 +334,7 @@ std::string mvt_tile::encode() {
layer_writer.add_string(3, layers[i].keys[j]); /* key */
}
std::vector<std::shared_ptr<sorted_value>> sorted_values;
std::vector<sorted_value> sorted_values;
for (size_t v = 0; v < layers[i].values.size(); v++) {
std::string value_string;
@@ -375,34 +371,30 @@ std::string mvt_tile::encode() {
exit(EXIT_IMPOSSIBLE);
}
std::shared_ptr<sorted_value> sv = std::make_shared<sorted_value>();
sv->val = std::move(value_string);
sv->orig = v;
sorted_value sv;
sv.val = std::move(value_string);
sv.orig = v;
sorted_values.push_back(std::move(sv));
}
std::stable_sort(sorted_values.begin(), sorted_values.end(), sorted_value());
std::stable_sort(sorted_values.begin(), sorted_values.end());
std::vector<size_t> mapping;
mapping.resize(sorted_values.size());
size_t value_index = 0;
for (size_t v = 0; v < sorted_values.size(); v++) {
mapping[sorted_values[v]->orig] = value_index;
layer_writer.add_message(4, sorted_values[v]->val);
mapping[sorted_values[v].orig] = value_index;
layer_writer.add_message(4, sorted_values[v].val);
// crunch out duplicates that were missed by the hashing
while (v + 1 < sorted_values.size() && sorted_values[v]->val == sorted_values[v + 1]->val) {
sorted_values[v]->val.clear();
mapping[sorted_values[v + 1]->orig] = value_index;
while (v + 1 < sorted_values.size() && sorted_values[v].val == sorted_values[v + 1].val) {
mapping[sorted_values[v + 1].orig] = value_index;
v++;
}
sorted_values[v]->val.clear();
value_index++;
}
sorted_values.clear();
for (size_t f = 0; f < layers[i].features.size(); f++) {
std::string feature_string;
protozero::pbf_writer feature_writer(feature_string);
+13
View File
@@ -714,6 +714,19 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
}
bbox_index = encode_index(midx, midy);
if (use_h3_index.size() > 0) {
for (size_t i = 0; i < sf.full_keys.size(); i++) {
if (*(sf.full_keys[i]) == use_h3_index) {
unsigned long long h3_index = atoll(sf.full_values[i].s.c_str());
// the top 52 bits of the feature index are the H3 index;
// the bottom 12 bits are retained from what otherwise would have been the index.
bbox_index = ((h3_index & ((1LL << 52) - 1)) << 12) | (bbox_index & ((1 << 12) - 1));
break;
}
}
}
if (additional[A_CALCULATE_INDEX]) {
sf.full_keys.push_back(key_pool.pool("tippecanoe:index"));
+1
View File
@@ -165,6 +165,7 @@ struct serial_feature {
long long clustered; // does this feature need the clustered/point_count attributes?
const char *stringpool; // string pool for keys/values lookup
std::shared_ptr<std::string> tile_stringpool; // string pool for mvt_value construction
std::set<std::string> need_tilestats;
int z; // tile being produced
int tx;
+47 -47
View File
@@ -83,13 +83,13 @@ bool edges_same(std::pair<std::vector<edge>::iterator, std::vector<edge>::iterat
return true;
}
bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, int z, int line_detail, double simplification, int maxzoom, double merge_fraction) {
bool find_common_edges(std::vector<serial_feature> &features, int z, int line_detail, double simplification, int maxzoom, double merge_fraction) {
size_t merge_count = ceil((1 - merge_fraction) * features.size());
for (size_t i = 0; i < features.size(); i++) {
if (features[i]->t == VT_POLYGON) {
if (features[i].t == VT_POLYGON) {
{
drawvec &g = features[i]->geometry;
drawvec &g = features[i].geometry;
drawvec out;
for (size_t k = 0; k < g.size(); k++) {
@@ -100,7 +100,7 @@ bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, i
}
}
features[i]->geometry = out;
features[i].geometry = out;
}
}
}
@@ -112,21 +112,21 @@ bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, i
std::vector<edge> edges;
size_t ring = 0;
for (size_t i = 0; i < features.size(); i++) {
if (features[i]->t == VT_POLYGON) {
if (features[i].t == VT_POLYGON) {
{
for (size_t k = 0; k + 1 < features[i]->geometry.size(); k++) {
if (features[i]->geometry[k].op == VT_MOVETO) {
for (size_t k = 0; k + 1 < features[i].geometry.size(); k++) {
if (features[i].geometry[k].op == VT_MOVETO) {
ring++;
}
if (features[i]->geometry[k + 1].op == VT_LINETO) {
if (features[i].geometry[k + 1].op == VT_LINETO) {
drawvec dv;
if (features[i]->geometry[k] < features[i]->geometry[k + 1]) {
dv.push_back(features[i]->geometry[k]);
dv.push_back(features[i]->geometry[k + 1]);
if (features[i].geometry[k] < features[i].geometry[k + 1]) {
dv.push_back(features[i].geometry[k]);
dv.push_back(features[i].geometry[k + 1]);
} else {
dv.push_back(features[i]->geometry[k + 1]);
dv.push_back(features[i]->geometry[k]);
dv.push_back(features[i].geometry[k + 1]);
dv.push_back(features[i].geometry[k]);
}
edges.push_back(edge(dv[0].x, dv[0].y, dv[1].x, dv[1].y, ring));
@@ -143,9 +143,9 @@ bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, i
// is not the same as the set of rings using the edge on the other side.
for (size_t i = 0; i < features.size(); i++) {
if (features[i]->t == VT_POLYGON) {
if (features[i].t == VT_POLYGON) {
{
drawvec &g = features[i]->geometry;
drawvec &g = features[i].geometry;
for (size_t k = 0; k < g.size(); k++) {
g[k].necessary = 0;
@@ -223,9 +223,9 @@ bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, i
// Roll rings that include a necessary point around so they start at one
for (size_t i = 0; i < features.size(); i++) {
if (features[i]->t == VT_POLYGON) {
if (features[i].t == VT_POLYGON) {
{
drawvec &g = features[i]->geometry;
drawvec &g = features[i].geometry;
for (size_t k = 0; k < g.size(); k++) {
if (necessaries.count(g[k]) != 0) {
@@ -315,21 +315,21 @@ bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, i
// Add new arc
size_t added = arcs.size() + 1;
arcs.insert(std::pair<drawvec, size_t>(arc, added));
features[i]->arc_polygon.push_back(added);
features[i].arc_polygon.push_back(added);
merge_candidates.insert(std::pair<ssize_t, size_t>(added, i));
} else {
features[i]->arc_polygon.push_back(-(ssize_t) f2->second);
features[i].arc_polygon.push_back(-(ssize_t) f2->second);
merge_candidates.insert(std::pair<ssize_t, size_t>(-(ssize_t) f2->second, i));
}
} else {
features[i]->arc_polygon.push_back(f->second);
features[i].arc_polygon.push_back(f->second);
merge_candidates.insert(std::pair<ssize_t, size_t>(f->second, i));
}
m = n - 1;
}
features[i]->arc_polygon.push_back(0);
features[i].arc_polygon.push_back(0);
k = l - 1;
}
@@ -385,10 +385,10 @@ bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, i
if (r1i->second != r2i->second) {
merge_order mo;
mo.edge = i;
if (features[r1i->second]->index > features[r2i->second]->index) {
mo.gap = features[r1i->second]->index - features[r2i->second]->index;
if (features[r1i->second].index > features[r2i->second].index) {
mo.gap = features[r1i->second].index - features[r2i->second].index;
} else {
mo.gap = features[r2i->second]->index - features[r1i->second]->index;
mo.gap = features[r2i->second].index - features[r1i->second].index;
}
mo.p1 = r1i->second;
mo.p2 = r2i->second;
@@ -406,19 +406,19 @@ bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, i
}
size_t i = order[o].p1;
while (features[i]->renamed >= 0) {
i = features[i]->renamed;
while (features[i].renamed >= 0) {
i = features[i].renamed;
}
size_t i2 = order[o].p2;
while (features[i2]->renamed >= 0) {
i2 = features[i2]->renamed;
while (features[i2].renamed >= 0) {
i2 = features[i2].renamed;
}
for (size_t j = 0; j < features[i]->arc_polygon.size() && merged < merge_count; j++) {
if (features[i]->arc_polygon[j] == order[o].edge) {
for (size_t j = 0; j < features[i].arc_polygon.size() && merged < merge_count; j++) {
if (features[i].arc_polygon[j] == order[o].edge) {
{
// XXX snap links
if (features[order[o].p2]->arc_polygon.size() > 0) {
if (features[order[o].p2].arc_polygon.size() > 0) {
// This has to merge the ring that contains the anti-arc to this arc
// into the current ring, and then add whatever other rings were in
// that feature on to the end.
@@ -427,11 +427,11 @@ bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, i
// the rings in order, but Wagyu should sort that out later
std::vector<ssize_t> additions;
std::vector<ssize_t> &here = features[i]->arc_polygon;
std::vector<ssize_t> &other = features[i2]->arc_polygon;
std::vector<ssize_t> &here = features[i].arc_polygon;
std::vector<ssize_t> &other = features[i2].arc_polygon;
#if 0
printf("seeking %zd\n", features[i]->arc_polygon[j]);
printf("seeking %zd\n", features[i].arc_polygon[j]);
printf("before: ");
for (size_t k = 0; k < here.size(); k++) {
printf("%zd ", here[k]);
@@ -464,7 +464,7 @@ bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, i
size_t m;
for (m = k; m <= l; m++) {
if (other[m] == -features[i]->arc_polygon[j]) {
if (other[m] == -features[i].arc_polygon[j]) {
break;
}
}
@@ -494,12 +494,12 @@ bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, i
k = l;
}
features[i2]->arc_polygon.clear();
features[i2]->renamed = i;
features[i2].arc_polygon.clear();
features[i2].renamed = i;
merged++;
for (size_t k = 0; k < additions.size(); k++) {
features[i]->arc_polygon.push_back(additions[k]);
features[i].arc_polygon.push_back(additions[k]);
}
#if 0
@@ -528,37 +528,37 @@ bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, i
// Turn the arc representations of the polygons back into standard polygon geometries
for (size_t i = 0; i < features.size(); i++) {
if (features[i]->t == VT_POLYGON) {
features[i]->geometry.clear();
if (features[i].t == VT_POLYGON) {
features[i].geometry.clear();
bool at_start = true;
draw first(-1, 0, 0);
for (size_t j = 0; j < features[i]->arc_polygon.size(); j++) {
ssize_t p = features[i]->arc_polygon[j];
for (size_t j = 0; j < features[i].arc_polygon.size(); j++) {
ssize_t p = features[i].arc_polygon[j];
if (p == 0) {
if (first.op >= 0) {
features[i]->geometry.push_back(first);
features[i].geometry.push_back(first);
first = draw(-1, 0, 0);
}
at_start = true;
} else if (p > 0) {
for (size_t k = 0; k + 1 < simplified_arcs[p].size(); k++) {
if (at_start) {
features[i]->geometry.push_back(draw(VT_MOVETO, simplified_arcs[p][k].x, simplified_arcs[p][k].y));
features[i].geometry.push_back(draw(VT_MOVETO, simplified_arcs[p][k].x, simplified_arcs[p][k].y));
first = draw(VT_LINETO, simplified_arcs[p][k].x, simplified_arcs[p][k].y);
} else {
features[i]->geometry.push_back(draw(VT_LINETO, simplified_arcs[p][k].x, simplified_arcs[p][k].y));
features[i].geometry.push_back(draw(VT_LINETO, simplified_arcs[p][k].x, simplified_arcs[p][k].y));
}
at_start = 0;
}
} else { /* p < 0 */
for (ssize_t k = simplified_arcs[-p].size() - 1; k > 0; k--) {
if (at_start) {
features[i]->geometry.push_back(draw(VT_MOVETO, simplified_arcs[-p][k].x, simplified_arcs[-p][k].y));
features[i].geometry.push_back(draw(VT_MOVETO, simplified_arcs[-p][k].x, simplified_arcs[-p][k].y));
first = draw(VT_LINETO, simplified_arcs[-p][k].x, simplified_arcs[-p][k].y);
} else {
features[i]->geometry.push_back(draw(VT_LINETO, simplified_arcs[-p][k].x, simplified_arcs[-p][k].y));
features[i].geometry.push_back(draw(VT_LINETO, simplified_arcs[-p][k].x, simplified_arcs[-p][k].y));
}
at_start = 0;
}
+1 -1
View File
@@ -1 +1 @@
bool find_common_edges(std::vector<std::shared_ptr<serial_feature>> &features, int z, int line_detail, double simplification, int maxzoom, double merge_fraction);
bool find_common_edges(std::vector<serial_feature> &features, int z, int line_detail, double simplification, int maxzoom, double merge_fraction);
+147 -131
View File
@@ -92,17 +92,13 @@ static bool draws_something(drawvec const &geom) {
// comparator for --preserve-input-order, to reorder features back to their original input sequence
static struct preservecmp {
bool operator()(const std::vector<std::shared_ptr<serial_feature>> &a, const std::vector<std::shared_ptr<serial_feature>> &b) {
bool operator()(const std::vector<serial_feature> &a, const std::vector<serial_feature> &b) {
return operator()(a[0], b[0]);
}
bool operator()(const serial_feature &a, const serial_feature &b) {
return a.seq < b.seq;
}
bool operator()(const std::shared_ptr<serial_feature> &a, const std::shared_ptr<serial_feature> &b) {
return a->seq < b->seq;
}
} preservecmp;
static int metacmp(const serial_feature &one, const serial_feature &two);
@@ -194,8 +190,8 @@ struct coalindexcmp_comparator {
return cmp;
}
bool operator()(const std::shared_ptr<serial_feature> &a, const std::shared_ptr<serial_feature> &o) const {
int cmp = coalindexcmp(&*a, &*o);
bool operator()(const serial_feature &a, const serial_feature &o) const {
int cmp = coalindexcmp(&a, &o);
if (cmp < 0) {
return true;
} else {
@@ -207,9 +203,9 @@ struct coalindexcmp_comparator {
static unsigned long long calculate_drop_sequence(serial_feature const &sf);
struct drop_sequence_cmp {
bool operator()(const std::shared_ptr<serial_feature> &a, const std::shared_ptr<serial_feature> &b) {
unsigned long long a_seq = calculate_drop_sequence(*a);
unsigned long long b_seq = calculate_drop_sequence(*b);
bool operator()(const serial_feature &a, const serial_feature &b) {
unsigned long long a_seq = calculate_drop_sequence(a);
unsigned long long b_seq = calculate_drop_sequence(b);
// sorts backwards, to put the features that would be dropped last, first here
if (a_seq > b_seq) {
@@ -340,14 +336,14 @@ static mvt_value coerce_double(mvt_value v) {
// compare features numerically according to that sort key until the keys are exhausted.
// If there is a tie, the feature with the earlier index (centroid) comes first.
struct ordercmp {
bool operator()(const std::vector<std::shared_ptr<serial_feature>> &a, const std::vector<std::shared_ptr<serial_feature>> &b) {
bool operator()(const std::vector<serial_feature> &a, const std::vector<serial_feature> &b) {
return operator()(a[0], b[0]);
}
bool operator()(const std::shared_ptr<serial_feature> &a, const std::shared_ptr<serial_feature> &b) {
bool operator()(const serial_feature &a, const serial_feature &b) {
for (size_t i = 0; i < order_by.size(); i++) {
mvt_value v1 = coerce_double(find_attribute_value(&*a, order_by[i].name));
mvt_value v2 = coerce_double(find_attribute_value(&*b, order_by[i].name));
mvt_value v1 = coerce_double(find_attribute_value(&a, order_by[i].name));
mvt_value v2 = coerce_double(find_attribute_value(&b, order_by[i].name));
if (order_by[i].descending) {
if (v2 < v1) {
@@ -364,7 +360,7 @@ struct ordercmp {
}
}
if (a->index < b->index) {
if (a.index < b.index) {
return true;
}
@@ -374,12 +370,12 @@ struct ordercmp {
// For --retain-points-multiplier: Go through a list of features and return a list of clusters of features,
// creating a new cluster whenever the tippecanoe:retain_points_multiplier_first attribute is seen.
static std::vector<std::vector<std::shared_ptr<serial_feature>>> assemble_multiplier_clusters(std::vector<std::shared_ptr<serial_feature>> const &features) {
std::vector<std::vector<std::shared_ptr<serial_feature>>> clusters;
static std::vector<std::vector<serial_feature>> assemble_multiplier_clusters(std::vector<serial_feature> const &features) {
std::vector<std::vector<serial_feature>> clusters;
if (retain_points_multiplier == 1) {
for (auto const &feature : features) {
std::vector<std::shared_ptr<serial_feature>> cluster;
std::vector<serial_feature> cluster;
cluster.push_back(std::move(feature));
clusters.push_back(std::move(cluster));
}
@@ -387,8 +383,8 @@ static std::vector<std::vector<std::shared_ptr<serial_feature>>> assemble_multip
for (auto const &feature : features) {
bool is_cluster_start = false;
for (size_t i = 0; i < feature->full_keys.size(); i++) {
if (*feature->full_keys[i] == "tippecanoe:retain_points_multiplier_first") {
for (size_t i = 0; i < feature.full_keys.size(); i++) {
if (*feature.full_keys[i] == "tippecanoe:retain_points_multiplier_first") {
is_cluster_start = true;
break;
}
@@ -408,20 +404,20 @@ static std::vector<std::vector<std::shared_ptr<serial_feature>>> assemble_multip
// For --retain-points-multiplier: Flatten a list of clusters of features back into a list of features,
// moving the "tippecanoe:retain_points_multiplier_first" attribute onto the first feature of each cluster
// if it is not already there.
static std::vector<std::shared_ptr<serial_feature>> disassemble_multiplier_clusters(std::vector<std::vector<std::shared_ptr<serial_feature>>> &clusters) {
std::vector<std::shared_ptr<serial_feature>> out;
static std::vector<serial_feature> disassemble_multiplier_clusters(std::vector<std::vector<serial_feature>> &clusters) {
std::vector<serial_feature> out;
for (auto &cluster : clusters) {
// fix up the attributes so the first feature of the multiplier cluster
// gets the marker attribute
for (size_t i = 0; i < cluster.size(); i++) {
for (size_t j = 0; j < cluster[i]->full_keys.size(); j++) {
if (*cluster[i]->full_keys[j] == "tippecanoe:retain_points_multiplier_first") {
cluster[0]->full_keys.push_back(std::move(cluster[i]->full_keys[j]));
cluster[0]->full_values.push_back(std::move(cluster[i]->full_values[j]));
for (size_t j = 0; j < cluster[i].full_keys.size(); j++) {
if (*cluster[i].full_keys[j] == "tippecanoe:retain_points_multiplier_first") {
cluster[0].full_keys.push_back(std::move(cluster[i].full_keys[j]));
cluster[0].full_values.push_back(std::move(cluster[i].full_values[j]));
cluster[i]->full_keys.erase(cluster[i]->full_keys.begin() + j);
cluster[i]->full_values.erase(cluster[i]->full_values.begin() + j);
cluster[i].full_keys.erase(cluster[i].full_keys.begin() + j);
cluster[i].full_values.erase(cluster[i].full_values.begin() + j);
i = cluster.size(); // break outer
break;
@@ -538,7 +534,7 @@ static void rewrite(serial_feature const &osf, int z, int nextzoom, int maxzoom,
// This is the parameter block passed to each simplification worker thread
struct simplification_worker_arg {
std::vector<std::shared_ptr<serial_feature>> *features = NULL;
std::vector<serial_feature> *features = NULL;
int task = 0;
int tasks = 0;
bool trying_to_stop_early = false;
@@ -672,19 +668,19 @@ static double simplify_feature(serial_feature *p, drawvec const &shared_nodes, n
// simplify and clean the geometry of batches of features.
static void *simplification_worker(void *v) {
simplification_worker_arg *a = (simplification_worker_arg *) v;
std::vector<std::shared_ptr<serial_feature>> *features = a->features;
std::vector<serial_feature> *features = a->features;
for (size_t i = a->task; i < (*features).size(); i += a->tasks) {
double area = 0;
if (!a->trying_to_stop_early) {
area = simplify_feature(&*((*features)[i]), *(a->shared_nodes), a->shared_nodes_map, a->nodepos, *(a->shared_nodes_bloom));
area = simplify_feature(&((*features)[i]), *(a->shared_nodes), a->shared_nodes_map, a->nodepos, *(a->shared_nodes_bloom));
}
signed char t = (*features)[i]->t;
int z = (*features)[i]->z;
int out_detail = (*features)[i]->extra_detail;
signed char t = (*features)[i].t;
int z = (*features)[i].z;
int out_detail = (*features)[i].extra_detail;
drawvec geom = (*features)[i]->geometry;
drawvec geom = (*features)[i].geometry;
to_tile_scale(geom, z, out_detail);
if (t == VT_POLYGON) {
@@ -713,15 +709,15 @@ static void *simplification_worker(void *v) {
}
if (t == VT_POLYGON && additional[A_GENERATE_POLYGON_LABEL_POINTS]) {
t = (*features)[i]->t = VT_POINT;
geom = checkerboard_anchors(from_tile_scale(geom, z, out_detail), (*features)[i]->tx, (*features)[i]->ty, z, (*features)[i]->label_point);
t = (*features)[i].t = VT_POINT;
geom = checkerboard_anchors(from_tile_scale(geom, z, out_detail), (*features)[i].tx, (*features)[i].ty, z, (*features)[i].label_point);
to_tile_scale(geom, z, out_detail);
}
if ((*features)[i]->index == 0) {
(*features)[i]->index = i;
if ((*features)[i].index == 0) {
(*features)[i].index = i;
}
(*features)[i]->geometry = std::move(geom);
(*features)[i].geometry = std::move(geom);
}
return NULL;
@@ -1405,6 +1401,10 @@ void add_tilestats(std::string const &layername, int z, std::vector<std::map<std
}
void promote_attribute(std::string const &key, serial_feature &p, key_pool &key_pool) {
if (p.need_tilestats.count(key) == 0) {
p.need_tilestats.insert(key);
}
// If the feature being merged into has this key as a metadata reference,
// promote it to a full_key so it can be modified
@@ -1426,6 +1426,10 @@ void promote_attribute(std::string const &key, serial_feature &p, key_pool &key_
}
void promote_attribute_prefix(std::string const &key, std::string const &prefixed_key, serial_feature &p, key_pool &key_pool) {
if (p.need_tilestats.count(prefixed_key) == 0) {
p.need_tilestats.insert(prefixed_key);
}
// does the prefixed attribute already exist as a full key?
ssize_t found_as = -1;
for (size_t i = 0; i < p.full_keys.size(); i++) {
@@ -1442,7 +1446,6 @@ void promote_attribute_prefix(std::string const &key, std::string const &prefixe
if (found_as >= 0) {
p.full_keys.push_back(key_pool.pool(prefixed_key));
p.full_values.push_back(p.full_values[found_as]);
return;
}
@@ -1535,13 +1538,13 @@ void preserve_attributes(std::unordered_map<std::string, attribute_op> const *at
// ordinarily returns the most recently-added feature from the same layer as the feature
// that is being dropped.
//
bool find_feature_to_accumulate_onto(std::vector<std::shared_ptr<serial_feature>> &features, serial_feature &sf, ssize_t &out, std::vector<std::vector<std::string>> *layer_unmaps, long long maxextent) {
bool find_feature_to_accumulate_onto(std::vector<serial_feature> &features, serial_feature &sf, ssize_t &out, std::vector<std::vector<std::string>> *layer_unmaps, long long maxextent) {
for (size_t i = features.size(); i > 0; i--) {
if (features[i - 1]->t == sf.t) {
std::string &layername1 = (*layer_unmaps)[features[i - 1]->segment][features[i - 1]->layer];
if (features[i - 1].t == sf.t) {
std::string &layername1 = (*layer_unmaps)[features[i - 1].segment][features[i - 1].layer];
std::string &layername2 = (*layer_unmaps)[sf.segment][sf.layer];
if (layername1 == layername2 && features[i - 1]->extent <= maxextent) {
if (layername1 == layername2 && features[i - 1].extent <= maxextent) {
out = i - 1;
return true;
}
@@ -1614,8 +1617,8 @@ return;
// This is the structure that the features from each layer are accumulated into
struct layer_features {
std::vector<std::shared_ptr<serial_feature>> features; // The features of this layer, so far
size_t multiplier_cluster_size = 0; // The feature count of the current multiplier cluster
std::vector<serial_feature> features; // The features of this layer, so far
size_t multiplier_cluster_size = 0; // The feature count of the current multiplier cluster
};
bool drop_feature_unless_it_can_be_added_to_a_multiplier_cluster(layer_features &layer, serial_feature &sf, std::vector<std::vector<std::string>> *layer_unmaps, strategy &strategy, bool &drop_rest, std::unordered_map<std::string, attribute_op> const *attribute_accum, key_pool &key_pool) {
@@ -1629,7 +1632,7 @@ bool drop_feature_unless_it_can_be_added_to_a_multiplier_cluster(layer_features
sf.dropped = layer.multiplier_cluster_size + 1;
return false; // converted rather than dropped
} else {
preserve_attributes(attribute_accum, sf, *layer.features[which_serial_feature], key_pool);
preserve_attributes(attribute_accum, sf, layer.features[which_serial_feature], key_pool);
drop_rest = true;
return true; // dropped
}
@@ -1869,7 +1872,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
layers.emplace(layername, layer_features());
}
struct layer_features &layer = layers.find(layername)->second;
std::vector<std::shared_ptr<serial_feature>> &features = layer.features;
std::vector<serial_feature> &features = layer.features;
if (sf.t == VT_POINT) {
if (extent_previndex >= sf.index) {
@@ -1918,7 +1921,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
if (sf.dropped == FEATURE_DROPPED || drop_rest) {
if (find_feature_to_accumulate_onto(features, sf, which_serial_feature, layer_unmaps, LLONG_MAX)) {
preserve_attributes(arg->attribute_accum, sf, *features[which_serial_feature], key_pool);
preserve_attributes(arg->attribute_accum, sf, features[which_serial_feature], key_pool);
strategy.dropped_by_rate++;
can_stop_early = false;
continue;
@@ -1931,7 +1934,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
if (sf.dropped == FEATURE_KEPT) {
if (gamma > 0) {
if (manage_gap(sf.index, &previndex, scale, gamma, &gap) && find_feature_to_accumulate_onto(features, sf, which_serial_feature, layer_unmaps, LLONG_MAX)) {
preserve_attributes(arg->attribute_accum, sf, *features[which_serial_feature], key_pool);
preserve_attributes(arg->attribute_accum, sf, features[which_serial_feature], key_pool);
strategy.dropped_by_gamma++;
drop_rest = true;
can_stop_early = false;
@@ -1946,20 +1949,20 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
// rather than wanting each feature to have a consistent
// idea of density between zooms.
if ((sf.index < merge_previndex || sf.index - merge_previndex < cluster_mingap) && find_feature_to_accumulate_onto(features, sf, which_serial_feature, layer_unmaps, LLONG_MAX)) {
features[which_serial_feature]->clustered++;
features[which_serial_feature].clustered++;
if (features[which_serial_feature]->t == VT_POINT &&
features[which_serial_feature]->geometry.size() == 1 &&
if (features[which_serial_feature].t == VT_POINT &&
features[which_serial_feature].geometry.size() == 1 &&
sf.geometry.size() == 1) {
double x = (double) features[which_serial_feature]->geometry[0].x * features[which_serial_feature]->clustered;
double y = (double) features[which_serial_feature]->geometry[0].y * features[which_serial_feature]->clustered;
double x = (double) features[which_serial_feature].geometry[0].x * features[which_serial_feature].clustered;
double y = (double) features[which_serial_feature].geometry[0].y * features[which_serial_feature].clustered;
x += sf.geometry[0].x;
y += sf.geometry[0].y;
features[which_serial_feature]->geometry[0].x = x / (features[which_serial_feature]->clustered + 1);
features[which_serial_feature]->geometry[0].y = y / (features[which_serial_feature]->clustered + 1);
features[which_serial_feature].geometry[0].x = x / (features[which_serial_feature].clustered + 1);
features[which_serial_feature].geometry[0].y = y / (features[which_serial_feature].clustered + 1);
}
preserve_attributes(arg->attribute_accum, sf, *features[which_serial_feature], key_pool);
preserve_attributes(arg->attribute_accum, sf, features[which_serial_feature], key_pool);
strategy.coalesced_as_needed++;
drop_rest = true;
can_stop_early = false;
@@ -1978,20 +1981,20 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
// it averages the point locations
add_sample_to(gaps, sf.gap, gaps_increment, seq);
if (sf.gap < mingap && find_feature_to_accumulate_onto(features, sf, which_serial_feature, layer_unmaps, LLONG_MAX)) {
features[which_serial_feature]->clustered++;
features[which_serial_feature].clustered++;
if (features[which_serial_feature]->t == VT_POINT &&
features[which_serial_feature]->geometry.size() == 1 &&
if (features[which_serial_feature].t == VT_POINT &&
features[which_serial_feature].geometry.size() == 1 &&
sf.geometry.size() == 1) {
double x = (double) features[which_serial_feature]->geometry[0].x * features[which_serial_feature]->clustered;
double y = (double) features[which_serial_feature]->geometry[0].y * features[which_serial_feature]->clustered;
double x = (double) features[which_serial_feature].geometry[0].x * features[which_serial_feature].clustered;
double y = (double) features[which_serial_feature].geometry[0].y * features[which_serial_feature].clustered;
x += sf.geometry[0].x;
y += sf.geometry[0].y;
features[which_serial_feature]->geometry[0].x = x / (features[which_serial_feature]->clustered + 1);
features[which_serial_feature]->geometry[0].y = y / (features[which_serial_feature]->clustered + 1);
features[which_serial_feature].geometry[0].x = x / (features[which_serial_feature].clustered + 1);
features[which_serial_feature].geometry[0].y = y / (features[which_serial_feature].clustered + 1);
}
preserve_attributes(arg->attribute_accum, sf, *features[which_serial_feature], key_pool);
preserve_attributes(arg->attribute_accum, sf, features[which_serial_feature], key_pool);
strategy.coalesced_as_needed++;
drop_rest = true;
continue;
@@ -1999,10 +2002,10 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
} else if (additional[A_COALESCE_DENSEST_AS_NEEDED]) {
add_sample_to(gaps, sf.gap, gaps_increment, seq);
if (sf.gap < mingap && find_feature_to_accumulate_onto(features, sf, which_serial_feature, layer_unmaps, LLONG_MAX)) {
coalesce_geometry(*features[which_serial_feature], sf);
features[which_serial_feature]->coalesced = true;
coalesce_geometry(features[which_serial_feature], sf);
features[which_serial_feature].coalesced = true;
coalesced_area += sf.extent;
preserve_attributes(arg->attribute_accum, sf, *features[which_serial_feature], key_pool);
preserve_attributes(arg->attribute_accum, sf, features[which_serial_feature], key_pool);
strategy.coalesced_as_needed++;
drop_rest = true;
can_stop_early = false;
@@ -2021,10 +2024,10 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
} else if (additional[A_COALESCE_SMALLEST_AS_NEEDED]) {
add_sample_to(extents, sf.extent, extents_increment, seq);
if (minextent != 0 && sf.extent + coalesced_area <= minextent && find_feature_to_accumulate_onto(features, sf, which_serial_feature, layer_unmaps, minextent)) {
coalesce_geometry(*features[which_serial_feature], sf);
features[which_serial_feature]->coalesced = true;
coalesce_geometry(features[which_serial_feature], sf);
features[which_serial_feature].coalesced = true;
coalesced_area += sf.extent;
preserve_attributes(arg->attribute_accum, sf, *features[which_serial_feature], key_pool);
preserve_attributes(arg->attribute_accum, sf, features[which_serial_feature], key_pool);
strategy.coalesced_as_needed++;
drop_rest = true;
can_stop_early = false;
@@ -2041,9 +2044,9 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
} else if (additional[A_COALESCE_FRACTION_AS_NEEDED]) {
add_sample_to(drop_sequences, drop_sequence, drop_sequences_increment, seq);
if (mindrop_sequence != 0 && drop_sequence <= mindrop_sequence && find_feature_to_accumulate_onto(features, sf, which_serial_feature, layer_unmaps, LLONG_MAX)) {
coalesce_geometry(*features[which_serial_feature], sf);
features[which_serial_feature]->coalesced = true;
preserve_attributes(arg->attribute_accum, sf, *features[which_serial_feature], key_pool);
coalesce_geometry(features[which_serial_feature], sf);
features[which_serial_feature].coalesced = true;
preserve_attributes(arg->attribute_accum, sf, features[which_serial_feature], key_pool);
strategy.coalesced_as_needed++;
drop_rest = true;
can_stop_early = false;
@@ -2185,23 +2188,23 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
tile_detail = sf.extra_detail;
}
features.push_back(std::make_shared<serial_feature>(sf));
features.push_back(std::move(sf));
unsimplified_geometry_size += features.back()->geometry.size() * sizeof(draw);
unsimplified_geometry_size += features.back().geometry.size() * sizeof(draw);
if (unsimplified_geometry_size > 10 * 1024 * 1024 && !additional[A_DETECT_SHARED_BORDERS]) {
// we should be safe to simplify here with P_SIMPLIFY_SHARED_NODES, since they will
// have been assembled globally, although that also means that simplification
// may not be very effective for reducing memory usage.
for (; simplified_geometry_through < features.size(); simplified_geometry_through++) {
simplify_feature(&*features[simplified_geometry_through], shared_nodes, shared_nodes_map, nodepos, shared_nodes_bloom);
simplify_feature(&features[simplified_geometry_through], shared_nodes, shared_nodes_map, nodepos, shared_nodes_bloom);
if (features[simplified_geometry_through]->t == VT_POLYGON) {
drawvec to_clean = features[simplified_geometry_through]->geometry;
if (features[simplified_geometry_through].t == VT_POLYGON) {
drawvec to_clean = features[simplified_geometry_through].geometry;
// don't scale up because this is still world coordinates
to_clean = clean_or_clip_poly(to_clean, 0, 0, false, false);
features[simplified_geometry_through]->geometry = std::move(to_clean);
features[simplified_geometry_through].geometry = std::move(to_clean);
}
}
@@ -2290,14 +2293,16 @@ 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<std::shared_ptr<serial_feature>> &features = kv.second.features;
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"));
// mapping from input sequence to current sequence within this tile
std::vector<std::pair<size_t, size_t>> feature_sequences;
for (size_t i = 0; i < features.size(); i++) {
feature_sequences.emplace_back(features[i]->seq, i);
feature_sequences.emplace_back(features[i].seq, i);
}
// tag each feature with its sequence number within the layer
@@ -2311,13 +2316,15 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
size_t j = feature_sequences[i].second;
serial_val sv(mvt_double, std::to_string(i));
features[j]->full_keys.push_back(key_pool.pool("tippecanoe:retain_points_multiplier_sequence"));
features[j]->full_values.push_back(sv);
features[j].full_keys.push_back(key_pool.pool("tippecanoe:retain_points_multiplier_sequence"));
features[j].full_values.push_back(sv);
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, *features[j].full_keys.back(), sv);
}
}
for (size_t i = 0; i < features.size(); i++) {
serial_feature &p = *features[i];
serial_feature &p = features[i];
if (p.clustered > 0) {
serial_val sv, sv2, sv3, sv4;
@@ -2329,16 +2336,22 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
sv.s = "true";
p.full_values.push_back(sv);
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "clustered", sv);
p.full_keys.push_back(key_pool.pool("point_count"));
sv2.type = mvt_double;
sv2.s = std::to_string(point_count);
p.full_values.push_back(sv2);
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "point_count", sv2);
p.full_keys.push_back(key_pool.pool("sqrt_point_count"));
sv3.type = mvt_double;
sv3.s = std::to_string(round(100 * sqrt(point_count)) / 100.0);
p.full_values.push_back(sv3);
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "sqrt_point_count", sv3);
p.full_keys.push_back(key_pool.pool("point_count_abbreviated"));
sv4.type = mvt_string;
if (point_count >= 10000) {
@@ -2350,15 +2363,21 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
}
sv4.s = abbrev;
p.full_values.push_back(sv4);
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, "point_count_abbreviated", sv4);
}
for (size_t j = 0; j < p.full_keys.size(); j++) {
// remove accumulation state
size_t found = p.full_values[j].s.find('\0');
if (found != std::string::npos) {
p.full_values[j].s = p.full_values[j].s.substr(0, found);
if (p.need_tilestats.size() > 0) {
for (size_t j = 0; j < p.full_keys.size(); j++) {
if (p.need_tilestats.count(*p.full_keys[j]) > 0) {
// remove accumulation state
size_t found = p.full_values[j].s.find('\0');
if (found != std::string::npos) {
p.full_values[j].s = p.full_values[j].s.substr(0, found);
}
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, *p.full_keys[j], p.full_values[j]);
}
}
add_tilestats(layername, z, layermaps, tiling_seg, layer_unmaps, *p.full_keys[j], p.full_values[j]);
}
}
@@ -2407,18 +2426,18 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
}
for (size_t i = 0; i < features.size(); i++) {
signed char t = features[i]->t;
signed char t = features[i].t;
{
if (t == VT_POINT || draws_something(features[i]->geometry)) {
if (t == VT_POINT || draws_something(features[i].geometry)) {
// printf("segment %d layer %lld is %s\n", features[i].segment, features[i].layer, (*layer_unmaps)[features[i].segment][features[i].layer].c_str());
features[i]->coalesced = false;
features[i].coalesced = false;
}
}
}
std::vector<std::shared_ptr<serial_feature>> &layer_features = features;
std::vector<serial_feature> &layer_features = features;
if (additional[A_REORDER]) {
std::stable_sort(layer_features.begin(), layer_features.end(), coalindexcmp_comparator());
@@ -2435,11 +2454,11 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
for (size_t x = 1; x < layer_features.size(); x++) {
size_t y = out - 1;
if (out > 0 && coalcmp(&*layer_features[x], &*layer_features[y]) == 0) {
for (size_t g = 0; g < layer_features[x]->geometry.size(); g++) {
layer_features[y]->geometry.push_back(std::move(layer_features[x]->geometry[g]));
if (out > 0 && coalcmp(&layer_features[x], &layer_features[y]) == 0) {
for (size_t g = 0; g < layer_features[x].geometry.size(); g++) {
layer_features[y].geometry.push_back(std::move(layer_features[x].geometry[g]));
}
layer_features[y]->coalesced = true;
layer_features[y].coalesced = true;
} else {
layer_features[out++] = layer_features[x];
}
@@ -2457,25 +2476,25 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
size_t out = 0;
for (size_t x = 0; x < layer_features.size(); x++) {
if (layer_features[x]->coalesced && layer_features[x]->t == VT_LINE) {
layer_features[x]->geometry = remove_noop(layer_features[x]->geometry, layer_features[x]->t, 0);
if (layer_features[x].coalesced && layer_features[x].t == VT_LINE) {
layer_features[x].geometry = remove_noop(layer_features[x].geometry, layer_features[x].t, 0);
if (!(prevent[P_SIMPLIFY] || (z == maxzoom && prevent[P_SIMPLIFY_LOW]))) {
// XXX revisit: why does this not take zoom into account?
layer_features[x]->geometry = simplify_lines(layer_features[x]->geometry, 32, 0, 0, 0,
!(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, layer_features[x]->t == VT_POLYGON ? 4 : 0, shared_nodes, NULL, 0, "");
layer_features[x].geometry = simplify_lines(layer_features[x].geometry, 32, 0, 0, 0,
!(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, layer_features[x].t == VT_POLYGON ? 4 : 0, shared_nodes, NULL, 0, "");
}
}
if (layer_features[x]->t == VT_POLYGON) {
if (layer_features[x]->coalesced) {
if (layer_features[x].t == VT_POLYGON) {
if (layer_features[x].coalesced) {
// we can try scaling up because this is tile coordinates
layer_features[x]->geometry = clean_or_clip_poly(layer_features[x]->geometry, 0, 0, false, true);
layer_features[x].geometry = clean_or_clip_poly(layer_features[x].geometry, 0, 0, false, true);
}
layer_features[x]->geometry = close_poly(layer_features[x]->geometry);
layer_features[x].geometry = close_poly(layer_features[x].geometry);
}
if (layer_features[x]->geometry.size() > 0) {
if (layer_features[x].geometry.size() > 0) {
layer_features[out++] = layer_features[x];
}
}
@@ -2516,7 +2535,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
size_t feature_count = 0;
for (auto layer_iterator = layers.begin(); layer_iterator != layers.end(); ++layer_iterator) {
std::vector<std::shared_ptr<serial_feature>> &layer_features = layer_iterator->second.features;
std::vector<serial_feature> &layer_features = layer_iterator->second.features;
feature_count += layer_features.size();
mvt_layer layer;
@@ -2527,37 +2546,34 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
for (size_t x = 0; x < layer_features.size(); x++) {
mvt_feature feature;
if (layer_features[x]->t == VT_LINE || layer_features[x]->t == VT_POLYGON) {
layer_features[x]->geometry = remove_noop(layer_features[x]->geometry, layer_features[x]->t, 0);
if (layer_features[x].t == VT_LINE || layer_features[x].t == VT_POLYGON) {
layer_features[x].geometry = remove_noop(layer_features[x].geometry, layer_features[x].t, 0);
}
if (layer_features[x]->geometry.size() == 0) {
layer_features[x] = std::make_shared<serial_feature>();
if (layer_features[x].geometry.size() == 0) {
layer_features[x] = serial_feature();
continue;
}
feature.type = layer_features[x]->t;
feature.geometry = to_feature(layer_features[x]->geometry);
count += layer_features[x]->geometry.size();
layer_features[x]->geometry.clear();
feature.type = layer_features[x].t;
feature.geometry = to_feature(layer_features[x].geometry);
count += layer_features[x].geometry.size();
layer_features[x].geometry.clear();
feature.id = layer_features[x]->id;
feature.has_id = layer_features[x]->has_id;
feature.id = layer_features[x].id;
feature.has_id = layer_features[x].has_id;
decode_meta(*layer_features[x], layer, feature);
for (size_t a = 0; a < layer_features[x]->full_keys.size(); a++) {
serial_val sv = layer_features[x]->full_values[a];
decode_meta(layer_features[x], layer, feature);
for (size_t a = 0; a < layer_features[x].full_keys.size(); a++) {
serial_val sv = layer_features[x].full_values[a];
mvt_value v = stringified_to_mvt_value(sv.type, sv.s.c_str(), tile_stringpool);
layer.tag(feature, *layer_features[x]->full_keys[a], v);
layer.tag(feature, *layer_features[x].full_keys[a], v);
}
layer_features[x]->full_keys.clear();
layer_features[x]->full_values.clear();
if (additional[A_CALCULATE_FEATURE_DENSITY]) {
int glow = 255;
if (layer_features[x]->spacing > 0) {
glow = (1 / layer_features[x]->spacing);
if (layer_features[x].spacing > 0) {
glow = (1 / layer_features[x].spacing);
if (glow > 255) {
glow = 255;
}
@@ -2576,7 +2592,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
}
layer.features.push_back(std::move(feature));
layer_features[x] = std::make_shared<serial_feature>();
layer_features[x] = serial_feature();
}
if (layer.features.size() > 0) {
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef VERSION_HPP
#define VERSION_HPP
#define VERSION "v2.75.1"
#define VERSION "v2.74.0"
#endif