Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.32.5

* Use less memory on lines and polygons that are too small for the tile
* Fix coordinate rounding problem that was causing --grid-low-zooms grids
to be lost at low zooms if the original polygons were not aligned to
tile boundaries

## 1.32.4

* Ignore leading zeroes when converting string attributes to feature IDs
Expand Down
4 changes: 2 additions & 2 deletions geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,8 @@ drawvec stairstep(drawvec &geom, int z, int detail) {
double scale = 1 << (32 - detail - z);

for (size_t i = 0; i < geom.size(); i++) {
geom[i].x = std::round(geom[i].x / scale);
geom[i].y = std::round(geom[i].y / scale);
geom[i].x = std::floor(geom[i].x / scale);
geom[i].y = std::floor(geom[i].y / scale);
}

for (size_t i = 0; i < geom.size(); i++) {
Expand Down
11 changes: 8 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3050,9 +3050,14 @@ int main(int argc, char **argv) {
full_detail = 12;
}

if (full_detail < min_detail || low_detail < min_detail) {
fprintf(stderr, "%s: Full detail and low detail must be at least minimum detail\n", argv[0]);
exit(EXIT_FAILURE);
if (full_detail < min_detail) {
min_detail = full_detail;
fprintf(stderr, "%s: Reducing minimum detail to match full detail %d\n", argv[0], min_detail);
}

if (low_detail < min_detail) {
min_detail = low_detail;
fprintf(stderr, "%s: Reducing minimum detail to match low detail %d\n", argv[0], min_detail);
}

// Need two checks: one for geometry representation, the other for
Expand Down
14 changes: 12 additions & 2 deletions serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ static long long scale_geometry(struct serialization_state *sst, long long *bbox
long long offset = 0;
long long prev = 0;
bool has_prev = false;
double scale = 1.0 / (1 << geometry_scale);

for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO || geom[i].op == VT_LINETO) {
Expand Down Expand Up @@ -365,8 +366,17 @@ static long long scale_geometry(struct serialization_state *sst, long long *bbox
*(sst->initialized) = 1;
}

geom[i].x = x >> geometry_scale;
geom[i].y = y >> geometry_scale;
if (additional[A_GRID_LOW_ZOOMS]) {
// If we are gridding, snap to the maxzoom grid in case the incoming data
// is already supposed to be aligned to tile boundaries (but is not, exactly,
// because of rounding error during projection).

geom[i].x = std::round(x * scale);
geom[i].y = std::round(y * scale);
} else {
geom[i].x = x >> geometry_scale;
geom[i].y = y >> geometry_scale;
}
}
}

Expand Down
1,024 changes: 1,024 additions & 0 deletions tests/grid-aligned/in.json

Large diffs are not rendered by default.

2,806 changes: 2,806 additions & 0 deletions tests/grid-aligned/out/-z11_-D7_--grid-low-zooms.json

Large diffs are not rendered by default.

1,024 changes: 1,024 additions & 0 deletions tests/grid-unaligned/in.json

Large diffs are not rendered by default.

4,670 changes: 4,670 additions & 0 deletions tests/grid-unaligned/out/-z11_-D7_--grid-low-zooms.json

Large diffs are not rendered by default.

2,834 changes: 1,411 additions & 1,423 deletions tests/ne_110m_admin_0_countries/out/-z4_-yname_--grid-low-zooms_-D8.json

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,26 @@ bool find_partial(std::vector<partial> &partials, serial_feature &sf, ssize_t &o
return false;
}

static bool line_is_too_small(drawvec const &geometry, int z, int detail) {
if (geometry.size() == 0) {
return true;
}

long long x = geometry[0].x >> (32 - detail - z);
long long y = geometry[0].y >> (32 - detail - z);

for (auto &g : geometry) {
long long xx = g.x >> (32 - detail - z);
long long yy = g.y >> (32 - detail - z);

if (xx != x || yy != y) {
return false;
}
}

return true;
}

long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *metabase, char *stringpool, int z, unsigned tx, unsigned ty, int detail, int min_detail, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, FILE **geomfile, int minzoom, int maxzoom, double todo, std::atomic<long long> *along, long long alongminus, double gamma, int child_shards, long long *meta_off, 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, size_t passes, unsigned long long mingap, long long minextent, double fraction, const char *prefilter, const char *postfilter, struct json_object *filter, write_tile_args *arg) {
int line_detail;
double merge_fraction = 1;
Expand Down Expand Up @@ -1929,6 +1949,11 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
}
has_polygons = true;
}
if (sf.t == VT_POLYGON || sf.t == VT_LINE) {
if (line_is_too_small(sf.geometry, z, line_detail)) {
continue;
}
}

if (sf.geometry.size() > 0) {
partial p;
Expand Down
2 changes: 1 addition & 1 deletion version.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef VERSION_HPP
#define VERSION_HPP

#define VERSION "v1.32.4"
#define VERSION "v1.32.5"

#endif