Progress toward eliminating decodes of feature indices

This commit is contained in:
Erica Fischer
2025-02-10 13:02:22 -08:00
parent 16c71ff756
commit ebcc8bf799
6 changed files with 30 additions and 14 deletions
+2 -4
View File
@@ -944,12 +944,10 @@ drawvec polygon_to_anchor(const drawvec &geom) {
return drawvec();
}
drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigned long long label_point) {
drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigned wx, unsigned wy) {
drawvec out;
// anchor point in world coordinates
unsigned wx, wy;
decode_index(label_point, &wx, &wy);
// wx,wy is anchor point in world coordinates
// upper left of tile in world coordinates
long long tx1 = 0, ty1 = 0;
+1 -1
View File
@@ -89,7 +89,7 @@ void check_polygon(drawvec &geom);
double get_area(const drawvec &geom, size_t i, size_t j);
double get_mp_area(drawvec &geom);
drawvec polygon_to_anchor(const drawvec &geom);
drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigned long long label_point);
drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigned label_x, unsigned label_y);
drawvec simple_clip_poly(drawvec &geom, int z, int buffer, drawvec &shared_nodes, bool prevent_simplify_shared_nodes);
drawvec simple_clip_poly(drawvec &geom, long long x1, long long y1, long long x2, long long y2, bool prevent_simplify_shared_nodes);
+1
View File
@@ -2499,6 +2499,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
long long ip;
for (ip = 0; ip < indices; ip++) {
unsigned xx, yy;
// XXX this will behave oddly if the index is actually H3
decode_index(map[ip].ix, &xx, &yy);
long long nprogress = 100 * ip / indices;
+20 -6
View File
@@ -186,7 +186,7 @@ std::string serialize_feature(serial_feature *sf, long long wx, long long wy) {
long long layer = 0;
layer |= sf->layer << FLAG_LAYER;
layer |= (sf->label_point != 0) << FLAG_LABEL_POINT;
layer |= ((sf->label_x | sf->label_y) != 0) << FLAG_LABEL_POINT;
layer |= (sf->index != 0) << FLAG_INDEX;
layer |= (sf->extent != 0) << FLAG_EXTENT;
layer |= sf->has_id << FLAG_ID;
@@ -211,10 +211,13 @@ std::string serialize_feature(serial_feature *sf, long long wx, long long wy) {
if (sf->index != 0) {
serialize_ulong_long(s, sf->index);
serialize_ulong_long(s, sf->wx);
serialize_ulong_long(s, sf->wy);
serialize_ulong_long(s, sf->gap);
}
if (sf->label_point != 0) {
serialize_ulong_long(s, sf->label_point);
if ((sf->label_x | sf->label_y) != 0) {
serialize_ulong_long(s, sf->label_x);
serialize_ulong_long(s, sf->label_y);
}
if (sf->extent != 0) {
serialize_long_long(s, sf->extent);
@@ -261,17 +264,27 @@ serial_feature deserialize_feature(std::string const &geoms, unsigned z, unsigne
sf.index = 0;
sf.gap = 0;
sf.label_point = 0;
sf.label_x = 0;
sf.label_y = 0;
sf.extent = 0;
sf.geometry = decode_geometry(&cp, z, tx, ty, sf.bbox, initial_x[sf.segment], initial_y[sf.segment]);
if (sf.layer & (1 << FLAG_INDEX)) {
unsigned long long wx, wy;
deserialize_ulong_long(&cp, &sf.index);
deserialize_ulong_long(&cp, &wx);
deserialize_ulong_long(&cp, &wy);
sf.wx = wx;
sf.wy = wy;
deserialize_ulong_long(&cp, &sf.gap);
}
if (sf.layer & (1 << FLAG_LABEL_POINT)) {
deserialize_ulong_long(&cp, &sf.label_point);
unsigned long long wx, wy;
deserialize_ulong_long(&cp, &wx);
deserialize_ulong_long(&cp, &wy);
sf.label_x = wx;
sf.label_y = wy;
}
if (sf.layer & (1 << FLAG_EXTENT)) {
deserialize_long_long(&cp, &sf.extent);
@@ -741,7 +754,8 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
if (dv.size() > 0) {
dv[0].x = SHIFT_LEFT(dv[0].x) & ((1LL << 32) - 1);
dv[0].y = SHIFT_LEFT(dv[0].y) & ((1LL << 32) - 1);
sf.label_point = encode_index(dv[0].x, dv[0].y);
sf.label_x = dv[0].x;
sf.label_y = dv[0].y;
}
}
+2 -1
View File
@@ -118,8 +118,9 @@ struct serial_feature {
drawvec geometry = drawvec();
unsigned long long index = 0;
unsigned wx = 0, wy = 0;
unsigned long long gap = 0; // filled in during z0. square of planar distance
unsigned long long label_point = 0;
unsigned label_x = 0, label_y = 0;
long long extent = 0;
// These fields are not directly serialized, but are used
+4 -2
View File
@@ -714,7 +714,7 @@ 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);
geom = checkerboard_anchors(from_tile_scale(geom, z, out_detail), (*features)[i]->tx, (*features)[i]->ty, z, (*features)[i]->label_x, (*features)[i]->label_y);
to_tile_scale(geom, z, out_detail);
}
@@ -1131,6 +1131,8 @@ static serial_feature next_feature(decompressor *geoms, std::atomic<long long> *
unsigned wx1, wy1;
decode_index(next_feature_state.previndex, &wx1, &wy1);
// find the furthest distance of a vertex in this feature
// from the representative point of the previous feature
for (auto const &g : sf.geometry) {
long long dx = (long long) wx1 - (g.x + ox);
long long dy = (long long) wy1 - (g.y + oy);
@@ -2819,7 +2821,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
}
if (skipped > 0 || too_many_bytes || too_many_features) {
fprintf(stderr, "Can't happen: writing tile even though we skipped\n");
fprintf(stderr, "Can't happen: writing tile even though we skipped (%zu %d %d)\n", skipped, too_many_bytes, too_many_features);
exit(EXIT_IMPOSSIBLE);
}