Delta encoding for motion within features

This commit is contained in:
Eric Fischer
2015-06-17 17:48:29 -07:00
parent 725ea71e57
commit 46626e4f08
3 changed files with 24 additions and 12 deletions
+8 -5
View File
@@ -100,7 +100,7 @@ void serialize_string(FILE *out, const char *s, long long *fpos, const char *fna
*fpos += len + 1; *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) { 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) {
if (j == NULL || j->type != JSON_ARRAY) { if (j == NULL || j->type != JSON_ARRAY) {
fprintf(stderr, "%s:%d: expected array for type %d\n", fname, source->line, t); fprintf(stderr, "%s:%d: expected array for type %d\n", fname, source->line, t);
return; return;
@@ -119,7 +119,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); parse_geometry(within, j->array[i], bbox, fpos, out, op, fname, source, wx, wy);
} }
} else { } else {
if (j->length >= 2 && j->array[0]->type == JSON_NUMBER && j->array[1]->type == JSON_NUMBER) { if (j->length >= 2 && j->array[0]->type == JSON_NUMBER && j->array[1]->type == JSON_NUMBER) {
@@ -153,8 +153,10 @@ void parse_geometry(int t, json_object *j, unsigned *bbox, long long *fpos, FILE
} }
serialize_byte(out, op, fpos, fname); serialize_byte(out, op, fpos, fname);
serialize_uint(out, x, fpos, fname); serialize_long_long(out, x - *wx, fpos, fname);
serialize_uint(out, y, fpos, fname); serialize_long_long(out, y - *wy, fpos, fname);
*wx = x;
*wy = y;
} else { } else {
fprintf(stderr, "%s:%d: malformed point\n", fname, source->line); fprintf(stderr, "%s:%d: malformed point\n", fname, source->line);
} }
@@ -652,7 +654,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, mb_geometry[t], &geompos, fname);
serialize_byte(geomfile, n, &geompos, fname); serialize_byte(geomfile, n, &geompos, fname);
serialize_long_long(geomfile, metastart, &geompos, fname); serialize_long_long(geomfile, metastart, &geompos, fname);
parse_geometry(t, coordinates, bbox, &geompos, geomfile, VT_MOVETO, fname, jp); long long wx = 0, wy = 0;
parse_geometry(t, coordinates, bbox, &geompos, geomfile, VT_MOVETO, fname, jp, &wx, &wy);
serialize_byte(geomfile, VT_END, &geompos, fname); serialize_byte(geomfile, VT_END, &geompos, fname);
/* /*
+11 -5
View File
@@ -25,6 +25,8 @@ drawvec decode_geometry(char **meta, int z, unsigned tx, unsigned ty, int detail
bbox[2] = LONG_LONG_MIN; bbox[2] = LONG_LONG_MIN;
bbox[3] = LONG_LONG_MIN; bbox[3] = LONG_LONG_MIN;
long long wx = 0, wy = 0;
while (1) { while (1) {
draw d; draw d;
@@ -34,12 +36,16 @@ drawvec decode_geometry(char **meta, int z, unsigned tx, unsigned ty, int detail
} }
if (d.op == VT_MOVETO || d.op == VT_LINETO) { if (d.op == VT_MOVETO || d.op == VT_LINETO) {
unsigned wx, wy; long long dx, dy;
deserialize_uint(meta, &wx);
deserialize_uint(meta, &wy);
long long wwx = (unsigned) wx; deserialize_long_long(meta, &dx);
long long wwy = (unsigned) wy; deserialize_long_long(meta, &dy);
wx += dx;
wy += dy;
long long wwx = wx;
long long wwy = wy;
if (z != 0) { if (z != 0) {
wwx -= tx << (32 - z); wwx -= tx << (32 - z);
+5 -2
View File
@@ -506,13 +506,16 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, unsigned *f
serialize_byte(geomfile[j], t, &geompos[j], fname); serialize_byte(geomfile[j], t, &geompos[j], fname);
serialize_byte(geomfile[j], layer, &geompos[j], fname); serialize_byte(geomfile[j], layer, &geompos[j], fname);
serialize_long_long(geomfile[j], metastart, &geompos[j], fname); serialize_long_long(geomfile[j], metastart, &geompos[j], fname);
long long wx = 0, wy = 0;
for (unsigned u = 0; u < geom.size(); u++) { for (unsigned u = 0; u < geom.size(); u++) {
serialize_byte(geomfile[j], geom[u].op, &geompos[j], fname); serialize_byte(geomfile[j], geom[u].op, &geompos[j], fname);
if (geom[u].op != VT_CLOSEPATH) { if (geom[u].op != VT_CLOSEPATH) {
serialize_uint(geomfile[j], geom[u].x + sx, &geompos[j], fname); serialize_long_long(geomfile[j], geom[u].x + sx - wx, &geompos[j], fname);
serialize_uint(geomfile[j], geom[u].y + sy, &geompos[j], fname); serialize_long_long(geomfile[j], geom[u].y + sy - wy, &geompos[j], fname);
wx = geom[u].x + sx;
wy = geom[u].y + sy;
} }
} }