mirror of
https://github.com/felt/tippecanoe.git
synced 2026-11-22 16:31:18 +01:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b362b0cd7 | ||
|
|
829c765d5d |
+37
-15
@@ -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
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user