mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-06 10:25:41 +02:00
The indexing side of buffering features at the edges of tiles
This commit is contained in:
@@ -342,6 +342,7 @@ void read_json(FILE *f, char *fname, char *layername, int maxzoom, int minzoom,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int z = maxzoom;
|
int z = maxzoom;
|
||||||
|
int buffer = 10;
|
||||||
|
|
||||||
unsigned cx = bbox[0] / 2 + bbox[2] / 2;
|
unsigned cx = bbox[0] / 2 + bbox[2] / 2;
|
||||||
unsigned cy = bbox[1] / 2 + bbox[3] / 2;
|
unsigned cy = bbox[1] / 2 + bbox[3] / 2;
|
||||||
@@ -353,9 +354,28 @@ void read_json(FILE *f, char *fname, char *layername, int maxzoom, int minzoom,
|
|||||||
ix.fpos = start;
|
ix.fpos = start;
|
||||||
fwrite_check(&ix, sizeof(struct index), 1, indexfile, fname, jp);
|
fwrite_check(&ix, sizeof(struct index), 1, indexfile, fname, jp);
|
||||||
} else {
|
} else {
|
||||||
|
for (z = maxzoom; z >= 1; z--) {
|
||||||
unsigned x, y;
|
unsigned x, y;
|
||||||
for (x = bbox[0] >> (32 - z); x <= bbox[2] >> (32 - z); x++) {
|
for (x = (bbox[0] - (buffer << (32 - z - 8))) >> (32 - z); x <= (bbox[2] + (buffer << (32 - z - 8))) >> (32 - z); x++) {
|
||||||
for (y = bbox[1] >> (32 - z); y <= bbox[3] >> (32 - z); y++) {
|
for (y = (bbox[1] - (buffer << (32 - z - 8))) >> (32 - z); y <= (bbox[3] + (buffer << (32 - z - 8))) >> (32 - z); y++) {
|
||||||
|
if (z != maxzoom) {
|
||||||
|
// There must be a clearer way to write this, but the intent is
|
||||||
|
// not to add an additional index for a low-zoom tile
|
||||||
|
// if one of its children was already part of the
|
||||||
|
// buffered bounding box for the child's zoom.
|
||||||
|
|
||||||
|
// So we are comparing this tile's x and y to the edges of the
|
||||||
|
// bounding box at the next zoom down, but divided by two
|
||||||
|
// to get it back into this zoom's tile coordinate scheme
|
||||||
|
|
||||||
|
if ((x >= ((bbox[0] - (buffer << (32 - (z + 1) - 8))) >> (32 - (z + 1)) >> 1)) &&
|
||||||
|
(x <= ((bbox[2] + (buffer << (32 - (z + 1) - 8))) >> (32 - (z + 1)) >> 1)) &&
|
||||||
|
(y >= ((bbox[1] - (buffer << (32 - (z + 1) - 8))) >> (32 - (z + 1)) >> 1)) &&
|
||||||
|
(y <= ((bbox[3] + (buffer << (32 - (z + 1) - 8))) >> (32 - (z + 1)) >> 1))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct index ix;
|
struct index ix;
|
||||||
|
|
||||||
if (x == cx >> (32 - z) && y == cy >> (32 - z)) {
|
if (x == cx >> (32 - z) && y == cy >> (32 - z)) {
|
||||||
@@ -364,10 +384,12 @@ void read_json(FILE *f, char *fname, char *layername, int maxzoom, int minzoom,
|
|||||||
ix.index = encode(x << (32 - z), y << (32 - z));
|
ix.index = encode(x << (32 - z), y << (32 - z));
|
||||||
}
|
}
|
||||||
ix.fpos = start;
|
ix.fpos = start;
|
||||||
|
ix.maxzoom = z;
|
||||||
fwrite_check(&ix, sizeof(struct index), 1, indexfile, fname, jp);
|
fwrite_check(&ix, sizeof(struct index), 1, indexfile, fname, jp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < 2; i++) {
|
for (i = 0; i < 2; i++) {
|
||||||
if (bbox[i] < file_bbox[i]) {
|
if (bbox[i] < file_bbox[i]) {
|
||||||
|
|||||||
@@ -366,6 +366,10 @@ long long write_tile(struct index *start, struct index *end, char *metabase, uns
|
|||||||
|
|
||||||
struct index *i;
|
struct index *i;
|
||||||
for (i = start; i < end; i++) {
|
for (i = start; i < end; i++) {
|
||||||
|
if (z > i->maxzoom) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
struct pool_val *pv = pool_long_long(&dup, &i->fpos, 0);
|
struct pool_val *pv = pool_long_long(&dup, &i->fpos, 0);
|
||||||
if (pv->n == 0) {
|
if (pv->n == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ struct pool_val *deserialize_string(char **f, struct pool *p, int type);
|
|||||||
struct index {
|
struct index {
|
||||||
unsigned long long index;
|
unsigned long long index;
|
||||||
long long fpos;
|
long long fpos;
|
||||||
|
int maxzoom;
|
||||||
};
|
};
|
||||||
|
|
||||||
long long write_tile(struct index *start, struct index *end, char *metabase, unsigned *file_bbox, int z, unsigned x, unsigned y, int detail, int basezoom, struct pool *file_keys, char *layername, sqlite3 *outdb, double droprate);
|
long long write_tile(struct index *start, struct index *end, char *metabase, unsigned *file_bbox, int z, unsigned x, unsigned y, int detail, int basezoom, struct pool *file_keys, char *layername, sqlite3 *outdb, double droprate);
|
||||||
|
|||||||
Reference in New Issue
Block a user