From e8adeba40e65ec15ddecee140c840cf5eec5f705 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Thu, 18 Sep 2014 10:26:47 -0700 Subject: [PATCH] Keep a file bounding box to know the area that needs to be tiled --- geojson.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/geojson.c b/geojson.c index ea38f393..338fe650 100644 --- a/geojson.c +++ b/geojson.c @@ -291,6 +291,8 @@ void read_json(FILE *f) { FILE *indexfile = fopen("index.out", "wb"); long long fpos = 0; + unsigned file_bbox[] = { UINT_MAX, UINT_MAX, 0, 0 }; + while (1) { json_object *j = json_read(jp); if (j == NULL) { @@ -387,6 +389,17 @@ void read_json(FILE *f) { serialize_int(metafile, t, &fpos); parse_geometry(t, coordinates, bbox, &fpos, metafile, VT_MOVETO); serialize_int(metafile, VT_END, &fpos); + + for (i = 0; i < 2; i++) { + if (bbox[i] < file_bbox[i]) { + file_bbox[i] = bbox[i]; + } + } + for (i = 2; i < 4; i++) { + if (bbox[i] > file_bbox[i]) { + file_bbox[i] = bbox[i]; + } + } // printf("bbox %x %x %x %x\n", bbox[0], bbox[1], bbox[2], bbox[3]); @@ -402,6 +415,8 @@ next_feature: /* XXX check for any non-features in the outer object */ } + printf("bbox: %x %x %x %x\n", file_bbox[0], file_bbox[1], file_bbox[2], file_bbox[3]); + json_end(jp); fclose(metafile); fclose(indexfile);