Work in progress on binning features in overzoom (#258)

* Factoring out tilestats management from GeoJSON file reading

* Move code around so overzoom can link against parse_layers

* Read the file of bins

* Plumb the bins through to overzoom()

* Some zip code bins to test with

* (Currently non-functional) test of binning

* Starting to spell out the bin matching loop

* Can't flatten points, so don't flatten bins either

* More fleshing out bin traversal

* Bounding box of tile-relative mvt geometry

* Smallest enclosing tile from bbox

* Most of the bin scan

* Add point in polygon check. It crashes.

* Find the matching bins

* GDAL-style bounding boxes have eaten my brain

* Make some features to bin into

* Increment a count as features are found to be within the bins

* Fix longitude wraparound in overzoom bins

* Fix the tests

* Push off attribute copying until after bin assignment

* Carry sum of numeric attributes into the bins

* Also add mean, min, and max

* Add --calculate-feature-index since I keep needing it for testing

* Add an option to accumulate sum/mean/max/min/count of all numeric attrs

* Don't bake in tippecanoe:mean, since we redo it from sum and count

* Forgot to update this test fixture after removing tiled mean

* Update version and changelog
This commit is contained in:
Erica Fischer
2024-09-05 12:06:51 -07:00
committed by GitHub
parent f3b575ead4
commit 5b18eea673
27 changed files with 1305 additions and 410 deletions
+56
View File
@@ -835,3 +835,59 @@ long long mvt_value_to_long_long(mvt_value const &v) {
exit(EXIT_IMPOSSIBLE);
}
}
// This extracts a double value from an mvt_value
double mvt_value_to_double(mvt_value const &v) {
switch (v.type) {
case mvt_string:
return atof(v.c_str());
case mvt_float:
return v.numeric_value.float_value;
case mvt_double:
return v.numeric_value.double_value;
case mvt_int:
return v.numeric_value.int_value;
case mvt_uint:
return v.numeric_value.uint_value;
case mvt_sint:
return v.numeric_value.sint_value;
case mvt_bool:
return v.numeric_value.bool_value;
case mvt_null:
return 0;
default:
fprintf(stderr, "unhandled mvt_type %d\n", v.type);
exit(EXIT_IMPOSSIBLE);
}
}
void get_bbox(std::vector<mvt_geometry> const &geom,
long long *xmin, long long *ymin, long long *xmax, long long *ymax,
int z, int tx, int ty, int detail) {
*xmin = LLONG_MAX;
*ymin = LLONG_MAX;
*xmax = 0;
*ymax = 0;
for (auto const &g : geom) {
if (g.op == mvt_moveto || g.op == mvt_lineto) {
long long x = g.x;
long long y = g.y;
// to world scale
x = x * (1LL << (32 - z - detail));
y = y * (1LL << (32 - z - detail));
// to world origin
if (z > 0) {
x += (1LL << (32 - z)) * tx;
y += (1LL << (32 - z)) * ty;
}
*xmin = std::min(*xmin, x);
*ymin = std::min(*ymin, y);
*xmax = std::max(*xmax, x);
*ymax = std::max(*ymax, y);
}
}
}