Snap to the tile grid as each simplified point is chosen

This commit is contained in:
Erica Fischer
2023-05-04 14:37:19 -07:00
parent 605640e138
commit ae6eed17c1
5 changed files with 19 additions and 10 deletions
+13 -3
View File
@@ -832,7 +832,7 @@ static double square_distance_from_line(long long point_x, long long point_y, lo
} }
// https://github.com/Project-OSRM/osrm-backend/blob/733d1384a40f/Algorithms/DouglasePeucker.cpp // https://github.com/Project-OSRM/osrm-backend/blob/733d1384a40f/Algorithms/DouglasePeucker.cpp
static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t kept, size_t retain) { static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t kept, size_t retain, double res) {
e = e * e; e = e * e;
std::stack<int> recursion_stack; std::stack<int> recursion_stack;
@@ -875,7 +875,10 @@ static void douglas_peucker(drawvec &geom, int start, int n, double e, size_t ke
if (max_distance >= 0) { if (max_distance >= 0) {
// mark idx as necessary // mark idx as necessary
geom[start + farthest_element_index].necessary = 1; size_t k = start + farthest_element_index;
geom[k].necessary = 1;
geom[k].x = res * std::round((double) geom[k].x / res);
geom[k].y = res * std::round((double) geom[k].y / res);
kept++; kept++;
if (1 < farthest_element_index - first) { if (1 < farthest_element_index - first) {
@@ -961,6 +964,13 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds,
geom[i].necessary = 1; geom[i].necessary = 1;
geom[j - 1].necessary = 1; geom[j - 1].necessary = 1;
for (size_t k = i; k < j; k++) {
if (geom[k].necessary) {
geom[k].x = res * std::round((double) geom[k].x / res);
geom[k].y = res * std::round((double) geom[k].y / res);
}
}
// empirical mapping from douglas-peucker simplifications // empirical mapping from douglas-peucker simplifications
// to visvalingam simplifications that yield similar // to visvalingam simplifications that yield similar
// output sizes // output sizes
@@ -972,7 +982,7 @@ drawvec simplify_lines(drawvec &geom, int z, int detail, bool mark_tile_bounds,
if (additional[A_VISVALINGAM]) { if (additional[A_VISVALINGAM]) {
visvalingam(geom, i, j, scale, retain); visvalingam(geom, i, j, scale, retain);
} else { } else {
douglas_peucker(geom, i, j - i, res * simplification, 2, retain); douglas_peucker(geom, i, j - i, res * simplification, 2, retain, res);
} }
} }
i = j - 1; i = j - 1;
+2 -2
View File
@@ -34,7 +34,7 @@
#include <map> #include <map>
#include <cmath> #include <cmath>
#if defined(__APPLE__) || defined(__FreeBSD__) #if defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/types.h> #include <sys/types.h>
#include <sys/sysctl.h> #include <sys/sysctl.h>
#include <sys/param.h> #include <sys/param.h>
@@ -3521,7 +3521,7 @@ int main(int argc, char **argv) {
long long file_bbox[4] = {UINT_MAX, UINT_MAX, 0, 0}; long long file_bbox[4] = {UINT_MAX, UINT_MAX, 0, 0};
long long file_bbox1[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0}; // standard -180 to 180 world plane long long file_bbox1[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0}; // standard -180 to 180 world plane
long long file_bbox2[4] = {0x1FFFFFFFF, 0xFFFFFFFF, 0x100000000, 0}; // 0 to 360 world plane long long file_bbox2[4] = {0x1FFFFFFFF, 0xFFFFFFFF, 0x100000000, 0}; // 0 to 360 world plane
auto input_ret = read_input(sources, name ? name : out_mbtiles ? out_mbtiles auto input_ret = read_input(sources, name ? name : out_mbtiles ? out_mbtiles
+1 -1
View File
@@ -88,7 +88,7 @@ struct reader {
long long file_bbox[4] = {0, 0, 0, 0}; long long file_bbox[4] = {0, 0, 0, 0};
long long file_bbox1[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0}; // standard -180 to 180 world plane long long file_bbox1[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0, 0}; // standard -180 to 180 world plane
long long file_bbox2[4] = {0x1FFFFFFFF, 0xFFFFFFFF, 0x100000000, 0}; // 0 to 360 world plane long long file_bbox2[4] = {0x1FFFFFFFF, 0xFFFFFFFF, 0x100000000, 0}; // 0 to 360 world plane
struct stat geomst {}; struct stat geomst {};
+1 -3
View File
@@ -1178,7 +1178,7 @@ int main(int argc, char **argv) {
std::string sa; std::string sa;
filearg = 1; filearg = 1;
while (getline(read_file, sa)) { while (getline(read_file, sa)) {
char* c = const_cast<char*>(sa.c_str()); char *c = const_cast<char *>(sa.c_str());
reader *r = begin_reading(c); reader *r = begin_reading(c);
struct reader **rr; struct reader **rr;
for (rr = &readers; *rr != NULL; rr = &((*rr)->next)) { for (rr = &readers; *rr != NULL; rr = &((*rr)->next)) {
@@ -1191,7 +1191,6 @@ int main(int argc, char **argv) {
} }
read_file.close(); read_file.close();
} }
} }
case 'q': case 'q':
@@ -1262,7 +1261,6 @@ int main(int argc, char **argv) {
std::string description; std::string description;
std::string name; std::string name;
if (filearg == 0) { if (filearg == 0) {
for (i = optind; i < argc; i++) { for (i = optind; i < argc; i++) {
reader *r = begin_reading(argv[i]); reader *r = begin_reading(argv[i]);
+2 -1
View File
@@ -573,6 +573,7 @@ double simplify_partial(partial *p, drawvec &shared_nodes) {
} }
// continues to simplify to line_detail even if we have extra detail // continues to simplify to line_detail even if we have extra detail
// should this change since we are now snapping as part of simplifying?
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);
if (t != VT_POLYGON || ngeom.size() >= 3) { if (t != VT_POLYGON || ngeom.size() >= 3) {
@@ -2301,7 +2302,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
std::string layername = (*layer_unmaps)[p.segment][p.layer]; std::string layername = (*layer_unmaps)[p.segment][p.layer];
serial_val sv, sv2, sv3, sv4; serial_val sv, sv2, sv3, sv4;
long long point_count = p.clustered + 1; long long point_count = p.clustered + 1;
char abbrev[17]; // to_string(LLONG_MAX).length() / 1000 + 1; char abbrev[17]; // to_string(LLONG_MAX).length() / 1000 + 1;
p.full_keys.push_back("clustered"); p.full_keys.push_back("clustered");
sv.type = mvt_bool; sv.type = mvt_bool;