mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-01-22 04:18:01 +00:00
Use the first coordinates of the first feature as the origin for deltas
This commit is contained in:
parent
46626e4f08
commit
1a44538bdf
19
geojson.c
19
geojson.c
@ -25,6 +25,9 @@ int low_detail = 10;
|
||||
int full_detail = -1;
|
||||
int min_detail = 7;
|
||||
|
||||
unsigned initial_x = 0, initial_y = 0;
|
||||
int initialized = 0;
|
||||
|
||||
#define GEOM_POINT 0 /* array of positions */
|
||||
#define GEOM_MULTIPOINT 1 /* array of arrays of positions */
|
||||
#define GEOM_LINESTRING 2 /* array of arrays of positions */
|
||||
@ -100,7 +103,7 @@ void serialize_string(FILE *out, const char *s, long long *fpos, const char *fna
|
||||
*fpos += len + 1;
|
||||
}
|
||||
|
||||
void parse_geometry(int t, json_object *j, unsigned *bbox, long long *fpos, FILE *out, int op, const char *fname, json_pull *source, long long *wx, long long *wy) {
|
||||
void parse_geometry(int t, json_object *j, unsigned *bbox, long long *fpos, FILE *out, int op, const char *fname, json_pull *source, long long *wx, long long *wy, int *initialized) {
|
||||
if (j == NULL || j->type != JSON_ARRAY) {
|
||||
fprintf(stderr, "%s:%d: expected array for type %d\n", fname, source->line, t);
|
||||
return;
|
||||
@ -119,7 +122,7 @@ void parse_geometry(int t, json_object *j, unsigned *bbox, long long *fpos, FILE
|
||||
}
|
||||
}
|
||||
|
||||
parse_geometry(within, j->array[i], bbox, fpos, out, op, fname, source, wx, wy);
|
||||
parse_geometry(within, j->array[i], bbox, fpos, out, op, fname, source, wx, wy, initialized);
|
||||
}
|
||||
} else {
|
||||
if (j->length >= 2 && j->array[0]->type == JSON_NUMBER && j->array[1]->type == JSON_NUMBER) {
|
||||
@ -152,6 +155,14 @@ void parse_geometry(int t, json_object *j, unsigned *bbox, long long *fpos, FILE
|
||||
}
|
||||
}
|
||||
|
||||
if (!*initialized) {
|
||||
initial_x = x;
|
||||
initial_y = y;
|
||||
*wx = x;
|
||||
*wy = y;
|
||||
*initialized = 1;
|
||||
}
|
||||
|
||||
serialize_byte(out, op, fpos, fname);
|
||||
serialize_long_long(out, x - *wx, fpos, fname);
|
||||
serialize_long_long(out, y - *wy, fpos, fname);
|
||||
@ -654,8 +665,8 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
|
||||
serialize_byte(geomfile, mb_geometry[t], &geompos, fname);
|
||||
serialize_byte(geomfile, n, &geompos, fname);
|
||||
serialize_long_long(geomfile, metastart, &geompos, fname);
|
||||
long long wx = 0, wy = 0;
|
||||
parse_geometry(t, coordinates, bbox, &geompos, geomfile, VT_MOVETO, fname, jp, &wx, &wy);
|
||||
long long wx = initial_x, wy = initial_y;
|
||||
parse_geometry(t, coordinates, bbox, &geompos, geomfile, VT_MOVETO, fname, jp, &wx, &wy, &initialized);
|
||||
serialize_byte(geomfile, VT_END, &geompos, fname);
|
||||
|
||||
/*
|
||||
|
@ -25,7 +25,7 @@ drawvec decode_geometry(char **meta, int z, unsigned tx, unsigned ty, int detail
|
||||
bbox[2] = LONG_LONG_MIN;
|
||||
bbox[3] = LONG_LONG_MIN;
|
||||
|
||||
long long wx = 0, wy = 0;
|
||||
long long wx = initial_x, wy = initial_y;
|
||||
|
||||
while (1) {
|
||||
draw d;
|
||||
|
2
tile.cc
2
tile.cc
@ -506,7 +506,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, unsigned *f
|
||||
serialize_byte(geomfile[j], t, &geompos[j], fname);
|
||||
serialize_byte(geomfile[j], layer, &geompos[j], fname);
|
||||
serialize_long_long(geomfile[j], metastart, &geompos[j], fname);
|
||||
long long wx = 0, wy = 0;
|
||||
long long wx = initial_x, wy = initial_y;
|
||||
|
||||
for (unsigned u = 0; u < geom.size(); u++) {
|
||||
serialize_byte(geomfile[j], geom[u].op, &geompos[j], fname);
|
||||
|
2
tile.h
2
tile.h
@ -26,3 +26,5 @@ void deserialize_byte(char **f, signed char *n);
|
||||
struct pool_val *deserialize_string(char **f, struct pool *p, int type);
|
||||
|
||||
long long write_tile(char **geom, char *metabase, char *stringpool, unsigned *file_bbox, int z, unsigned x, unsigned y, int detail, int min_detail, int basezoom, struct pool **file_keys, char **layernames, sqlite3 *outdb, double droprate, int buffer, const char *fname, FILE *geomfile[4], int file_minzoom, int file_maxzoom, double todo, char *geomstart, long long along, double gamma, int nlayers, char *prevent);
|
||||
|
||||
extern unsigned initial_x, initial_y;
|
||||
|
Loading…
Reference in New Issue
Block a user