mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +02:00
Somewhat less shardy
This commit is contained in:
+7
-1
@@ -926,7 +926,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 +939,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]) {
|
||||
@@ -985,6 +990,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,9 +586,10 @@ 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 = 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;
|
||||
@@ -1001,6 +1002,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 +1019,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 +2217,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 +2330,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 +2449,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