Compare commits

..
Author SHA1 Message Date
Erica Fischer 8b362b0cd7 Griddy, but could be a lot worse 2023-01-04 16:50:01 -08:00
Erica Fischer 829c765d5d Somewhat less shardy 2023-01-04 14:51:20 -08:00
9 changed files with 74 additions and 67 deletions
-4
View File
@@ -1,7 +1,3 @@
## 2.18.0
* Fix crash when using tile-join to join an empty pmtiles tileset
## 2.17.0
* Add pmtiles output format
-23
View File
@@ -329,29 +329,6 @@ join-test: tile-join
./tippecanoe-decode -x generator tests/join-population/concat.mbtiles > tests/join-population/concat.mbtiles.json.check
cmp tests/join-population/concat.mbtiles.json.check tests/join-population/concat.mbtiles.json
rm tests/join-population/concat.mbtiles.json.check tests/join-population/concat.mbtiles tests/join-population/macarthur.mbtiles
#`
# Make sure empty tilesets work
#
# mbtiles:
./tippecanoe -q -z0 -f -o tests/join-population/empty.mbtiles tests/join-population/empty.json
./tile-join -f -o tests/join-population/empty.out.mbtiles tests/join-population/empty.mbtiles
./tippecanoe-decode -x generator -x generator_options -x name -x description tests/join-population/empty.mbtiles > tests/join-population/empty.out.json.check
cmp tests/join-population/empty.out.json.check tests/join-population/empty.out.json
rm -f tests/join-population/empty.mbtiles tests/join-population/empty.out.mbtiles tests/join-population/empty.out.json.check
# pmtiles:
./tippecanoe -q -z0 -f -o tests/join-population/empty.pmtiles tests/join-population/empty.json
./tile-join -f -o tests/join-population/empty.out.pmtiles tests/join-population/empty.pmtiles
./tippecanoe-decode -x generator -x generator_options -x name -x description tests/join-population/empty.pmtiles > tests/join-population/empty.out.json.check
cmp tests/join-population/empty.out.json.check tests/join-population/empty.out.json
rm -f tests/join-population/empty.pmtiles tests/join-population/empty.out.pmtiles tests/join-population/empty.out.json.check
# dirtiles:
./tippecanoe -q -z0 -f -e tests/join-population/empty.dirtiles tests/join-population/empty.json
./tile-join -f -e tests/join-population/empty.out.dirtiles tests/join-population/empty.dirtiles
./tippecanoe-decode -x generator -x generator_options -x name -x description tests/join-population/empty.dirtiles > tests/join-population/empty.out.json.check
cmp tests/join-population/empty.out.json.check tests/join-population/empty.out.json
rm -rf tests/join-population/empty.dirtiles tests/join-population/empty.out.dirtiles tests/join-population/empty.out.json.check
join-filter-test:
# Comes out different from the direct tippecanoe run because null attributes are lost
+37 -15
View File
@@ -869,9 +869,17 @@ static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t ke
double distance = std::fabs(temp_dist);
if ((distance > e || kept < retain) && distance > max_distance) {
farthest_element_index = i;
max_distance = distance;
if ((distance > e || kept < retain) && distance >= max_distance) {
if (distance > max_distance) {
farthest_element_index = i;
max_distance = distance;
} else if (geom[i].y > geom[farthest_element_index].y) {
farthest_element_index = i;
max_distance = distance;
} else if (geom[i].y == geom[farthest_element_index].y && geom[i].x == geom[farthest_element_index].x) {
farthest_element_index = i;
max_distance = distance;
}
}
}
@@ -926,7 +934,7 @@ drawvec impose_tile_boundaries(drawvec &geom, long long extent) {
return out;
}
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes) {
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes, std::set<std::pair<long long, long long>> &kept) {
int res = 1 << (32 - detail - z);
long long area = 1LL << (32 - z);
@@ -939,6 +947,11 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds,
geom[i].necessary = 1;
}
auto found = kept.find(std::pair<long long, long long>((long long) geom[i].x, (long long) geom[i].y));
if (found != kept.end()) {
geom[i].necessary = 1;
}
if (prevent[P_SIMPLIFY_SHARED_NODES]) {
auto pt = std::lower_bound(shared_nodes.begin(), shared_nodes.end(), geom[i]);
if (pt != shared_nodes.end() && *pt == geom[i]) {
@@ -963,20 +976,28 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds,
geom[i].necessary = 1;
geom[j - 1].necessary = 1;
// empirical mapping from douglas-peucker simplifications
// to visvalingam simplifications that yield similar
// output sizes
double sim = simplification * (0.1596 * z + 0.878);
double scale = (res * sim) * (res * sim);
scale = exp(1.002 * log(scale) + 0.3043);
size_t start = i;
for (size_t k = start + 1; k <= j - 1; k++) {
if (geom[k].necessary) {
if (k - start > 1) {
// empirical mapping from douglas-peucker simplifications
// to visvalingam simplifications that yield similar
// output sizes
double sim = simplification * (0.1596 * z + 0.878);
double scale = (res * sim) * (res * sim);
scale = exp(1.002 * log(scale) + 0.3043);
if (j - i > 1) {
if (additional[A_VISVALINGAM]) {
visvalingam(geom, i, j, scale, retain);
} else {
douglas_peucker(geom, i, j - i, res * simplification, 2, retain);
if (additional[A_VISVALINGAM]) {
visvalingam(geom, start, k + 1, scale, retain);
} else {
douglas_peucker(geom, start, k + 1 - start, res * simplification, 2, retain);
}
}
start = k;
}
}
i = j - 1;
}
}
@@ -985,6 +1006,7 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds,
for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].necessary) {
out.push_back(geom[i]);
kept.insert(std::pair<long long, long long>((long long) geom[i].x, (long long) geom[i].y));
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
#define GEOMETRY_HPP
#include <vector>
#include <set>
#include <atomic>
#include <sqlite3.h>
#include <stdio.h>
@@ -71,7 +72,7 @@ drawvec clip_lines(drawvec &geom, int z, long long buffer);
drawvec stairstep(drawvec &geom, int z, int detail);
bool point_within_tile(long long x, long long y, int z);
int quick_check(long long *bbox, int z, long long buffer);
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes);
drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes, std::set<std::pair<long long, long long>> &kept);
drawvec reorder_lines(drawvec &geom);
drawvec fix_polygon(drawvec &geom);
std::vector<drawvec> chop_polygon(std::vector<drawvec> &geoms);
-2
View File
@@ -1,2 +0,0 @@
{ "type": "Feature", "properties": { "id": 1 }, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 417.4513514, -299.1709459 ], [ 415.1435811, -288.1915541 ], [ 421.1577703, -286.2334459 ], [ 431.5077703, -317.4932432 ], [ 471.2293919, -312.2483108 ] ] ] } }
{ "type": "Feature", "properties": { "id": 2 }, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 423.6753378, -364.5577703 ], [ 426.3327703, -334.0672297 ], [ 512.3496622, -321.7591216 ], [ 510.2516892, -347.4942568 ] ] ] } }
-11
View File
@@ -1,11 +0,0 @@
{ "type": "FeatureCollection", "properties": {
"bounds": "-180.000000,-85.051129,180.000000,-85.051129",
"center": "0.000000,-85.051129,0",
"format": "pbf",
"json": "{\"vector_layers\":[{\"id\":\"empty\",\"description\":\"\",\"minzoom\":0,\"maxzoom\":0,\"fields\":{\"id\":\"Number\"}}],\"tilestats\":{\"layerCount\":1,\"layers\":[{\"layer\":\"empty\",\"count\":2,\"geometry\":\"LineString\",\"attributeCount\":1,\"attributes\":[{\"attribute\":\"id\",\"count\":2,\"type\":\"number\",\"values\":[1,2],\"min\":1,\"max\":2}]}]}}",
"maxzoom": "0",
"minzoom": "0",
"type": "overlay",
"version": "2"
}, "features": [
] }
+2 -3
View File
@@ -456,10 +456,9 @@ struct reader *begin_reading(char *fname) {
r->x = r->pmtiles_entries.back().x;
r->y = r->pmtiles_entries.back().y;
r->sorty = (1LL << r->zoom) - 1 - r->y;
r->data = std::string(r->pmtiles_map + r->pmtiles_entries.back().offset, r->pmtiles_entries.back().length);
r->pmtiles_entries.pop_back();
}
r->data = std::string(r->pmtiles_map + r->pmtiles_entries.back().offset, r->pmtiles_entries.back().length);
r->pmtiles_entries.pop_back();
} else {
sqlite3 *db;
+32 -7
View File
@@ -517,7 +517,7 @@ drawvec revive_polygon(drawvec &geom, double area, int z, int detail) {
}
}
double simplify_partial(partial *p, drawvec &shared_nodes) {
double simplify_partial(partial *p, drawvec &shared_nodes, std::set<std::pair<long long, long long>> &kept) {
drawvec geom;
for (size_t j = 0; j < p->geoms.size(); j++) {
@@ -566,7 +566,7 @@ double simplify_partial(partial *p, drawvec &shared_nodes) {
}
// continues to simplify to line_detail even if we have extra detail
drawvec ngeom = simplify_lines(geom, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), p->simplification, t == VT_POLYGON ? 4 : 0, shared_nodes);
drawvec ngeom = simplify_lines(geom, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), p->simplification, t == VT_POLYGON ? 4 : 0, shared_nodes, kept);
if (t != VT_POLYGON || ngeom.size() >= 3) {
geom = ngeom;
@@ -586,10 +586,31 @@ double simplify_partial(partial *p, drawvec &shared_nodes) {
void *partial_feature_worker(void *v) {
struct partial_arg *a = (struct partial_arg *) v;
std::vector<struct partial> *partials = a->partials;
std::set<std::pair<long long, long long>> kept;
for (size_t i = 0; i < (*partials).size(); i++) {
for (size_t j = 0; j < (*partials)[i].geoms.size(); j++) {
(*partials)[i].geoms[j] = remove_noop((*partials)[i].geoms[j], (*partials)[i].t, 0);
}
}
for (size_t n = 0; n < 20; n++) {
size_t before = kept.size();
for (size_t i = a->task; i < (*partials).size(); i += a->tasks) {
auto stash = (*partials)[i].geoms;
double area = simplify_partial(&((*partials)[i]), *(a->shared_nodes), kept);
(*partials)[i].geoms = stash;
}
printf("%zu nodes kept\n", kept.size());
if (kept.size() == before) {
break;
}
}
for (size_t i = a->task; i < (*partials).size(); i += a->tasks) {
double area = simplify_partial(&((*partials)[i]), *(a->shared_nodes));
double area = simplify_partial(&((*partials)[i]), *(a->shared_nodes), kept);
signed char t = (*partials)[i].t;
int z = (*partials)[i].z;
int out_detail = (*partials)[i].extra_detail;
@@ -1001,6 +1022,7 @@ bool find_common_edges(std::vector<partial> &partials, int z, int line_detail, d
// Simplify each arc
std::vector<drawvec> simplified_arcs;
std::set<std::pair<long long, long long>> kept;
size_t count = 0;
for (auto ai = arcs.begin(); ai != arcs.end(); ++ai) {
@@ -1017,7 +1039,7 @@ bool find_common_edges(std::vector<partial> &partials, int z, int line_detail, d
}
}
if (!(prevent[P_SIMPLIFY] || (z == maxzoom && prevent[P_SIMPLIFY_LOW]) || (z < maxzoom && additional[A_GRID_LOW_ZOOMS]))) {
simplified_arcs[ai->second] = simplify_lines(dv, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, 4, drawvec());
simplified_arcs[ai->second] = simplify_lines(dv, z, line_detail, !(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, 4, drawvec(), kept);
} else {
simplified_arcs[ai->second] = dv;
}
@@ -2215,9 +2237,10 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
unsimplified_geometry_size += sf.geometry.size() * sizeof(draw);
if (unsimplified_geometry_size > 10 * 1024 * 1024 && !additional[A_DETECT_SHARED_BORDERS]) {
drawvec dv;
std::set<std::pair<long long, long long>> keptp;
for (; simplified_geometry_through < partials.size(); simplified_geometry_through++) {
simplify_partial(&partials[simplified_geometry_through], dv);
simplify_partial(&partials[simplified_geometry_through], dv, keptp);
for (auto &g : partials[simplified_geometry_through].geoms) {
if (partials[simplified_geometry_through].t == VT_POLYGON) {
@@ -2327,6 +2350,7 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
if (tasks < 1) {
tasks = 1;
}
tasks = 1;
pthread_t pthreads[tasks];
std::vector<partial_arg> args;
@@ -2445,12 +2469,13 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
layer_features = out;
std::set<std::pair<long long, long long>> keptp;
out.clear();
for (size_t x = 0; x < layer_features.size(); x++) {
if (layer_features[x].coalesced && layer_features[x].type == VT_LINE) {
layer_features[x].geom = remove_noop(layer_features[x].geom, layer_features[x].type, 0);
layer_features[x].geom = simplify_lines(layer_features[x].geom, 32, 0,
!(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, layer_features[x].type == VT_POLYGON ? 4 : 0, shared_nodes);
!(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, layer_features[x].type == VT_POLYGON ? 4 : 0, shared_nodes, keptp);
}
if (layer_features[x].type == VT_POLYGON) {
+1 -1
View File
@@ -1,6 +1,6 @@
#ifndef VERSION_HPP
#define VERSION_HPP
#define VERSION "v2.18.0"
#define VERSION "v2.17.0"
#endif