Compare commits

...
32 Commits
Author SHA1 Message Date
Erica Fischer 3556142d80 Hilbert and quadkey 128-bit encodings are reversible 2024-04-05 14:02:58 -07:00
Erica Fischer 77f5e9677f Next step of index widening; tests still pass 2024-04-05 12:44:29 -07:00
Erica Fischer 47124087ca Unit test coordinate encoding and decoding 2024-04-05 12:23:37 -07:00
Erica Fischer bc5183c075 Found the place that expected to be able to mask bits off the top 2024-04-04 16:37:06 -07:00
Erica Fischer dcda6bcdd5 Work in progress on a new feature sort 2024-04-04 15:29:45 -07:00
Erica Fischer da94dbf9c4 Getting a little closer to 128-bit indices 2024-04-03 14:21:32 -07:00
Erica Fischer 6c148a63f7 Use a typedef for variables representing quadkey/hilbert indices 2024-04-03 13:50:03 -07:00
Erica Fischer 9c7a1b66f5 Revert "Progress on 128-bit indices"
This reverts commit 2abbcc7099.
2024-04-03 12:48:32 -07:00
Erica Fischer 3e1848c67c Merge remote-tracking branch 'origin/main' into more-detail 2024-04-03 12:46:35 -07:00
Erica Fischer 2ea364d32a Make it further into the tests 2024-04-01 12:25:08 -07:00
Erica Fischer 2abbcc7099 Progress on 128-bit indices 2024-03-29 21:55:25 -07:00
Erica Fischer 054becc58f Merge remote-tracking branch 'origin/main' into more-detail 2024-03-29 13:56:41 -07:00
Erica Fischer 5dd72da3f8 Work around overflow in distance calculations 2024-03-18 12:47:07 -07:00
Erica Fischer 686ab56c4a Bringing back reverted overflow changes, one at a time 2024-03-18 12:37:24 -07:00
Erica Fischer cf63945c37 Revert "Fix more overflows"
This reverts commit cc6135dd02.
2024-03-18 12:28:19 -07:00
Erica Fischer ccc49bc870 Revert "Use 128-bit arithmetic to avoid overflow"
This reverts commit 3b948e0f20.
2024-03-18 12:28:11 -07:00
Erica Fischer 77431db47d Don't let bounds stick off the edge of the plane 2024-03-18 11:47:46 -07:00
Erica Fischer 3b948e0f20 Use 128-bit arithmetic to avoid overflow 2024-03-18 11:37:47 -07:00
Erica Fischer cc6135dd02 Fix more overflows 2024-03-18 10:17:18 -07:00
Erica Fischer 1c97d476c5 Fix tileset bounds 2024-03-18 09:54:21 -07:00
Erica Fischer 331bd662bc Fix cluster-distance, which works by indices, not coordinates 2024-03-15 15:38:39 -07:00
Erica Fischer 3f45b5c51c Reduce test diff noisiness with intermediate rounding 2024-03-15 12:17:32 -07:00
Erica Fischer db9a4feec2 Trying to figure out what is throwing off this point's location 2024-03-15 10:16:28 -07:00
Erica Fischer fbc7ef52ac 32-bit worlds as hex strings 2024-03-15 08:57:37 -07:00
Erica Fischer accdb96409 Trying to fix tileset bounding boxes 2024-03-14 23:40:56 -07:00
Erica Fischer 96ba174473 Fix higher zooms 2024-03-14 23:27:15 -07:00
Erica Fischer dcf760a439 Fix z1 at least 2024-03-14 23:15:04 -07:00
Erica Fischer c114d17eb4 Change initial_x and initial_y to be 64-bit 2024-03-14 18:43:12 -07:00
Erica Fischer 4632b15b47 Eradicate more 32s 2024-03-14 14:54:54 -07:00
Erica Fischer a12bea7129 Straighten out hilbert and quadkey encoding 2024-03-14 14:36:51 -07:00
Erica Fischer a852c04ed4 More 32s 2024-03-14 13:43:42 -07:00
Erica Fischer cea16d3f7e Checkpoint on parameterizing 32s 2024-03-14 13:30:38 -07:00
25 changed files with 400 additions and 284 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ tile-join: tile-join.o projection.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpul
tippecanoe-json-tool: jsontool.o jsonpull/jsonpull.o csv.o text.o geojson-loop.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
unit: unit.o text.o sort.o mvt.o
unit: unit.o text.o sort.o mvt.o projection.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
tippecanoe-overzoom: overzoom.o mvt.o clip.o evaluator.o jsonpull/jsonpull.o text.o attribute.o
+23 -22
View File
@@ -10,6 +10,7 @@
#include "evaluator.hpp"
#include "serial.hpp"
#include "attribute.hpp"
#include "projection.hpp"
static std::vector<std::pair<double, double>> clip_poly1(std::vector<std::pair<double, double>> &geom,
long long minx, long long miny, long long maxx, long long maxy,
@@ -69,7 +70,7 @@ drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long lon
}
drawvec simple_clip_poly(drawvec &geom, int z, int buffer, drawvec &edge_nodes, bool prevent_simplify_shared_nodes) {
long long area = 1LL << (32 - z);
long long area = 1LL << (GLOBAL_DETAIL - z);
long long clip_buffer = buffer * area / 256;
return simple_clip_poly(geom, -clip_buffer, -clip_buffer, area + clip_buffer, area + clip_buffer,
@@ -78,7 +79,7 @@ drawvec simple_clip_poly(drawvec &geom, int z, int buffer, drawvec &edge_nodes,
drawvec clip_point(drawvec &geom, int z, long long buffer) {
long long min = 0;
long long area = 1LL << (32 - z);
long long area = 1LL << (GLOBAL_DETAIL - z);
min -= buffer * area / 256;
area += buffer * area / 256;
@@ -100,7 +101,7 @@ drawvec clip_point(drawvec &geom, long long minx, long long miny, long long maxx
drawvec clip_lines(drawvec &geom, int z, long long buffer) {
long long min = 0;
long long area = 1LL << (32 - z);
long long area = 1LL << (GLOBAL_DETAIL - z);
min -= buffer * area / 256;
area += buffer * area / 256;
@@ -176,7 +177,7 @@ int clip(long long *x0, long long *y0, long long *x1, long long *y1, long long x
} else {
// failed both tests, so calculate the line segment to clip
// from an outside point to an intersection with clip edge
long long x = *x0, y = *y0;
__int128 x = *x0, y = *y0;
// At least one endpoint is outside the clip rectangle; pick it.
int outcodeOut = outcode0 ? outcode0 : outcode1;
@@ -186,16 +187,16 @@ int clip(long long *x0, long long *y0, long long *x1, long long *y1, long long x
// Now find the intersection point;
// use formulas y = y0 + slope * (x - x0), x = x0 + (1 / slope) * (y - y0)
if (outcodeOut & TOP) { // point is above the clip rectangle
x = *x0 + (*x1 - *x0) * (ymax - *y0) / (*y1 - *y0);
x = *x0 + (__int128) (*x1 - *x0) * (ymax - *y0) / (*y1 - *y0);
y = ymax;
} else if (outcodeOut & BOTTOM) { // point is below the clip rectangle
x = *x0 + (*x1 - *x0) * (ymin - *y0) / (*y1 - *y0);
x = *x0 + (__int128) (*x1 - *x0) * (ymin - *y0) / (*y1 - *y0);
y = ymin;
} else if (outcodeOut & RIGHT) { // point is to the right of clip rectangle
y = *y0 + (*y1 - *y0) * (xmax - *x0) / (*x1 - *x0);
y = *y0 + (__int128) (*y1 - *y0) * (xmax - *x0) / (*x1 - *x0);
x = xmax;
} else if (outcodeOut & LEFT) { // point is to the left of clip rectangle
y = *y0 + (*y1 - *y0) * (xmin - *x0) / (*x1 - *x0);
y = *y0 + (__int128) (*y1 - *y0) * (xmin - *x0) / (*x1 - *x0);
x = xmin;
}
@@ -292,9 +293,9 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip, bool try
}
if (clip) {
long long area = 0xFFFFFFFF;
long long area = (1LL << GLOBAL_DETAIL) - 1;
if (z != 0) {
area = 1LL << (32 - z);
area = 1LL << (GLOBAL_DETAIL - z);
}
long long clip_buffer = buffer * area / 256;
@@ -383,15 +384,15 @@ drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip, bool try
}
void to_tile_scale(drawvec &geom, int z, int detail) {
if (32 - detail - z < 0) {
if (GLOBAL_DETAIL - detail - z < 0) {
for (size_t i = 0; i < geom.size(); i++) {
geom[i].x = std::round((double) geom[i].x * (1LL << (-(32 - detail - z))));
geom[i].y = std::round((double) geom[i].y * (1LL << (-(32 - detail - z))));
geom[i].x = geom[i].x * (1LL << (-(GLOBAL_DETAIL - detail - z)));
geom[i].y = geom[i].y * (1LL << (-(GLOBAL_DETAIL - detail - z)));
}
} else {
for (size_t i = 0; i < geom.size(); i++) {
geom[i].x = std::round((double) geom[i].x / (1LL << (32 - detail - z)));
geom[i].y = std::round((double) geom[i].y / (1LL << (32 - detail - z)));
geom[i].x = std::llround((double) geom[i].x / (1LL << (GLOBAL_DETAIL - detail - z)));
geom[i].y = std::llround((double) geom[i].y / (1LL << (GLOBAL_DETAIL - detail - z)));
}
}
}
@@ -400,8 +401,8 @@ drawvec from_tile_scale(drawvec const &geom, int z, int detail) {
drawvec out;
for (size_t i = 0; i < geom.size(); i++) {
draw d = geom[i];
d.x *= (1LL << (32 - detail - z));
d.y *= (1LL << (32 - detail - z));
d.x *= (1LL << (GLOBAL_DETAIL - detail - z));
d.y *= (1LL << (GLOBAL_DETAIL - detail - z));
out.push_back(d);
}
return out;
@@ -414,8 +415,8 @@ drawvec remove_noop(drawvec geom, int type, int shift) {
drawvec out;
for (size_t i = 0; i < geom.size(); i++) {
long long nx = std::round((double) geom[i].x / (1LL << shift));
long long ny = std::round((double) geom[i].y / (1LL << shift));
long long nx = std::llround((double) geom[i].x / (1LL << shift));
long long ny = std::llround((double) geom[i].y / (1LL << shift));
if (geom[i].op == VT_LINETO && nx == ox && ny == oy) {
continue;
@@ -526,7 +527,7 @@ double get_area(const drawvec &geom, size_t i, size_t j) {
// do not use the full precision, shift them nearer to the origin so
// their product is more likely to be exactly representable as a double.
//
// (In practice they are actually 34-bit integers: 32 bits for the
// (In practice they are actually (GLOBAL_DETAIL + 2)-bit integers: GLOBAL_DETAIL bits for the
// Mercator world plane, plus another two bits so features can stick
// off either the left or right side. But that is still too many bits
// for the product to fit either in a 64-bit long long or in a
@@ -931,7 +932,7 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
// Convert feature geometry to world coordinates
long long tilesize = 1LL << (32 - oz); // source tile size in world coordinates
long long tilesize = 1LL << (GLOBAL_DETAIL - oz); // source tile size in world coordinates
draw ring_closure(0, 0, 0);
bool sametile = (nz == oz && nx == ox && ny == oy && outlayer.extent >= layer.extent);
@@ -953,7 +954,7 @@ std::string overzoom(const mvt_tile &tile, int oz, int ox, int oy, int nz, int n
// Now offset from world coordinates to output tile coordinates,
// but retain world scale, because that is what tippecanoe clipping expects
long long outtilesize = 1LL << (32 - nz); // destination tile size in world coordinates
long long outtilesize = 1LL << (GLOBAL_DETAIL - nz); // destination tile size in world coordinates
for (auto &g : geom) {
g.x -= nx * outtilesize;
g.y -= ny * outtilesize;
+4 -2
View File
@@ -25,8 +25,10 @@
#include "pmtiles_file.hpp"
#include "errors.hpp"
#define MAX_MAXZOOM 32 // should this be higher?
int minzoom = 0;
int maxzoom = 32;
int maxzoom = MAX_MAXZOOM;
bool force = false;
bool progress_time() {
@@ -456,7 +458,7 @@ void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> co
int tx = sqlite3_column_int(stmt, 2);
int ty = sqlite3_column_int(stmt, 3);
if (tz < 0 || tz >= 32) {
if (tz < 0 || tz >= MAX_MAXZOOM) {
fprintf(stderr, "Impossible zoom level %d in mbtiles\n", tz);
exit(EXIT_IMPOSSIBLE);
}
+3 -1
View File
@@ -4,6 +4,8 @@
#include <sqlite3.h>
#include "errors.hpp"
#define MAX_MAXZOOM 32
void enumerate(char *fname) {
sqlite3 *db;
@@ -31,7 +33,7 @@ void enumerate(char *fname) {
long long x = sqlite3_column_int(stmt, 1);
long long y = sqlite3_column_int(stmt, 2);
if (zoom < 0 || zoom > 31) {
if (zoom < 0 || zoom > MAX_MAXZOOM) {
fprintf(stderr, "Corrupt mbtiles file: impossible zoom level %lld\n", zoom);
exit(EXIT_IMPOSSIBLE);
}
+2 -2
View File
@@ -45,7 +45,7 @@ drawvec readPoints(const FlatGeobuf::Geometry *geometry) {
for (unsigned int i = 0; i < xy->size(); i+=2) {
long long x, y;
projection->project(xy->Get(i), xy->Get(i+1), 32, &x, &y);
projection->project(xy->Get(i), xy->Get(i+1), GLOBAL_DETAIL, &x, &y);
dv.push_back(draw(VT_MOVETO, x, y));
}
return dv;
@@ -59,7 +59,7 @@ drawvec readLinePart(const FlatGeobuf::Geometry *geometry) {
for (unsigned int i = 0; i < xy->size(); i+=2) {
long long x, y;
projection->project(xy->Get(i), xy->Get(i+1), 32, &x, &y);
projection->project(xy->Get(i), xy->Get(i+1), GLOBAL_DETAIL, &x, &y);
if (i == 0 || (ends != NULL && current_end < ends->size() && i == ends->Get(current_end)*2)) {
dv.push_back(draw(VT_MOVETO, x, y));
if (i > 0) current_end++;
+2 -2
View File
@@ -101,7 +101,7 @@ drawvec readPoint(std::vector<long long> &coords, size_t dim, double e) {
ensureDim(dim);
long long x, y;
projection->project(coords[0] / e, coords[1] / e, 32, &x, &y);
projection->project(coords[0] / e, coords[1] / e, GLOBAL_DETAIL, &x, &y);
drawvec dv;
dv.push_back(draw(VT_MOVETO, x, y));
return dv;
@@ -128,7 +128,7 @@ drawvec readLinePart(std::vector<long long> &coords, size_t dim, double e, size_
}
long long x, y;
projection->project(p[0], p[1], 32, &x, &y);
projection->project(p[0], p[1], GLOBAL_DETAIL, &x, &y);
if (i == start) {
dv.push_back(draw(VT_MOVETO, x, y));
+1 -1
View File
@@ -85,7 +85,7 @@ void parse_geocsv(std::vector<struct serialization_state> &sst, std::string fnam
double lat = atof(line[latcol].c_str());
long long x, y;
projection->project(lon, lat, 32, &x, &y);
projection->project(lon, lat, GLOBAL_DETAIL, &x, &y);
drawvec dv;
dv.push_back(draw(VT_MOVETO, x, y));
+49 -46
View File
@@ -21,7 +21,7 @@
#include "errors.hpp"
#include "projection.hpp"
drawvec decode_geometry(const char **meta, int z, unsigned tx, unsigned ty, long long *bbox, unsigned initial_x, unsigned initial_y) {
drawvec decode_geometry(const char **meta, int z, long long tx, long long ty, long long *bbox, long long initial_x, long long initial_y) {
drawvec out;
bbox[0] = LLONG_MAX;
@@ -52,8 +52,8 @@ drawvec decode_geometry(const char **meta, int z, unsigned tx, unsigned ty, long
long long wwy = wy;
if (z != 0) {
wwx -= tx << (32 - z);
wwy -= ty << (32 - z);
wwx -= tx << (GLOBAL_DETAIL - z);
wwy -= ty << (GLOBAL_DETAIL - z);
}
bbox[0] = std::min(wwx, bbox[0]);
@@ -170,7 +170,7 @@ void check_polygon(drawvec &geom) {
drawvec reduce_tiny_poly(drawvec const &geom, int z, int detail, bool *still_needs_simplification, bool *reduced_away, double *accum_area) {
drawvec out;
const double pixel = (1LL << (32 - detail - z)) * (double) tiny_polygon_size;
const double pixel = (1LL << (GLOBAL_DETAIL - detail - z)) * (double) tiny_polygon_size;
bool included_last_outer = false;
*still_needs_simplification = false;
@@ -264,7 +264,7 @@ drawvec reduce_tiny_poly(drawvec const &geom, int z, int detail, bool *still_nee
int quick_check(const long long *bbox, int z, long long buffer) {
long long min = 0;
long long area = 1LL << (32 - z);
long long area = 1LL << (GLOBAL_DETAIL - z);
// bbox entirely within the tile proper
if (bbox[0] > min && bbox[1] > min && bbox[2] < area && bbox[3] < area) {
@@ -295,14 +295,14 @@ bool point_within_tile(long long x, long long y, int z) {
// No adjustment for buffer, because the point must be
// strictly within the tile to appear exactly once
long long area = 1LL << (32 - z);
long long area = 1LL << (GLOBAL_DETAIL - z);
return x >= 0 && y >= 0 && x < area && y < area;
}
double distance_from_line(long long point_x, long long point_y, long long segA_x, long long segA_y, long long segB_x, long long segB_y) {
long long p2x = segB_x - segA_x;
long long p2y = segB_y - segA_y;
__int128 p2x = segB_x - segA_x;
__int128 p2y = segB_y - segA_y;
// These calculations must be made in integers instead of floating point
// to make them consistent between x86 and arm floating point implementations.
@@ -311,7 +311,7 @@ double distance_from_line(long long point_x, long long point_y, long long segA_x
// making their sum up to 69 bits. Downshift before multiplying to keep them in range.
double something = ((p2x / 4) * (p2x / 8) + (p2y / 4) * (p2y / 8)) * 32.0;
// likewise
double u = (0 == something) ? 0 : ((point_x - segA_x) / 4 * (p2x / 8) + (point_y - segA_y) / 4 * (p2y / 8)) * 32.0 / (something);
double u = (0 == something) ? 0 : ((__int128) (point_x - segA_x) / 4 * (p2x / 8) + (__int128) (point_y - segA_y) / 4 * (p2y / 8)) * 32.0 / (something);
if (u >= 1) {
u = 1;
@@ -459,8 +459,8 @@ drawvec impose_tile_boundaries(const drawvec &geom, long long extent) {
}
drawvec simplify_lines(drawvec &geom, int z, int tx, int ty, int detail, bool mark_tile_bounds, double simplification, size_t retain, drawvec const &shared_nodes, struct node *shared_nodes_map, size_t nodepos) {
int res = 1 << (32 - detail - z);
long long area = 1LL << (32 - z);
int res = 1 << (GLOBAL_DETAIL - detail - z);
long long area = 1LL << (GLOBAL_DETAIL - z);
for (size_t i = 0; i < geom.size(); i++) {
if (geom[i].op == VT_MOVETO) {
@@ -491,13 +491,13 @@ drawvec simplify_lines(drawvec &geom, int z, int tx, int ty, int detail, bool ma
// offset to global
draw d = geom[i];
if (z != 0) {
d.x += tx * (1LL << (32 - z));
d.y += ty * (1LL << (32 - z));
d.x += tx * (1LL << (GLOBAL_DETAIL - z));
d.y += ty * (1LL << (GLOBAL_DETAIL - z));
}
// to quadkey
struct node n;
n.index = encode_quadkey((unsigned) d.x, (unsigned) d.y);
n.index = encode_quadkey(coordinate_to_encodable(d.x), coordinate_to_encodable(d.y));
if (bsearch(&n, shared_nodes_map, nodepos / sizeof(node), sizeof(node), nodecmp) != NULL) {
geom[i].necessary = true;
@@ -578,8 +578,8 @@ drawvec reorder_lines(const drawvec &geom) {
// instead of down and to the right
// so that it will coalesce better
unsigned long long l1 = encode_index(geom[0].x, geom[0].y);
unsigned long long l2 = encode_index(geom[geom.size() - 1].x, geom[geom.size() - 1].y);
index_t l1 = encode_index(coordinate_to_encodable(geom[0].x), coordinate_to_encodable(geom[0].y));
index_t l2 = encode_index(coordinate_to_encodable(geom[geom.size() - 1].x), coordinate_to_encodable(geom[geom.size() - 1].y));
if (l1 > l2) {
drawvec out;
@@ -671,9 +671,9 @@ drawvec fix_polygon(const drawvec &geom) {
// calculate centroid
// a + 1 < size() because point 0 is duplicated at the end
long long xtotal = 0;
long long ytotal = 0;
long long count = 0;
__int128 xtotal = 0;
__int128 ytotal = 0;
size_t count = 0;
for (size_t a = 0; a + 1 < ring.size(); a++) {
xtotal += ring[a].x;
ytotal += ring[a].y;
@@ -683,13 +683,13 @@ drawvec fix_polygon(const drawvec &geom) {
ytotal /= count;
// figure out which point is furthest from the centroid
long long dist2 = 0;
long long furthest = 0;
__int128 dist2 = 0;
size_t furthest = 0;
for (size_t a = 0; a + 1 < ring.size(); a++) {
// division by 16 because these are z0 coordinates and we need to avoid overflow
long long xd = (ring[a].x - xtotal) / 16;
long long yd = (ring[a].y - ytotal) / 16;
long long d2 = xd * xd + yd * yd;
__int128 xd = (ring[a].x - xtotal) / 16;
__int128 yd = (ring[a].y - ytotal) / 16;
__int128 d2 = xd * xd + yd * yd;
if (d2 > dist2 || (d2 == dist2 && ring[a] < ring[furthest])) {
dist2 = d2;
furthest = a;
@@ -699,13 +699,13 @@ drawvec fix_polygon(const drawvec &geom) {
// then figure out which point is furthest from *that*,
// which will hopefully be a good origin point since it should be
// at a far edge of the shape.
long long dist2b = 0;
long long furthestb = 0;
__int128 dist2b = 0;
size_t furthestb = 0;
for (size_t a = 0; a + 1 < ring.size(); a++) {
// division by 16 because these are z0 coordinates and we need to avoid overflow
long long xd = (ring[a].x - ring[furthest].x) / 16;
long long yd = (ring[a].y - ring[furthest].y) / 16;
long long d2 = xd * xd + yd * yd;
__int128 xd = (ring[a].x - ring[furthest].x) / 16;
__int128 yd = (ring[a].y - ring[furthest].y) / 16;
__int128 d2 = xd * xd + yd * yd;
if (d2 > dist2b || (d2 == dist2b && ring[a] < ring[furthestb])) {
dist2b = d2;
furthestb = a;
@@ -823,7 +823,7 @@ std::vector<drawvec> chop_polygon(std::vector<drawvec> &geoms) {
drawvec stairstep(drawvec &geom, int z, int detail) {
drawvec out;
double scale = 1 << (32 - detail - z);
double scale = 1 << (GLOBAL_DETAIL - detail - z);
for (size_t i = 0; i < geom.size(); i++) {
geom[i].x = std::round(geom[i].x / scale);
@@ -900,8 +900,8 @@ drawvec stairstep(drawvec &geom, int z, int detail) {
}
for (size_t i = 0; i < out.size(); i++) {
out[i].x *= 1 << (32 - detail - z);
out[i].y *= 1 << (32 - detail - z);
out[i].x *= 1LL << (GLOBAL_DETAIL - detail - z);
out[i].y *= 1LL << (GLOBAL_DETAIL - detail - z);
}
return out;
@@ -1277,7 +1277,7 @@ drawvec polygon_to_anchor(const drawvec &geom) {
if (goodness <= 0) {
double lon, lat;
tile2lonlat(d.x, d.y, 32, &lon, &lat);
tile2lonlat(d.x, d.y, GLOBAL_DETAIL, &lon, &lat);
static std::atomic<long long> warned(0);
if (warned++ < 10) {
@@ -1299,19 +1299,22 @@ drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigne
drawvec out;
// anchor point in world coordinates
unsigned wx, wy;
unsigned long long wx, wy;
decode_index(label_point, &wx, &wy);
long long wwx = decoded_to_coordinate(wx);
long long wwy = decoded_to_coordinate(wy);
// upper left of tile in world coordinates
long long tx1 = 0, ty1 = 0;
// lower right of tile in world coordinates;
long long tx2 = 1LL << 32; // , ty2 = 1LL << 32;
long long tx2 = 1LL << GLOBAL_DETAIL; // , ty2 = 1LL << GLOBAL_DETAIL;
if (z != 0) {
tx1 = (long long) tx << (32 - z);
ty1 = (long long) ty << (32 - z);
tx1 = (long long) tx << (GLOBAL_DETAIL - z);
ty1 = (long long) ty << (GLOBAL_DETAIL - z);
tx2 = (long long) (tx + 1) << (32 - z);
// ty2 = (long long) (ty + 1) << (32 - z);
tx2 = (long long) (tx + 1) << (GLOBAL_DETAIL - z);
// ty2 = (long long) (ty + 1) << (GLOBAL_DETAIL - z);
}
// upper left of feature in world coordinates
@@ -1340,16 +1343,16 @@ drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigne
const long long label_spacing = spiral_dist * (tx2 - tx1);
long long x1 = floor(std::min(bx1 - wx, bx2 - wx) / label_spacing);
long long x2 = ceil(std::max(bx1 - wx, bx2 - wx) / label_spacing);
long long x1 = floor(std::min(bx1 - wwx, bx2 - wwx) / label_spacing);
long long x2 = ceil(std::max(bx1 - wwx, bx2 - wwx) / label_spacing);
long long y1 = floor(std::min(by1 - wy, by2 - wy) / label_spacing - 0.5);
long long y2 = ceil(std::max(by1 - wy, by2 - wy) / label_spacing);
long long y1 = floor(std::min(by1 - wwy, by2 - wwy) / label_spacing - 0.5);
long long y2 = ceil(std::max(by1 - wwy, by2 - wwy) / label_spacing);
for (long long lx = x1; lx <= x2; lx++) {
for (long long ly = y1; ly <= y2; ly++) {
long long x = lx * label_spacing + wx;
long long y = ly * label_spacing + wy;
long long x = lx * label_spacing + wwx;
long long y = ly * label_spacing + wwy;
if (((unsigned long long) lx & 1) == 1) {
y += label_spacing / 2;
@@ -1366,7 +1369,7 @@ drawvec checkerboard_anchors(drawvec const &geom, int tx, int ty, int z, unsigne
out.push_back(draw(VT_MOVETO, x - tx1, y - ty1));
break;
} else {
double tilesize = 1LL << (32 - z);
double tilesize = 1LL << (GLOBAL_DETAIL - z);
double goodness_threshold = tilesize / 100;
if (label_goodness(geom, x - tx1, y - ty1) > goodness_threshold) {
out.push_back(draw(VT_MOVETO, x - tx1, y - ty1));
+4 -3
View File
@@ -10,6 +10,7 @@
#include <mvt.hpp>
#include "jsonpull/jsonpull.h"
#include "attribute.hpp"
#include "projection.hpp"
#define VT_POINT 1
#define VT_LINE 2
@@ -24,9 +25,9 @@
// at the cost, apparently, of a 0.7% increase in running time
// for packing and unpacking.
struct draw {
long long x : 40;
long long x : GLOBAL_DETAIL + 3;
signed char op;
long long y : 40;
long long y : GLOBAL_DETAIL + 3;
signed char necessary;
draw(int nop, long long nx, long long ny)
@@ -67,7 +68,7 @@ struct draw {
typedef std::vector<draw> drawvec;
struct serial_feature;
drawvec decode_geometry(const char **meta, int z, unsigned tx, unsigned ty, long long *bbox, unsigned initial_x, unsigned initial_y);
drawvec decode_geometry(const char **meta, int z, long long tx, long long ty, long long *bbox, long long initial_x, long long initial_y);
void to_tile_scale(drawvec &geom, int z, int detail);
drawvec from_tile_scale(drawvec const &geom, int z, int detail);
drawvec remove_noop(drawvec geom, int type, int shift);
+69 -60
View File
@@ -283,13 +283,13 @@ static void insert(struct mergelist *m, struct mergelist **head, unsigned char *
struct drop_state {
double gap;
unsigned long long previndex;
index_t previndex;
double interval;
double seq; // floating point because interval is
};
struct drop_densest {
unsigned long long gap;
index_t gap;
size_t seq;
bool operator<(const drop_densest &o) const {
@@ -333,7 +333,7 @@ int calc_feature_minzoom(struct index *ix, struct drop_state *ds, int maxzoom, d
if (preserve_point_density_threshold > 0) {
for (ssize_t i = 0; i < feature_minzoom && i < maxzoom; i++) {
if (ix->ix - ds[i].previndex > ((1LL << (32 - i)) / preserve_point_density_threshold) * ((1LL << (32 - i)) / preserve_point_density_threshold)) {
if (ix->ix - ds[i].previndex > ((1LL << (GLOBAL_DETAIL - i)) / preserve_point_density_threshold) * ((1LL << (GLOBAL_DETAIL - i)) / preserve_point_density_threshold)) {
feature_minzoom = i;
for (ssize_t j = i; j <= maxzoom; j++) {
@@ -450,7 +450,7 @@ void *run_sort(void *v) {
return NULL;
}
void do_read_parallel(char *map, long long len, long long initial_offset, const char *reading, std::vector<struct reader> *readers, std::atomic<long long> *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int source, std::vector<std::map<std::string, layermap_entry> > *layermaps, int *initialized, unsigned *initial_x, unsigned *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::unordered_map<std::string, int> const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) {
void do_read_parallel(char *map, long long len, long long initial_offset, const char *reading, std::vector<struct reader> *readers, std::atomic<long long> *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int source, std::vector<std::map<std::string, layermap_entry> > *layermaps, int *initialized, long long *initial_x, long long *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::unordered_map<std::string, int> const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) {
long long segs[CPUS + 1];
segs[0] = 0;
segs[CPUS] = len;
@@ -647,8 +647,8 @@ struct read_parallel_arg {
int source = 0;
std::vector<std::map<std::string, layermap_entry> > *layermaps = NULL;
int *initialized = NULL;
unsigned *initial_x = NULL;
unsigned *initial_y = NULL;
long long *initial_x = NULL;
long long *initial_y = NULL;
std::string layername = "";
bool uses_gamma = false;
std::unordered_map<std::string, int> const *attribute_types = NULL;
@@ -695,7 +695,7 @@ void *run_read_parallel(void *v) {
return NULL;
}
void start_parsing(int fd, STREAM *fp, long long offset, long long len, std::atomic<int> *is_parsing, pthread_t *parallel_parser, bool &parser_created, const char *reading, std::vector<struct reader> *readers, std::atomic<long long> *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int source, std::vector<std::map<std::string, layermap_entry> > &layermaps, int *initialized, unsigned *initial_x, unsigned *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::unordered_map<std::string, int> const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) {
void start_parsing(int fd, STREAM *fp, long long offset, long long len, std::atomic<int> *is_parsing, pthread_t *parallel_parser, bool &parser_created, const char *reading, std::vector<struct reader> *readers, std::atomic<long long> *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, int basezoom, int source, std::vector<std::map<std::string, layermap_entry> > &layermaps, int *initialized, long long *initial_x, long long *initial_y, int maxzoom, std::string layername, bool uses_gamma, std::unordered_map<std::string, int> const *attribute_types, int separator, double *dist_sum, size_t *dist_count, double *area_sum, bool want_dist, bool filters) {
// This has to kick off an intermediate thread to start the parser threads,
// so the main thread can get back to reading the next input stage while
// the intermediate thread waits for the completion of the parser threads.
@@ -822,9 +822,20 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
for (size_t a = 0; a < indexst.st_size / sizeof(struct index); a++) {
struct index ix = indexmap[a];
unsigned long long which = (ix.ix << prefix) >> (64 - splitbits);
long long pos = sub_geompos[which];
// I think what is going on here is that `prefix` represents the top bits
// of the index, which we have already sorted on, so we are shifting up
// to mask off those bits (which previously fell off the top of the word)
// and then shifting back down to bring the top `splitbits` of what remains
// down to be the new partitions.
index_t ixmask = (((__int128_t) 1) << (2 * GLOBAL_DETAIL)) - 1;
index_t which = ((ix.ix << prefix) & ixmask) >> (2 * GLOBAL_DETAIL - splitbits);
if ((int) which >= splits) {
fprintf(stderr, "splits off the edge! segment %d of %d\n", (int) which, splits);
exit(EXIT_IMPOSSIBLE);
}
long long pos = sub_geompos[which];
fwrite_check(geommap + ix.start, ix.end - ix.start, 1, geomfiles[which], &sub_geompos[which], "geom");
// Count this as a 25%-accomplishment, since we will copy again
@@ -897,18 +908,13 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
std::atomic<long long> indexpos(indexst.st_size);
int bytes = sizeof(struct index);
int page = sysconf(_SC_PAGESIZE);
// Don't try to sort more than 2GB at once,
// which used to crash Macs and may still
long long max_unit = 2LL * 1024 * 1024 * 1024;
long long max_unit = ((2LL * 1024 * 1024 * 1024) / bytes) * bytes;
long long unit = ((indexpos / CPUS + bytes - 1) / bytes) * bytes;
if (unit > max_unit) {
unit = max_unit;
}
unit = ((unit + page - 1) / page) * page;
if (unit < page) {
unit = page;
}
size_t nmerges = (indexpos + unit - 1) / unit;
struct mergelist merges[nmerges];
@@ -975,7 +981,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
perror("unmap geom");
exit(EXIT_MEMORY);
}
} else if (indexst.st_size == sizeof(struct index) || prefix + splitbits >= 64) {
} else if (indexst.st_size == sizeof(struct index) || prefix + splitbits >= 2 * GLOBAL_DETAIL) {
struct index *indexmap = (struct index *) mmap(NULL, indexst.st_size, PROT_READ, MAP_PRIVATE, indexfds[i], 0);
if (indexmap == MAP_FAILED) {
fprintf(stderr, "fd %lld, len %lld\n", (long long) indexfds[i], (long long) indexst.st_size);
@@ -1181,21 +1187,21 @@ void choose_first_zoom(long long *file_bbox, long long *file_bbox1, long long *f
// bounding box is the whole world.
if (file_bbox[0] < 0) {
file_bbox[0] = 0;
file_bbox[2] = (1LL << 32) - 1;
file_bbox[2] = (1LL << GLOBAL_DETAIL) - 1;
}
if (file_bbox[2] > (1LL << 32) - 1) {
if (file_bbox[2] > (1LL << GLOBAL_DETAIL) - 1) {
file_bbox[0] = 0;
file_bbox[2] = (1LL << 32) - 1;
file_bbox[2] = (1LL << GLOBAL_DETAIL) - 1;
}
if (file_bbox[1] < 0) {
file_bbox[1] = 0;
}
if (file_bbox[3] > (1LL << 32) - 1) {
file_bbox[3] = (1LL << 32) - 1;
if (file_bbox[3] > (1LL << GLOBAL_DETAIL) - 1) {
file_bbox[3] = (1LL << GLOBAL_DETAIL) - 1;
}
for (ssize_t z = minzoom; z >= 0; z--) {
long long shift = 1LL << (32 - z);
long long shift = 1LL << (GLOBAL_DETAIL - z);
long long left = (file_bbox[0] - buffer * shift / 256) / shift;
long long top = (file_bbox[1] - buffer * shift / 256) / shift;
@@ -1341,7 +1347,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
memfile_write(r->treefile, &p, sizeof(struct stringpool), in_memory);
}
r->file_bbox[0] = r->file_bbox[1] = UINT_MAX;
r->file_bbox[0] = r->file_bbox[1] = (1LL << GLOBAL_DETAIL) - 1;
r->file_bbox[2] = r->file_bbox[3] = 0;
}
@@ -1358,7 +1364,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
// 2 * CPUS: One per reader thread, one per tiling thread
int initialized[2 * CPUS];
unsigned initial_x[2 * CPUS], initial_y[2 * CPUS];
long long initial_x[2 * CPUS], initial_y[2 * CPUS];
for (size_t i = 0; i < 2 * CPUS; i++) {
initialized[i] = initial_x[i] = initial_y[i] = 0;
}
@@ -2064,12 +2070,12 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
#if 0
double lon, lat;
tile2lonlat(x, y, 32, &lon, &lat);
tile2lonlat(x, y, GLOBAL_DETAIL, &lon, &lat);
printf("{\"type\":\"Feature\", \"properties\":{}, \"geometry\":{\"type\":\"Point\", \"coordinates\":[%f,%f]}}\n", lon, lat);
#endif
struct node n;
n.index = encode_quadkey((unsigned) x, (unsigned) y);
n.index = encode_quadkey(coordinate_to_encodable(x), coordinate_to_encodable(y));
fwrite_check((char *) &n, sizeof(struct node), 1, readers[0].nodefile, &readers[0].nodepos, "vertices");
}
@@ -2152,7 +2158,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
unsigned wx, wy;
decode_quadkey(here.index, &wx, &wy);
double lon, lat;
tile2lonlat(wx, wy, 32, &lon, &lat);
tile2lonlat(decoded_to_coordinate(wx), decoded_to_coordinate(wy), GLOBAL_DETAIL, &lon, &lat);
printf("{\"type\":\"Feature\", \"properties\":{}, \"geometry\":{\"type\":\"Point\", \"coordinates\":[%f,%f]}}\n", lon, lat);
#endif
}
@@ -2357,11 +2363,11 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
if (maxzoom < 0) {
maxzoom = 0;
}
if (maxzoom > 32 - full_detail) {
maxzoom = 32 - full_detail;
if (maxzoom > GLOBAL_DETAIL - full_detail) {
maxzoom = GLOBAL_DETAIL - full_detail;
}
if (maxzoom > 33 - low_detail) { // that is, maxzoom - 1 > 32 - low_detail
maxzoom = 33 - low_detail;
if (maxzoom - 1 > GLOBAL_DETAIL - low_detail) {
maxzoom = GLOBAL_DETAIL + 1 - low_detail;
}
if (!quiet) {
@@ -2374,8 +2380,8 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
}
bool changed = false;
while (maxzoom < 32 - full_detail && maxzoom < 33 - low_detail && maxzoom < cluster_maxzoom && cluster_distance > 0) {
unsigned long long zoom_mingap = ((1LL << (32 - maxzoom)) / 256 * cluster_distance) * ((1LL << (32 - maxzoom)) / 256 * cluster_distance);
while (maxzoom < GLOBAL_DETAIL - full_detail && maxzoom < GLOBAL_DETAIL + 1 - low_detail && maxzoom < cluster_maxzoom && cluster_distance > 0) {
index_t zoom_mingap = ((1LL << (GLOBAL_DETAIL - maxzoom)) / 256 * cluster_distance) * ((1LL << (GLOBAL_DETAIL - maxzoom)) / 256 * cluster_distance);
if (avg > zoom_mingap) {
break;
}
@@ -2414,11 +2420,11 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
if (mz < 0) {
mz = 0;
}
if (mz > 32 - full_detail) {
mz = 32 - full_detail;
if (mz > GLOBAL_DETAIL - full_detail) {
mz = GLOBAL_DETAIL - full_detail;
}
if (mz > 33 - low_detail) { // that is, mz - 1 > 32 - low_detail
mz = 33 - low_detail;
if (mz - 1 > GLOBAL_DETAIL - low_detail) {
mz = GLOBAL_DETAIL + 1 - low_detail;
}
if (mz > maxzoom || count <= 0) {
@@ -2431,7 +2437,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
double total_tile_count = 0;
for (int i = 1; i <= maxzoom; i++) {
double tile_count = ceil(area_sum / ((1LL << (32 - i)) * (1LL << (32 - i))));
double tile_count = ceil(area_sum / ((__int128) (1LL << (GLOBAL_DETAIL - i)) * (__int128) (1LL << (GLOBAL_DETAIL - i))));
total_tile_count += tile_count;
// 2M tiles is an arbitrary limit, chosen to make tiling jobs
@@ -2487,7 +2493,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
long long count;
long long fullcount;
double gap;
unsigned long long previndex;
index_t previndex;
} tile[MAX_ZOOM + 1], max[MAX_ZOOM + 1];
{
@@ -2502,9 +2508,12 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
long long ip;
for (ip = 0; ip < indices; ip++) {
unsigned xx, yy;
unsigned long long xx, yy;
decode_index(map[ip].ix, &xx, &yy);
long long gxx = decoded_to_coordinate(xx);
long long gyy = decoded_to_coordinate(yy);
long long nprogress = 100 * ip / indices;
if (nprogress != progress) {
progress = nprogress;
@@ -2520,8 +2529,8 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
if (z != 0) {
// These are tile numbers, not pixels,
// so shift, not round
xxx = xx >> (32 - z);
yyy = yy >> (32 - z);
xxx = gxx >> (GLOBAL_DETAIL - z);
yyy = gyy >> (GLOBAL_DETAIL - z);
}
double scale = (double) (1LL << (64 - 2 * (z + 8)));
@@ -2684,7 +2693,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
if (drop_denser > 0) {
std::vector<drop_densest> ddv;
unsigned long long previndex = 0;
index_t previndex = 0;
for (long long ip = 0; ip < indices; ip++) {
if (map[ip].t == VT_POINT ||
@@ -2794,8 +2803,8 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
midlat = (maxlat + minlat) / 2;
midlon = (maxlon + minlon) / 2;
tile2lonlat(file_bbox[0], file_bbox[1], 32, &minlon, &maxlat);
tile2lonlat(file_bbox[2], file_bbox[3], 32, &maxlon, &minlat);
tile2lonlat(file_bbox[0], file_bbox[1], GLOBAL_DETAIL, &minlon, &maxlat);
tile2lonlat(file_bbox[2], file_bbox[3], GLOBAL_DETAIL, &maxlon, &minlat);
if (midlat < minlat) {
midlat = minlat;
@@ -2814,11 +2823,11 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
double minlat2 = 0, minlon2 = 0, maxlat2 = 0, maxlon2 = 0;
// choose whichever of the two calculated bboxes is narrower
if (file_bbox2[2] - file_bbox2[0] < file_bbox1[2] - file_bbox1[0]) {
tile2lonlat(file_bbox2[0], file_bbox2[1], 32, &minlon2, &maxlat2);
tile2lonlat(file_bbox2[2], file_bbox2[3], 32, &maxlon2, &minlat2);
tile2lonlat(file_bbox2[0], file_bbox2[1], GLOBAL_DETAIL, &minlon2, &maxlat2);
tile2lonlat(file_bbox2[2], file_bbox2[3], GLOBAL_DETAIL, &maxlon2, &minlat2);
} else {
tile2lonlat(file_bbox1[0], file_bbox1[1], 32, &minlon2, &maxlat2);
tile2lonlat(file_bbox1[2], file_bbox1[3], 32, &maxlon2, &minlat2);
tile2lonlat(file_bbox1[0], file_bbox1[1], GLOBAL_DETAIL, &minlon2, &maxlat2);
tile2lonlat(file_bbox1[2], file_bbox1[3], GLOBAL_DETAIL, &maxlon2, &minlat2);
}
std::map<std::string, layermap_entry> merged_lm = merge_layermaps(layermaps);
@@ -3681,8 +3690,8 @@ int main(int argc, char **argv) {
// the same no matter what order the projection and bounding box are
// specified in
for (auto &c : clipbboxes) {
projection->project(c.lon1, c.lat1, 32, &c.minx, &c.maxy);
projection->project(c.lon2, c.lat2, 32, &c.maxx, &c.miny);
projection->project(c.lon1, c.lat1, GLOBAL_DETAIL, &c.minx, &c.maxy);
projection->project(c.lon2, c.lat2, GLOBAL_DETAIL, &c.maxx, &c.miny);
}
if (max_tilestats_sample_values < max_tilestats_values) {
@@ -3721,12 +3730,12 @@ int main(int argc, char **argv) {
// This previously dropped the maxzoom rather than the detail when they were in conflict,
// which proved to be annoying.
if (!guess_maxzoom) {
if (maxzoom > 32 - full_detail) {
full_detail = 32 - maxzoom;
if (maxzoom > GLOBAL_DETAIL - full_detail) {
full_detail = GLOBAL_DETAIL - maxzoom;
fprintf(stderr, "Highest supported detail with maxzoom %d is %d\n", maxzoom, full_detail);
}
if (maxzoom > 33 - low_detail) { // that is, maxzoom - 1 > 32 - low_detail
low_detail = 33 - maxzoom;
if (maxzoom - 1 > GLOBAL_DETAIL - low_detail) {
low_detail = GLOBAL_DETAIL + 1 - maxzoom;
fprintf(stderr, "Highest supported low detail with maxzoom %d is %d\n", maxzoom, low_detail);
}
}
@@ -3754,12 +3763,12 @@ int main(int argc, char **argv) {
if (extra_detail >= 0 || prevent[P_SIMPLIFY_SHARED_NODES] || additional[A_EXTEND_ZOOMS] || extend_zooms_max > 0) {
geometry_scale = 0;
} else {
geometry_scale = 32 - (full_detail + maxzoom);
geometry_scale = GLOBAL_DETAIL - (full_detail + maxzoom);
if (geometry_scale < 0) {
geometry_scale = 0;
if (!guess_maxzoom) {
// This shouldn't be able to happen any more. Can it still?
fprintf(stderr, "Full detail + maxzoom > 32, so you are asking for more detail than is available.\n");
fprintf(stderr, "Full detail + maxzoom > %d, so you are asking for more detail than is available.\n", GLOBAL_DETAIL);
}
}
}
@@ -3818,10 +3827,10 @@ int main(int argc, char **argv) {
}
}
long long file_bbox[4] = {UINT_MAX, UINT_MAX, 0, 0};
long long file_bbox[4] = {(1LL << GLOBAL_DETAIL) - 1, (1LL << GLOBAL_DETAIL) - 1, 0, 0};
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_bbox1[4] = {(1LL << GLOBAL_DETAIL) - 1, (1LL << GLOBAL_DETAIL) - 1, 0, 0}; // standard -180 to 180 world plane
long long file_bbox2[4] = {(2LL << GLOBAL_DETAIL) - 1, (1LL << GLOBAL_DETAIL) - 1, 1LL << GLOBAL_DETAIL, 0}; // 0 to 360 world plane
auto input_ret = read_input(sources, name ? name : out_mbtiles ? out_mbtiles
: out_dir,
+1 -1
View File
@@ -13,7 +13,7 @@
struct index {
long long start = 0;
long long end = 0;
unsigned long long ix = 0;
index_t ix = 0;
short segment = 0;
unsigned short t : 2;
unsigned long long seq : (64 - 18); // pack with segment and t to stay in 32 bytes
+4 -4
View File
@@ -198,7 +198,7 @@ std::vector<mvt_layer> parse_layers(int fd, int z, unsigned x, unsigned y, std::
// Scale and offset geometry from global to tile
for (size_t i = 0; i < dv.size(); i++) {
long long scale = 1LL << (32 - z);
long long scale = 1LL << (GLOBAL_DETAIL - z);
dv[i].x = std::round((dv[i].x - scale * x) * extent / (double) scale);
dv[i].y = std::round((dv[i].y - scale * y) * extent / (double) scale);
}
@@ -383,10 +383,10 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std::
// Scale and offset geometry from global to tile
double scale = 1LL << geometry_scale;
for (size_t i = 0; i < dv.size(); i++) {
unsigned sx = 0, sy = 0;
long long sx = 0, sy = 0;
if (z != 0) {
sx = x << (32 - z);
sy = y << (32 - z);
sx = (long long) x << (GLOBAL_DETAIL - z);
sy = (long long) y << (GLOBAL_DETAIL - z);
}
dv[i].x = std::round(dv[i].x / scale) * scale - sx;
dv[i].y = std::round(dv[i].y / scale) * scale - sy;
+47 -37
View File
@@ -7,8 +7,10 @@
#include "projection.hpp"
#include "errors.hpp"
unsigned long long (*encode_index)(unsigned int wx, unsigned int wy) = NULL;
void (*decode_index)(unsigned long long index, unsigned *wx, unsigned *wy) = NULL;
#define UINT_BITS 32
index_t (*encode_index)(unsigned long long wx, unsigned long long wy) = NULL;
void (*decode_index)(index_t index, unsigned long long *wx, unsigned long long *wy) = NULL;
struct projection projections[] = {
{"EPSG:4326", lonlat2tile, tile2lonlat, "urn:ogc:def:crs:OGC:1.3:CRS84"},
@@ -84,45 +86,45 @@ void epsg3857totile(double ix, double iy, int zoom, long long *x, long long *y)
ix = 40000000.0;
}
*x = std::round(ix * (1LL << 31) / 6378137.0 / M_PI + (1LL << 31));
*y = std::round(((1LL << 32) - 1) - (iy * (1LL << 31) / 6378137.0 / M_PI + (1LL << 31)));
*x = std::round(ix * (1LL << (GLOBAL_DETAIL - 1)) / 6378137.0 / M_PI + (1LL << (GLOBAL_DETAIL - 1)));
*y = std::round(((1LL << GLOBAL_DETAIL) - 1) - (iy * (1LL << (GLOBAL_DETAIL - 1)) / 6378137.0 / M_PI + (1LL << (GLOBAL_DETAIL - 1))));
if (zoom != 0) {
*x = std::round((double) *x / (1LL << (32 - zoom)));
*y = std::round((double) *y / (1LL << (32 - zoom)));
*x = std::round((double) *x / (1LL << (GLOBAL_DETAIL - zoom)));
*y = std::round((double) *y / (1LL << (GLOBAL_DETAIL - zoom)));
}
}
void tiletoepsg3857(long long ix, long long iy, int zoom, double *ox, double *oy) {
if (zoom != 0) {
ix <<= (32 - zoom);
iy <<= (32 - zoom);
ix <<= (GLOBAL_DETAIL - zoom);
iy <<= (GLOBAL_DETAIL - zoom);
}
*ox = (ix - (1LL << 31)) * M_PI * 6378137.0 / (1LL << 31);
*oy = ((1LL << 32) - 1 - iy - (1LL << 31)) * M_PI * 6378137.0 / (1LL << 31);
*ox = (ix - (1LL << (GLOBAL_DETAIL - 1))) * M_PI * 6378137.0 / (1LL << (GLOBAL_DETAIL - 1));
*oy = ((1LL << GLOBAL_DETAIL) - 1 - iy - (1LL << (GLOBAL_DETAIL - 1))) * M_PI * 6378137.0 / (1LL << (GLOBAL_DETAIL - 1));
}
// https://en.wikipedia.org/wiki/Hilbert_curve
void hilbert_rot(unsigned long long n, unsigned *x, unsigned *y, unsigned long long rx, unsigned long long ry) {
static void hilbert_rot(index_t n, unsigned long long *x, unsigned long long *y, index_t rx, index_t ry) {
if (ry == 0) {
if (rx == 1) {
*x = n - 1 - *x;
*y = n - 1 - *y;
}
unsigned t = *x;
unsigned long long t = *x;
*x = *y;
*y = t;
}
}
unsigned long long hilbert_xy2d(unsigned long long n, unsigned x, unsigned y) {
unsigned long long d = 0;
unsigned long long rx, ry;
static index_t hilbert_xy2d(index_t n, unsigned long long x, unsigned long long y) {
index_t d = 0;
index_t rx, ry;
for (unsigned long long s = n / 2; s > 0; s /= 2) {
for (index_t s = n / 2; s > 0; s /= 2) {
rx = (x & s) != 0;
ry = (y & s) != 0;
@@ -133,12 +135,12 @@ unsigned long long hilbert_xy2d(unsigned long long n, unsigned x, unsigned y) {
return d;
}
void hilbert_d2xy(unsigned long long n, unsigned long long d, unsigned *x, unsigned *y) {
unsigned long long rx, ry;
unsigned long long t = d;
static void hilbert_d2xy(index_t n, index_t d, unsigned long long *x, unsigned long long *y) {
index_t rx, ry;
index_t t = d;
*x = *y = 0;
for (unsigned long long s = 1; s < n; s *= 2) {
for (index_t s = 1; s < n; s *= 2) {
rx = 1 & (t / 2);
ry = 1 & (t ^ rx);
hilbert_rot(s, x, y, rx, ry);
@@ -148,22 +150,22 @@ void hilbert_d2xy(unsigned long long n, unsigned long long d, unsigned *x, unsig
}
}
unsigned long long encode_hilbert(unsigned int wx, unsigned int wy) {
return hilbert_xy2d(1LL << 32, wx, wy);
index_t encode_hilbert(unsigned long long wx, unsigned long long wy) {
return hilbert_xy2d((index_t) 1 << 64, wx, wy);
}
void decode_hilbert(unsigned long long index, unsigned *wx, unsigned *wy) {
hilbert_d2xy(1LL << 32, index, wx, wy);
void decode_hilbert(index_t index, unsigned long long *wx, unsigned long long *wy) {
hilbert_d2xy((index_t) 1 << 64, index, wx, wy);
}
unsigned long long encode_quadkey(unsigned int wx, unsigned int wy) {
unsigned long long out = 0;
index_t encode_quadkey(unsigned long long wx, unsigned long long wy) {
index_t out = 0;
int i;
for (i = 0; i < 32; i++) {
unsigned long long v = ((wx >> (32 - (i + 1))) & 1) << 1;
v |= (wy >> (32 - (i + 1))) & 1;
v = v << (64 - 2 * (i + 1));
for (i = 0; i < 64; i++) {
index_t v = ((wx >> (64 - (i + 1))) & 1) << 1;
v |= (wy >> (64 - (i + 1))) & 1;
v = v << (128 - 2 * (i + 1));
out |= v;
}
@@ -174,15 +176,15 @@ unsigned long long encode_quadkey(unsigned int wx, unsigned int wy) {
static std::atomic<unsigned char> decodex[256];
static std::atomic<unsigned char> decodey[256];
void decode_quadkey(unsigned long long index, unsigned *wx, unsigned *wy) {
void decode_quadkey(index_t index, unsigned long long *wx, unsigned long long *wy) {
static std::atomic<int> initialized(0);
if (!initialized) {
for (size_t ix = 0; ix < 256; ix++) {
size_t xx = 0, yy = 0;
for (size_t i = 0; i < 32; i++) {
xx |= ((ix >> (64 - 2 * (i + 1) + 1)) & 1) << (32 - (i + 1));
yy |= ((ix >> (64 - 2 * (i + 1) + 0)) & 1) << (32 - (i + 1));
for (size_t i = 0; i < UINT_BITS; i++) {
xx |= ((ix >> (64 - 2 * (i + 1) + 1)) & 1) << (UINT_BITS - (i + 1));
yy |= ((ix >> (64 - 2 * (i + 1) + 0)) & 1) << (UINT_BITS - (i + 1));
}
decodex[ix] = xx;
@@ -194,12 +196,20 @@ void decode_quadkey(unsigned long long index, unsigned *wx, unsigned *wy) {
*wx = *wy = 0;
for (size_t i = 0; i < 8; i++) {
*wx |= ((unsigned) decodex[(index >> (8 * i)) & 0xFF]) << (4 * i);
*wy |= ((unsigned) decodey[(index >> (8 * i)) & 0xFF]) << (4 * i);
for (size_t i = 0; i < 16; i++) {
*wx |= ((index_t) decodex[(index >> (8 * i)) & 0xFF]) << (4 * i);
*wy |= ((index_t) decodey[(index >> (8 * i)) & 0xFF]) << (4 * i);
}
}
unsigned coordinate_to_encodable(long long coord) {
return (unsigned) (coord / (1LL << (GLOBAL_DETAIL - UINT_BITS)));
}
long long decoded_to_coordinate(unsigned coord) {
return ((long long) coord) * (1LL << (GLOBAL_DETAIL - UINT_BITS));
}
void set_projection_or_exit(const char *optarg) {
struct projection *p;
for (p = projections; p->name != NULL; p++) {
+12 -6
View File
@@ -1,6 +1,9 @@
#ifndef PROJECTION_HPP
#define PROJECTION_HPP
#define GLOBAL_DETAIL 32
typedef __uint128_t index_t;
void lonlat2tile(double lon, double lat, int zoom, long long *x, long long *y);
void epsg3857totile(double ix, double iy, int zoom, long long *x, long long *y);
void tile2lonlat(long long x, long long y, int zoom, double *lon, double *lat);
@@ -17,13 +20,16 @@ struct projection {
extern struct projection *projection;
extern struct projection projections[];
extern unsigned long long (*encode_index)(unsigned int wx, unsigned int wy);
extern void (*decode_index)(unsigned long long index, unsigned *wx, unsigned *wy);
extern index_t (*encode_index)(unsigned long long wx, unsigned long long wy);
extern void (*decode_index)(index_t index, unsigned long long *wx, unsigned long long *wy);
unsigned long long encode_quadkey(unsigned int wx, unsigned int wy);
void decode_quadkey(unsigned long long index, unsigned *wx, unsigned *wy);
index_t encode_quadkey(unsigned long long wx, unsigned long long wy);
void decode_quadkey(index_t index, unsigned long long *wx, unsigned long long *wy);
unsigned long long encode_hilbert(unsigned int wx, unsigned int wy);
void decode_hilbert(unsigned long long index, unsigned *wx, unsigned *wy);
index_t encode_hilbert(unsigned long long wx, unsigned long long wy);
void decode_hilbert(index_t index, unsigned long long *wx, unsigned long long *wy);
unsigned coordinate_to_encodable(long long coord);
long long decoded_to_coordinate(unsigned coord);
#endif
+1 -1
View File
@@ -79,7 +79,7 @@ void parse_geometry(int t, json_object *j, drawvec &out, int op, const char *fna
long long x, y;
double lon = j->value.array.array[0]->value.number.number;
double lat = j->value.array.array[1]->value.number.number;
projection->project(lon, lat, 32, &x, &y);
projection->project(lon, lat, GLOBAL_DETAIL, &x, &y);
if (j->value.array.length > 2) {
static int warned = 0;
+64 -35
View File
@@ -25,7 +25,7 @@
#include "errors.hpp"
// Offset coordinates to keep them positive
#define COORD_OFFSET (4LL << 32)
#define COORD_OFFSET (4LL << GLOBAL_DETAIL)
#define SHIFT_RIGHT(a) ((long long) std::round((double) (a) / (1LL << geometry_scale)))
#define SHIFT_LEFT(a) ((((a) + (COORD_OFFSET >> geometry_scale)) << geometry_scale) - COORD_OFFSET)
@@ -92,6 +92,11 @@ void serialize_ulong_long(std::string &out, unsigned long long zigzag) {
out.append(buf, s - buf);
}
void serialize_index(std::string &out, index_t zigzag) {
serialize_ulong_long(out, zigzag);
serialize_ulong_long(out, ((__uint128_t) zigzag) >> 64);
}
void serialize_long_long(std::string &out, long long n) {
unsigned long long zigzag = protozero::encode_zigzag64(n);
@@ -142,6 +147,16 @@ void deserialize_ulong_long(const char **f, unsigned long long *zigzag) {
}
}
void deserialize_index(const char **f, index_t *zigzag) {
unsigned long long bottom;
unsigned long long top;
deserialize_ulong_long(f, &bottom);
deserialize_ulong_long(f, &top);
*zigzag = (((__uint128_t) top) << 64) | bottom;
}
void deserialize_uint(const char **f, unsigned *n) {
unsigned long long v;
deserialize_ulong_long(f, &v);
@@ -172,6 +187,8 @@ static void write_geometry(drawvec const &dv, std::string &out, long long wx, lo
std::string serialize_feature(serial_feature *sf, long long wx, long long wy) {
std::string s;
// index comes first so the sort can find it easily
serialize_index(s, sf->index);
serialize_byte(s, sf->t);
#define FLAG_LAYER 7
@@ -208,11 +225,8 @@ std::string serialize_feature(serial_feature *sf, long long wx, long long wy) {
write_geometry(sf->geometry, s, wx, wy);
if (sf->index != 0) {
serialize_ulong_long(s, sf->index);
}
if (sf->label_point != 0) {
serialize_ulong_long(s, sf->label_point);
serialize_index(s, sf->label_point);
}
if (sf->extent != 0) {
serialize_long_long(s, sf->extent);
@@ -230,10 +244,13 @@ std::string serialize_feature(serial_feature *sf, long long wx, long long wy) {
return s;
}
serial_feature deserialize_feature(std::string const &geoms, unsigned z, unsigned tx, unsigned ty, unsigned *initial_x, unsigned *initial_y) {
serial_feature deserialize_feature(std::string const &geoms, unsigned z, unsigned tx, unsigned ty, long long *initial_x, long long *initial_y) {
serial_feature sf;
const char *cp = geoms.c_str();
// index comes first so the sort can find it easily
deserialize_index(&cp, &sf.index);
deserialize_byte(&cp, &sf.t);
deserialize_long_long(&cp, &sf.layer);
@@ -257,17 +274,13 @@ serial_feature deserialize_feature(std::string const &geoms, unsigned z, unsigne
deserialize_int(&cp, &sf.segment);
sf.index = 0;
sf.label_point = 0;
sf.extent = 0;
sf.geometry = decode_geometry(&cp, z, tx, ty, sf.bbox, initial_x[sf.segment], initial_y[sf.segment]);
if (sf.layer & (1 << FLAG_INDEX)) {
deserialize_ulong_long(&cp, &sf.index);
}
if (sf.layer & (1 << FLAG_LABEL_POINT)) {
deserialize_ulong_long(&cp, &sf.label_point);
deserialize_index(&cp, &sf.label_point);
}
if (sf.layer & (1 << FLAG_EXTENT)) {
deserialize_long_long(&cp, &sf.extent);
@@ -315,12 +328,12 @@ static long long scale_geometry(struct serialization_state *sst, long long *bbox
// jumps at least 180° but not exactly 360°,
// which in some data sets is an intentional
// line across the world
if (x - prev > (1LL << 31) && x - prev != (1LL << 32)) {
offset -= 1LL << 32;
x -= 1LL << 32;
} else if (prev - x > (1LL << 31) && prev - x != (1LL << 32)) {
offset += 1LL << 32;
x += 1LL << 32;
if (x - prev > (1LL << (GLOBAL_DETAIL - 1)) && x - prev != (1LL << GLOBAL_DETAIL)) {
offset -= 1LL << GLOBAL_DETAIL;
x -= 1LL << GLOBAL_DETAIL;
} else if (prev - x > (1LL << (GLOBAL_DETAIL - 1)) && prev - x != (1LL << GLOBAL_DETAIL)) {
offset += 1LL << GLOBAL_DETAIL;
x += 1LL << GLOBAL_DETAIL;
}
}
@@ -345,11 +358,17 @@ static long long scale_geometry(struct serialization_state *sst, long long *bbox
bbox[3] = y;
}
// if the geometry offset is not yet initialized, initialize it
if (!*(sst->initialized)) {
if (x < 0 || x >= (1LL << 32) || y < 0 || y >= (1LL << 32)) {
*(sst->initial_x) = 1LL << 31;
*(sst->initial_y) = 1LL << 31;
if (x < 0 || x >= (1LL << GLOBAL_DETAIL) || y < 0 || y >= (1LL << GLOBAL_DETAIL)) {
// if the first point is off the edge of the world plane,
// use null island
*(sst->initial_x) = 1LL << (GLOBAL_DETAIL - 1);
*(sst->initial_y) = 1LL << (GLOBAL_DETAIL - 1);
} else {
// otherwise use the actual first point (rounded to the geometry_scale)
*(sst->initial_x) = SHIFT_LEFT(SHIFT_RIGHT(x));
*(sst->initial_y) = SHIFT_LEFT(SHIFT_RIGHT(y));
}
@@ -364,6 +383,15 @@ static long long scale_geometry(struct serialization_state *sst, long long *bbox
geom[i].x = std::round(x * scale);
geom[i].y = std::round(y * scale);
} else if (geometry_scale >= GLOBAL_DETAIL - 32) {
// this is silly, but rounding coordinates to what they would have been
// with a 32-bit world extent helps make test expectations not change
x = std::llround((double) x / (1LL << (GLOBAL_DETAIL - 32))) * (1LL << (GLOBAL_DETAIL - 32));
y = std::llround((double) y / (1LL << (GLOBAL_DETAIL - 32))) * (1LL << (GLOBAL_DETAIL - 32));
geom[i].x = SHIFT_RIGHT(x);
geom[i].y = SHIFT_RIGHT(y);
} else {
geom[i].x = SHIFT_RIGHT(x);
geom[i].y = SHIFT_RIGHT(y);
@@ -403,7 +431,7 @@ static void add_scaled_node(struct reader *r, serialization_state *sst, draw g)
long long y = SHIFT_LEFT(g.y);
struct node n;
n.index = encode_quadkey((unsigned) x, (unsigned) y);
n.index = encode_quadkey(coordinate_to_encodable(x), coordinate_to_encodable(y));
fwrite_check((char *) &n, sizeof(struct node), 1, r->nodefile, &r->nodepos, sst->fname);
}
@@ -419,11 +447,11 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
for (size_t i = 0; i < sf.geometry.size(); i++) {
if (sf.geometry[i].op == VT_MOVETO || sf.geometry[i].op == VT_LINETO) {
if (sf.geometry[i].y > 0 && sf.geometry[i].y < 0xFFFFFFFF) {
if (sf.geometry[i].y > 0 && sf.geometry[i].y < (1LL << GLOBAL_DETAIL) - 1) {
// standard -180 to 180 world plane
long long x = sf.geometry[i].x & 0xFFFFFFFF;
long long y = sf.geometry[i].y & 0xFFFFFFFF;
long long x = sf.geometry[i].x & ((1LL << GLOBAL_DETAIL) - 1);
long long y = sf.geometry[i].y & ((1LL << GLOBAL_DETAIL) - 1);
r->file_bbox1[0] = std::min(r->file_bbox1[0], x);
r->file_bbox1[1] = std::min(r->file_bbox1[1], y);
@@ -433,8 +461,8 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
// printf("%llx,%llx %llx,%llx %llx,%llx ", x, y, r->file_bbox1[0], r->file_bbox1[1], r->file_bbox1[2], r->file_bbox1[3]);
// shift the western hemisphere 360 degrees to the east
if (x < 0x80000000) { // prime meridian
x += 0x100000000;
if (x < 1LL << (GLOBAL_DETAIL - 1)) { // prime meridian
x += 1LL << GLOBAL_DETAIL;
}
r->file_bbox2[0] = std::min(r->file_bbox2[0], x);
@@ -667,13 +695,13 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
*(sst->area_sum) += extent;
}
unsigned long long bbox_index;
index_t bbox_index;
long long midx, midy;
if (sf.t == VT_POINT) {
// keep old behavior, which loses one bit of precision at the bottom
midx = (sf.bbox[0] / 2 + sf.bbox[2] / 2) & ((1LL << 32) - 1);
midy = (sf.bbox[1] / 2 + sf.bbox[3] / 2) & ((1LL << 32) - 1);
midx = (sf.bbox[0] / 2 + sf.bbox[2] / 2) & ((1LL << GLOBAL_DETAIL) - 1);
midy = (sf.bbox[1] / 2 + sf.bbox[3] / 2) & ((1LL << GLOBAL_DETAIL) - 1);
} else {
// To reduce the chances of giving multiple polygons or linestrings
// the same index, use an arbitrary but predictable point from the
@@ -694,18 +722,19 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf, std::
}
// If off the edge of the plane, mask to bring it back into the addressable area
midx = SHIFT_LEFT(scaled_geometry[ix].x) & ((1LL << 32) - 1);
midy = SHIFT_LEFT(scaled_geometry[ix].y) & ((1LL << 32) - 1);
midx = SHIFT_LEFT(scaled_geometry[ix].x) & ((1LL << GLOBAL_DETAIL) - 1);
midy = SHIFT_LEFT(scaled_geometry[ix].y) & ((1LL << GLOBAL_DETAIL) - 1);
}
bbox_index = encode_index(midx, midy);
bbox_index = encode_index(coordinate_to_encodable(midx), coordinate_to_encodable(midy));
if (sf.t == VT_POLYGON && additional[A_GENERATE_POLYGON_LABEL_POINTS]) {
drawvec dv = polygon_to_anchor(scaled_geometry);
if (dv.size() > 0) {
dv[0].x = SHIFT_LEFT(dv[0].x) & ((1LL << 32) - 1);
dv[0].y = SHIFT_LEFT(dv[0].y) & ((1LL << 32) - 1);
sf.label_point = encode_index(dv[0].x, dv[0].y);
dv[0].x = SHIFT_LEFT(dv[0].x) & ((1LL << GLOBAL_DETAIL) - 1);
dv[0].y = SHIFT_LEFT(dv[0].y) & ((1LL << GLOBAL_DETAIL) - 1);
// this could just be serialized as numbers instead of encoding and decoding
sf.label_point = encode_index(coordinate_to_encodable(dv[0].x), coordinate_to_encodable(dv[0].y));
}
}
+8 -7
View File
@@ -10,6 +10,7 @@
#include "geometry.hpp"
#include "mbtiles.hpp"
#include "jsonpull/jsonpull.h"
#include "projection.hpp"
size_t fwrite_check(const void *ptr, size_t size, size_t nitems, FILE *stream, std::atomic<long long> *fpos, const char *fname);
@@ -66,8 +67,8 @@ struct serial_feature {
int tippecanoe_maxzoom = -1;
drawvec geometry = drawvec();
unsigned long long index = 0;
unsigned long long label_point = 0;
index_t index = 0;
index_t label_point = 0;
long long extent = 0;
// These fields are not directly serialized, but are used
@@ -120,7 +121,7 @@ struct serial_feature {
};
std::string serialize_feature(serial_feature *sf, long long wx, long long wy);
serial_feature deserialize_feature(std::string const &geoms, unsigned z, unsigned tx, unsigned ty, unsigned *initial_x, unsigned *initial_y);
serial_feature deserialize_feature(std::string const &geoms, unsigned z, unsigned tx, unsigned ty, long long *initial_x, long long *initial_y);
struct reader {
int poolfd = -1;
@@ -143,8 +144,8 @@ struct reader {
std::atomic<long long> nodepos;
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_bbox2[4] = {0x1FFFFFFFF, 0xFFFFFFFF, 0x100000000, 0}; // 0 to 360 world plane
long long file_bbox1[4] = {(1LL << GLOBAL_DETAIL) - 1, (1LL << GLOBAL_DETAIL) - 1, 0, 0}; // standard -180 to 180 world plane
long long file_bbox2[4] = {(2LL << GLOBAL_DETAIL) - 1, (1LL << GLOBAL_DETAIL) - 1, 1LL << GLOBAL_DETAIL, 0}; // 0 to 360 world plane
struct stat geomst {};
char *geom_map = NULL;
@@ -201,8 +202,8 @@ struct serialization_state {
std::vector<struct reader> *readers = NULL; // array of data for each input thread
int segment = 0; // the current input thread
unsigned *initial_x = NULL; // relative offset of all geometries
unsigned *initial_y = NULL;
long long *initial_x = NULL; // relative offset of all geometries
long long *initial_y = NULL;
int *initialized = NULL;
double *dist_sum = NULL; // running tally for calculation of resolution within features
+1 -1
View File
@@ -367,7 +367,7 @@ bool find_common_edges(std::vector<serial_feature> &features, int z, int line_de
struct merge_order {
ssize_t edge = 0;
unsigned long long gap = 0;
index_t gap = 0;
size_t p1 = 0;
size_t p2 = 0;
+4
View File
@@ -4,6 +4,10 @@
#include <vector>
#include <string>
#include "projection.hpp"
#include "errors.hpp"
#include "serial.hpp"
#define MAX_MEMORY (1024 * 1024 * 1024) // 1 GB
void fqsort(std::vector<FILE *> &inputs, size_t width, int (*cmp)(const void *, const void *), FILE *out, size_t mem) {
+5 -3
View File
@@ -50,7 +50,9 @@ int pg = false;
int pe = false;
size_t CPUS;
int quiet = false;
int maxzoom = 32;
#define MAX_MAXZOOM 32
int maxzoom = MAX_MAXZOOM;
int minzoom = 0;
std::map<std::string, std::string> renames;
bool exclude_all = false;
@@ -474,7 +476,7 @@ struct tileset_reader {
if (overzoomed_tiles.size() == 0) {
// we have nothing to overzoom; give up
current_tile_is_overzoomed = false;
zoom = 32;
zoom = MAX_MAXZOOM;
return;
}
@@ -533,7 +535,7 @@ struct tileset_reader {
next_overzoom();
advance();
} else {
zoom = 32;
zoom = MAX_MAXZOOM;
}
} else {
if (zoom > maxzoom_so_far) {
+44 -43
View File
@@ -57,8 +57,6 @@ extern "C" {
#define CMD_BITS 3
// Offset coordinates to keep them positive
#define COORD_OFFSET (4LL << 32)
#define SHIFT_RIGHT(a) ((long long) std::round((double) (a) / (1LL << geometry_scale)))
#define XSTRINGIFY(s) STRINGIFY(s)
@@ -438,7 +436,7 @@ static std::vector<serial_feature> disassemble_multiplier_clusters(std::vector<s
}
// Write out copies of a feature into the temporary files for the next zoom level
static void rewrite(serial_feature const &osf, int z, int nextzoom, int maxzoom, unsigned tx, unsigned ty, int buffer, int within[], std::atomic<long long> *geompos, compressor *geomfile[], const char *fname, int child_shards, int max_zoom_increment, int segment, unsigned *initial_x, unsigned *initial_y) {
static void rewrite(serial_feature const &osf, int z, int nextzoom, int maxzoom, long long tx, long long ty, int buffer, int within[], std::atomic<long long> *geompos, compressor *geomfile[], const char *fname, int child_shards, int max_zoom_increment, int segment, long long *initial_x, long long *initial_y) {
if (osf.geometry.size() > 0 && (nextzoom <= maxzoom || additional[A_EXTEND_ZOOMS] || extend_zooms_max > 0)) {
int xo, yo;
int span = 1 << (nextzoom - z);
@@ -449,7 +447,7 @@ static void rewrite(serial_feature const &osf, int z, int nextzoom, int maxzoom,
int k;
for (k = 0; k < 4; k++) {
// Division instead of right-shift because coordinates can be negative
bbox2[k] = osf.bbox[k] / (1 << (32 - nextzoom - 8));
bbox2[k] = osf.bbox[k] / (1LL << (GLOBAL_DETAIL - nextzoom - 8));
}
// Decrement the top and left edges so that any features that are
// touching the edge can potentially be included in the adjacent tiles too.
@@ -470,10 +468,10 @@ static void rewrite(serial_feature const &osf, int z, int nextzoom, int maxzoom,
}
// Offset from tile coordinates back to world coordinates
unsigned sx = 0, sy = 0;
long long sx = 0, sy = 0;
if (z != 0) {
sx = tx << (32 - z);
sy = ty << (32 - z);
sx = tx << (GLOBAL_DETAIL - z);
sy = ty << (GLOBAL_DETAIL - z);
}
drawvec geom2;
@@ -543,7 +541,7 @@ struct simplification_worker_arg {
// so that the area of the feature is still somehow represented
static drawvec revive_polygon(drawvec &geom, double area, int z, int detail) {
// From area in world coordinates to area in tile coordinates
long long divisor = 1LL << (32 - detail - z);
long long divisor = 1LL << (GLOBAL_DETAIL - detail - z);
area /= divisor * divisor;
if (area == 0) {
@@ -613,7 +611,7 @@ static double simplify_feature(serial_feature *p, drawvec const &shared_nodes, n
// it would leave something else within the same tile pixel.
if (t == VT_LINE && !prevent[P_SIMPLIFY_SHARED_NODES]) {
// continues to deduplicate to line_detail even if we have extra detail
geom = remove_noop(geom, t, 32 - z - line_detail);
geom = remove_noop(geom, t, GLOBAL_DETAIL - z - line_detail);
}
bool already_marked = false;
@@ -707,7 +705,7 @@ static void *simplification_worker(void *v) {
// get rid of the --gamma option. It does something with the feature spacing to calculate
// whether each feature should be kept or is in a dense enough context that it should
// be dropped
int manage_gap(unsigned long long index, unsigned long long *previndex, double scale, double gamma, double *gap) {
int manage_gap(index_t index, index_t *previndex, double scale, double gamma, double *gap) {
if (gamma > 0) {
if (*gap > 0) {
if (index == *previndex) {
@@ -744,7 +742,7 @@ int manage_gap(unsigned long long index, unsigned long long *previndex, double s
// of features that survived the previous gap-choosing, so it first needs to calculate
// and sort the gaps between them before deciding which new gap threshold will satisfy
// the need to keep only the requested fraction of features.
static unsigned long long choose_mingap(std::vector<unsigned long long> const &indices, double f) {
static index_t choose_mingap(std::vector<unsigned long long> const &indices, double f) {
unsigned long long bot = ULLONG_MAX;
unsigned long long top = 0;
@@ -880,15 +878,15 @@ struct write_tile_args {
double simplification = 0;
std::atomic<long long> *most = NULL;
long long *pool_off = NULL;
unsigned *initial_x = NULL;
unsigned *initial_y = NULL;
long long *initial_x = NULL;
long long *initial_y = NULL;
std::atomic<int> *running = NULL;
int err = 0;
std::vector<std::map<std::string, layermap_entry>> *layermaps = NULL;
std::vector<std::vector<std::string>> *layer_unmaps = NULL;
size_t pass = 0;
unsigned long long mingap = 0;
unsigned long long mingap_out = 0;
index_t mingap = 0;
index_t mingap_out = 0;
long long minextent = 0;
long long minextent_out = 0;
unsigned long long mindrop_sequence = 0;
@@ -918,26 +916,26 @@ static bool clip_to_tile(serial_feature &sf, int z, long long buffer) {
int quick = quick_check(sf.bbox, z, buffer);
if (z == 0) {
if (sf.bbox[0] <= (1LL << 32) * buffer / 256 || sf.bbox[2] >= (1LL << 32) - ((1LL << 32) * buffer / 256)) {
if (sf.bbox[0] <= (1LL << GLOBAL_DETAIL) * buffer / 256 || sf.bbox[2] >= (1LL << GLOBAL_DETAIL) - ((1LL << GLOBAL_DETAIL) * buffer / 256)) {
// If the geometry extends off the edge of the world, concatenate on another copy
// shifted by 360 degrees, and then make sure both copies get clipped down to size.
size_t n = sf.geometry.size();
if (sf.bbox[0] <= (1LL << 32) * buffer / 256) {
if (sf.bbox[0] <= (1LL << GLOBAL_DETAIL) * buffer / 256) {
for (size_t i = 0; i < n; i++) {
sf.geometry.push_back(draw(sf.geometry[i].op, sf.geometry[i].x + (1LL << 32), sf.geometry[i].y));
sf.geometry.push_back(draw(sf.geometry[i].op, sf.geometry[i].x + (1LL << GLOBAL_DETAIL), sf.geometry[i].y));
}
}
if (sf.bbox[2] >= (1LL << 32) - ((1LL << 32) * buffer / 256)) {
if (sf.bbox[2] >= (1LL << GLOBAL_DETAIL) - ((1LL << GLOBAL_DETAIL) * buffer / 256)) {
for (size_t i = 0; i < n; i++) {
sf.geometry.push_back(draw(sf.geometry[i].op, sf.geometry[i].x - (1LL << 32), sf.geometry[i].y));
sf.geometry.push_back(draw(sf.geometry[i].op, sf.geometry[i].x - (1LL << GLOBAL_DETAIL), sf.geometry[i].y));
}
}
sf.bbox[0] = 0;
sf.bbox[2] = 1LL << 32;
sf.bbox[2] = 1LL << GLOBAL_DETAIL;
quick = -1;
}
@@ -1028,7 +1026,7 @@ struct multiplier_state {
// This function is called repeatedly from write_tile() to retrieve the next feature
// from the input stream. If the stream is at an end, it returns a feature with the
// geometry type set to -2.
static serial_feature next_feature(decompressor *geoms, std::atomic<long long> *geompos_in, int z, unsigned tx, unsigned ty, unsigned *initial_x, unsigned *initial_y, long long *original_features, long long *unclipped_features, int nextzoom, int maxzoom, int minzoom, int max_zoom_increment, size_t pass, std::atomic<long long> *along, long long alongminus, int buffer, int *within, compressor **geomfile, std::atomic<long long> *geompos, std::atomic<double> *oprogress, double todo, const char *fname, int child_shards, json_object *filter, const char *global_stringpool, long long *pool_off, std::vector<std::vector<std::string>> *layer_unmaps, bool first_time, bool compressed, multiplier_state *multiplier_state, std::shared_ptr<std::string> &tile_stringpool, std::vector<std::string> const &unidecode_data) {
static serial_feature next_feature(decompressor *geoms, std::atomic<long long> *geompos_in, int z, unsigned tx, unsigned ty, long long *initial_x, long long *initial_y, long long *original_features, long long *unclipped_features, int nextzoom, int maxzoom, int minzoom, int max_zoom_increment, size_t pass, std::atomic<long long> *along, long long alongminus, int buffer, int *within, compressor **geomfile, std::atomic<long long> *geompos, std::atomic<double> *oprogress, double todo, const char *fname, int child_shards, json_object *filter, const char *global_stringpool, long long *pool_off, std::vector<std::vector<std::string>> *layer_unmaps, bool first_time, bool compressed, multiplier_state *multiplier_state, std::shared_ptr<std::string> &tile_stringpool, std::vector<std::string> const &unidecode_data) {
while (1) {
serial_feature sf;
long long len;
@@ -1210,8 +1208,8 @@ struct run_prefilter_args {
int z = 0;
unsigned tx = 0;
unsigned ty = 0;
unsigned *initial_x = 0;
unsigned *initial_y = 0;
long long *initial_x = 0;
long long *initial_y = 0;
long long *original_features = 0;
long long *unclipped_features = 0;
int nextzoom = 0;
@@ -1252,7 +1250,7 @@ void *run_prefilter(void *v) {
}
mvt_layer tmp_layer;
tmp_layer.extent = 1LL << 32;
tmp_layer.extent = 1LL << GLOBAL_DETAIL;
tmp_layer.name = (*(rpa->layer_unmaps))[sf.segment][sf.layer];
if (sf.t == VT_POLYGON) {
@@ -1267,10 +1265,10 @@ void *run_prefilter(void *v) {
tmp_feature.dropped = sf.dropped;
// Offset from tile coordinates back to world coordinates
unsigned sx = 0, sy = 0;
long long sx = 0, sy = 0;
if (rpa->z != 0) {
sx = rpa->tx << (32 - rpa->z);
sy = rpa->ty << (32 - rpa->z);
sx = (long long) rpa->tx << (GLOBAL_DETAIL - rpa->z);
sy = (long long) rpa->ty << (GLOBAL_DETAIL - rpa->z);
}
for (size_t i = 0; i < tmp_feature.geometry.size(); i++) {
tmp_feature.geometry[i].x += sx;
@@ -1408,12 +1406,12 @@ static bool line_is_too_small(drawvec const &geometry, int z, int detail) {
return true;
}
long long x = std::round((double) geometry[0].x / (1LL << (32 - detail - z)));
long long y = std::round((double) geometry[0].y / (1LL << (32 - detail - z)));
long long x = std::round((double) geometry[0].x / (1LL << (GLOBAL_DETAIL - detail - z)));
long long y = std::round((double) geometry[0].y / (1LL << (GLOBAL_DETAIL - detail - z)));
for (auto &g : geometry) {
long long xx = std::round((double) g.x / (1LL << (32 - detail - z)));
long long yy = std::round((double) g.y / (1LL << (32 - detail - z)));
long long xx = std::round((double) g.x / (1LL << (GLOBAL_DETAIL - detail - z)));
long long yy = std::round((double) g.y / (1LL << (GLOBAL_DETAIL - detail - z)));
if (xx != x || yy != y) {
return false;
@@ -1490,7 +1488,7 @@ bool drop_feature_unless_it_can_be_added_to_a_multiplier_cluster(layer_features
return false; // did not drop because nothing could be found to accumulate attributes onto
}
long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, char *global_stringpool, int z, const unsigned tx, const unsigned ty, const int detail, int min_detail, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, compressor **geomfile, int minzoom, int maxzoom, double todo, std::atomic<long long> *along, long long alongminus, double gamma, int child_shards, 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, unsigned long long mingap, long long minextent, unsigned long long mindrop_sequence, const char *prefilter, const char *postfilter, json_object *filter, write_tile_args *arg, atomic_strategy *strategy, bool compressed_input, node *shared_nodes_map, size_t nodepos, std::vector<std::string> const &unidecode_data) {
long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, char *global_stringpool, int z, const unsigned tx, const unsigned ty, const int detail, int min_detail, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, compressor **geomfile, int minzoom, int maxzoom, double todo, std::atomic<long long> *along, long long alongminus, double gamma, int child_shards, long long *pool_off, long long *initial_x, long long *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, index_t mingap, long long minextent, unsigned long long mindrop_sequence, const char *prefilter, const char *postfilter, json_object *filter, write_tile_args *arg, atomic_strategy *strategy, bool compressed_input, node *shared_nodes_map, size_t nodepos, std::vector<std::string> const &unidecode_data) {
double merge_fraction = 1;
double mingap_fraction = 1;
double minextent_fraction = 1;
@@ -1527,8 +1525,8 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
long long count = 0;
double accum_area = 0;
unsigned long long previndex = 0, density_previndex = 0, merge_previndex = 0;
unsigned long long extent_previndex = 0;
index_t previndex = 0, density_previndex = 0, merge_previndex = 0;
index_t extent_previndex = 0;
double scale = (double) (1LL << (64 - 2 * (z + 8)));
double gap = 0, density_gap = 0;
double spacing = 0;
@@ -1872,7 +1870,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
}
}
unsigned long long sfindex = sf.index;
index_t sfindex = sf.index;
if (sf.geometry.size() > 0) {
if (lead_features_count > max_tile_size || (lead_features_count + other_multiplier_cluster_features_count > max_tile_features && !prevent[P_FEATURE_LIMIT])) {
@@ -2198,7 +2196,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
layer_features[x].geometry = remove_noop(layer_features[x].geometry, layer_features[x].t, 0);
if (!(prevent[P_SIMPLIFY] || (z == maxzoom && prevent[P_SIMPLIFY_LOW]))) {
// XXX revisit: why does this not take zoom into account?
layer_features[x].geometry = simplify_lines(layer_features[x].geometry, 32, 0, 0, 0,
layer_features[x].geometry = simplify_lines(layer_features[x].geometry, GLOBAL_DETAIL, 0, 0, 0,
!(prevent[P_CLIPPING] || prevent[P_DUPLICATION]), simplification, layer_features[x].t == VT_POLYGON ? 4 : 0, shared_nodes, NULL, 0);
}
}
@@ -2363,7 +2361,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
continue;
} else if (mingap < ULONG_MAX && (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_COALESCE_DENSEST_AS_NEEDED] || additional[A_CLUSTER_DENSEST_AS_NEEDED])) {
mingap_fraction = mingap_fraction * max_tile_features / totalsize * 0.90;
unsigned long long mg = choose_mingap(indices, mingap_fraction);
index_t mg = choose_mingap(indices, mingap_fraction);
if (mg <= mingap) {
mg = (mingap + 1) * 1.5;
@@ -2470,7 +2468,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
line_detail++; // to keep it the same when the loop decrements it
} else if (mingap < ULONG_MAX && (additional[A_DROP_DENSEST_AS_NEEDED] || additional[A_COALESCE_DENSEST_AS_NEEDED] || additional[A_CLUSTER_DENSEST_AS_NEEDED])) {
mingap_fraction = mingap_fraction * scaled_max_tile_size / (kept_adjust * compressed.size()) * 0.90;
unsigned long long mg = choose_mingap(indices, mingap_fraction);
index_t mg = choose_mingap(indices, mingap_fraction);
if (mg <= mingap) {
double nmg = (mingap + 1) * 1.5;
@@ -2639,8 +2637,10 @@ exit(EXIT_IMPOSSIBLE);
*arg->midy = y;
*arg->most = len;
} else if (len == *arg->most) {
unsigned long long a = (((unsigned long long) x) << 32) | y;
unsigned long long b = (((unsigned long long) *arg->midx) << 32) | *arg->midy;
// the details of the construction of a and b don't really matter very much;
// this is just a tie breaker if two maxzoom tiles have identical sizes
unsigned long long a = (((unsigned long long) x) << (8 * sizeof(y))) | y;
unsigned long long b = (((unsigned long long) *arg->midx) << (8 * sizeof(y))) | *arg->midy;
if (a < b) {
*arg->midx = x;
@@ -2691,7 +2691,7 @@ exit(EXIT_IMPOSSIBLE);
return err_or_null;
}
int traverse_zooms(int *geomfd, off_t *geom_size, char *global_stringpool, std::atomic<unsigned> *midx, std::atomic<unsigned> *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, double maxzoom_simplification, std::vector<std::map<std::string, layermap_entry>> &layermaps, const char *prefilter, const char *postfilter, std::unordered_map<std::string, attribute_op> const *attribute_accum, json_object *filter, std::vector<strategy> &strategies, int iz, node *shared_nodes_map, size_t nodepos, int basezoom, double droprate, std::vector<std::string> const &unidecode_data) {
int traverse_zooms(int *geomfd, off_t *geom_size, char *global_stringpool, std::atomic<unsigned> *midx, std::atomic<unsigned> *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, long long *initial_x, long long *initial_y, double simplification, double maxzoom_simplification, std::vector<std::map<std::string, layermap_entry>> &layermaps, const char *prefilter, const char *postfilter, std::unordered_map<std::string, attribute_op> const *attribute_accum, json_object *filter, std::vector<strategy> &strategies, int iz, node *shared_nodes_map, size_t nodepos, int basezoom, double droprate, std::vector<std::string> const &unidecode_data) {
last_progress = 0;
// The existing layermaps are one table per input thread.
@@ -2826,12 +2826,13 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *global_stringpool, std::
int err = INT_MAX;
double zoom_gamma = gamma;
unsigned long long zoom_mingap = ((1LL << (32 - z)) / 256 * cluster_distance) * ((1LL << (32 - z)) / 256 * cluster_distance);
long long zoom_minextent = 0;
unsigned long long zoom_mindrop_sequence = 0;
size_t zoom_tile_size = 0;
size_t zoom_feature_count = 0;
index_t zoom_mingap = (index_t) ((1LL << (GLOBAL_DETAIL - z)) / 256 * cluster_distance) * ((1LL << (GLOBAL_DETAIL - z)) / 256 * cluster_distance);
for (size_t pass = 0;; pass++) {
pthread_t pthreads[threads];
std::vector<write_tile_args> args;
+2 -2
View File
@@ -55,8 +55,8 @@ struct strategy {
// long long write_tile(char **geom, char *stringpool, unsigned *file_bbox, int z, unsigned x, unsigned y, int detail, int min_detail, int basezoom, sqlite3 *outdb, const char *outdir, double droprate, int buffer, const char *fname, FILE **geomfile, int file_minzoom, int file_maxzoom, double todo, char *geomstart, long long along, double gamma, int nlayers, std::atomic<strategy> *strategy);
int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic<unsigned> *midx, std::atomic<unsigned> *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, double maxzoom_simplification, std::vector<std::map<std::string, layermap_entry> > &layermap, const char *prefilter, const char *postfilter, std::unordered_map<std::string, attribute_op> const *attribute_accum, struct json_object *filter, std::vector<strategy> &strategies, int iz, struct node *shared_nodes_map, size_t nodepos, int basezoom, double droprate, std::vector<std::string> const &unidecode_data);
int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic<unsigned> *midx, std::atomic<unsigned> *midy, int &maxzoom, int minzoom, sqlite3 *outdb, const char *outdir, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *pool_off, long long *initial_x, long long *initial_y, double simplification, double maxzoom_simplification, std::vector<std::map<std::string, layermap_entry> > &layermap, const char *prefilter, const char *postfilter, std::unordered_map<std::string, attribute_op> const *attribute_accum, struct json_object *filter, std::vector<strategy> &strategies, int iz, struct node *shared_nodes_map, size_t nodepos, int basezoom, double droprate, std::vector<std::string> const &unidecode_data);
int manage_gap(unsigned long long index, unsigned long long *previndex, double scale, double gamma, double *gap);
int manage_gap(index_t index, index_t *previndex, double scale, double gamma, double *gap);
#endif
+45
View File
@@ -3,6 +3,7 @@
#include "text.hpp"
#include "sort.hpp"
#include "tile-cache.hpp"
#include "projection.hpp"
#include <unistd.h>
#include <limits.h>
@@ -105,3 +106,47 @@ TEST_CASE("Bit reversal", "bit reversal") {
REQUIRE(bit_reverse(0x1234567812489BCF) == 0xF3D912481E6A2C48);
REQUIRE(bit_reverse(0xF3D912481E6A2C48) == 0x1234567812489BCF);
}
TEST_CASE("Projection", "projection") {
// troublesome point from tests/accumulate/in.json
long long wx36, wy36;
lonlat2tile(-123.948513, -81.873970, 36, &wx36, &wy36);
REQUIRE(wx36 == 0x27dbdc9fb);
REQUIRE(wy36 == 0xebc06c629);
long long wx32, wy32;
lonlat2tile(-123.948513, -81.873970, 32, &wx32, &wy32);
REQUIRE(wx32 == 0x27dbdca0);
REQUIRE(wy32 == 0xebc06c63);
REQUIRE(std::llround(wx36 / 16.0) == wx32);
REQUIRE(std::llround(wy36 / 16.0) == wy32);
}
TEST_CASE("Quadkey index", "quadkey index") {
unsigned long long a = (unsigned) 1234567890;
unsigned long long b = (unsigned) 3210987654;
unsigned long long x = (b << 32) | a;
unsigned long long y = (a << 32) | b;
index_t encoded;
unsigned long long nx, ny;
encoded = encode_quadkey(x, y);
// the *bottom* 64 bits of the 128-bit encoding
// are the same as the 64-bit encoding of a, b
REQUIRE((unsigned long long) encoded == 7338499239188161052ULL);
REQUIRE((unsigned long long) (encoded >> 64) == 11163131681630900524ULL);
decode_quadkey(encoded, &nx, &ny);
REQUIRE(nx == x);
REQUIRE(ny == y);
encoded = encode_hilbert(y, x);
// the *top* 64 bits of the 128-bit encoding
// of the 64-bit encoding of a, b
REQUIRE((unsigned long long) (encoded >> 64) == 8447864191955811122ULL);
REQUIRE((unsigned long long) encoded == 16122461378071376152ULL);
decode_hilbert(encoded, &ny, &nx);
REQUIRE(nx == x);
REQUIRE(ny == y);
}
+3 -3
View File
@@ -268,7 +268,7 @@ void write_coords(json_writer &state, lonlat const &ll, double scale) {
}
}
void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool write_dropped, unsigned long long index, long long sequence, long long extent, bool complain, json_writer &state, double scale) {
void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool write_dropped, index_t index, long long sequence, long long extent, bool complain, json_writer &state, double scale) {
for (size_t f = 0; f < layer.features.size(); f++) {
mvt_feature const &feat = layer.features[f];
@@ -389,12 +389,12 @@ void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y
long long py = feat.geometry[g].y;
if (op == VT_MOVETO || op == VT_LINETO) {
long long wscale = 1LL << (32 - z);
long long wscale = 1LL << (GLOBAL_DETAIL - z);
long long wx = wscale * x + (wscale / layer.extent) * px;
long long wy = wscale * y + (wscale / layer.extent) * py;
double lat, lon;
projection->unproject(wx, wy, 32, &lon, &lat);
projection->unproject(wx, wy, GLOBAL_DETAIL, &lon, &lat);
ops.push_back(lonlat(op, lon, lat, px, py));
} else {
+1 -1
View File
@@ -61,7 +61,7 @@ struct json_writer {
void adds(std::string const &s);
};
void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, unsigned long long index, long long sequence, long long extent, bool complain, json_writer &state, double scale);
void layer_to_geojson(mvt_layer const &layer, unsigned z, unsigned x, unsigned y, bool comma, bool name, bool zoom, bool dropped, index_t index, long long sequence, long long extent, bool complain, json_writer &state, double scale);
void fprintq(FILE *f, const char *s);
#endif