From ce3cdfc5e9573f87e309d552fbf630e065644631 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 24 Sep 2014 12:14:35 -0700 Subject: [PATCH] Choose the center of the busiest tile for the map center --- geojson.c | 21 ++++++++++++++++----- tile.cc | 6 +++++- tile.h | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/geojson.c b/geojson.c index eb48541..28dec84 100644 --- a/geojson.c +++ b/geojson.c @@ -322,8 +322,9 @@ void range_search(struct index *ix, long long n, unsigned long long start, unsig } } -void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox, struct pool *file_keys) { +void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox, struct pool *file_keys, unsigned *midx, unsigned *midy) { fprintf(stderr, "\n"); + long long most = 0; int z; for (z = BASE_ZOOM; z >= 0; z--) { @@ -357,7 +358,13 @@ void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox, s printf("%d/%u/%u %x %x %lld to %lld\n", z, tx, ty, wx, wy, (long long)(i - ix), (long long)(j - ix)); - write_tile(i, j, metabase, file_bbox, z, tx, ty, z == BASE_ZOOM ? 12 : 10, BASE_ZOOM, file_keys); + long long len = write_tile(i, j, metabase, file_bbox, z, tx, ty, z == BASE_ZOOM ? 12 : 10, BASE_ZOOM, file_keys); + + if (z == BASE_ZOOM && len > most) { + *midx = tx; + *midy = ty; + most = len; + } } } } @@ -390,6 +397,7 @@ void read_json(FILE *f, char *fname) { unlink(indexname); unsigned file_bbox[] = { UINT_MAX, UINT_MAX, 0, 0 }; + unsigned midx = 0, midy = 0; json_pull *jp = json_begin_file(f); long long seq = 0; @@ -570,7 +578,7 @@ next_feature: file_keys.tail = NULL; qsort(index, indexst.st_size / sizeof(struct index), sizeof(struct index), indexcmp); - check(index, indexst.st_size / sizeof(struct index), meta, file_bbox, &file_keys); + check(index, indexst.st_size / sizeof(struct index), meta, file_bbox, &file_keys, &midx, &midy); munmap(index, indexst.st_size); munmap(meta, metast.st_size); @@ -594,12 +602,15 @@ next_feature: double minlat = 0, minlon = 0, maxlat = 0, maxlon = 0, midlat = 0, midlon = 0; - tile2latlon(file_bbox[0], file_bbox[1], 32, &maxlat, &minlon); - tile2latlon(file_bbox[2], file_bbox[3], 32, &minlat, &maxlon); + tile2latlon(midx, midy, BASE_ZOOM, &maxlat, &minlon); + tile2latlon(midx + 1, midy + 1, BASE_ZOOM, &minlat, &maxlon); midlat = (maxlat + minlat) / 2; midlon = (maxlon + minlon) / 2; + tile2latlon(file_bbox[0], file_bbox[1], 32, &maxlat, &minlon); + tile2latlon(file_bbox[2], file_bbox[3], 32, &minlat, &maxlon); + fprintf(fp, "\"version\": 1,\n"); fprintf(fp, "\"minzoom\": %d,\n", 0); fprintf(fp, "\"maxzoom\": %d,\n", BASE_ZOOM); diff --git a/tile.cc b/tile.cc index a744237..4425131 100644 --- a/tile.cc +++ b/tile.cc @@ -204,7 +204,7 @@ int remove_noop(struct draw *geom, int n) { return out; } -void write_tile(struct index *start, struct index *end, char *metabase, unsigned *file_bbox, int z, unsigned tx, unsigned ty, int detail, int basezoom, struct pool *file_keys) { +long long write_tile(struct index *start, struct index *end, char *metabase, unsigned *file_bbox, int z, unsigned tx, unsigned ty, int detail, int basezoom, struct pool *file_keys) { GOOGLE_PROTOBUF_VERIFY_VERSION; mapnik::vector::tile tile; @@ -235,6 +235,7 @@ void write_tile(struct index *start, struct index *end, char *metabase, unsigned double interval = 1; double seq = 0; + long long count = 0; if (z < basezoom) { interval = exp(log(2.5) * (basezoom - z)); @@ -288,6 +289,7 @@ void write_tile(struct index *start, struct index *end, char *metabase, unsigned } draw(geom, len, feature); + count += len; int m; deserialize_int(&meta, &m); @@ -351,5 +353,7 @@ void write_tile(struct index *start, struct index *end, char *metabase, unsigned FILE *f = fopen(path, "wb"); fwrite(compressed.data(), 1, compressed.size(), f); fclose(f); + + return count; } diff --git a/tile.h b/tile.h index a9d7714..0d23276 100644 --- a/tile.h +++ b/tile.h @@ -49,4 +49,4 @@ struct index { }; -void 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); +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);