From 98b0cb5e3fcf9c28e8076d32a20e4cc6de45aa1b Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 29 Sep 2014 15:38:33 -0700 Subject: [PATCH] Tiles are smaller if coalesced features are sorted geographically --- tile.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tile.cc b/tile.cc index 7aad026..e7b1820 100644 --- a/tile.cc +++ b/tile.cc @@ -444,6 +444,8 @@ struct coalesce { int nmeta; int *meta; + + unsigned long long index; }; int coalcmp(const void *v1, const void *v2) { @@ -467,6 +469,23 @@ int coalcmp(const void *v1, const void *v2) { return c1->nmeta - c2->nmeta; } +int coalindexcmp(const void *v1, const void *v2) { + int cmp = coalcmp(v1, v2); + + if (cmp == 0) { + const struct coalesce *c1 = (const struct coalesce *) v1; + const struct coalesce *c2 = (const struct coalesce *) v2; + + if (c1->index < c2->index) { + return -1; + } else if (c1->index > c2->index) { + return 1; + } + } + + return cmp; +} + 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, char *layername, sqlite3 *outdb) { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -546,6 +565,7 @@ long long write_tile(struct index *start, struct index *end, char *metabase, uns pv->n = 0; features[nfeatures].type = t; + features[nfeatures].index = i->index; features[nfeatures].ngeom = len; features[nfeatures].geom = (struct draw *) malloc(len * sizeof(struct draw)); @@ -575,7 +595,7 @@ long long write_tile(struct index *start, struct index *end, char *metabase, uns } } - qsort(features, nfeatures, sizeof(struct coalesce), coalcmp); + qsort(features, nfeatures, sizeof(struct coalesce), coalindexcmp); int x; int out = 0;