From 5595a087c7f537e762313561a9b6b77e937a6e60 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 12 Nov 2014 15:57:45 -0800 Subject: [PATCH] Quick reject by bounding box of linear features too small to draw --- geojson.c | 14 ++++++++++++++ tile.cc | 3 +++ tile.h | 5 +++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/geojson.c b/geojson.c index d4b50b5..a6727a6 100644 --- a/geojson.c +++ b/geojson.c @@ -445,6 +445,18 @@ void read_json(FILE *f, char *fname, char *layername, int maxzoom, int minzoom, unsigned cx = bbox[0] / 2 + bbox[2] / 2; unsigned cy = bbox[1] / 2 + bbox[3] / 2; + int minzoom = 0; + if (mb_geometry[t] == VT_LINE) { + for (minzoom = 0; minzoom < 31; minzoom++) { + unsigned mask = 1 << (32 - (minzoom + 1)); + + if (((bbox[0] & mask) != (bbox[2] & mask)) || + ((bbox[1] & mask) != (bbox[3] & mask))) { + break; + } + } + } + /* XXX do proper overlap instead of whole bounding box */ if (z == 0) { struct index ix; @@ -452,6 +464,7 @@ void read_json(FILE *f, char *fname, char *layername, int maxzoom, int minzoom, ix.fpos = start; ix.type = mb_geometry[t]; ix.maxzoom = z; + ix.minzoom = minzoom; fwrite_check(&ix, sizeof(struct index), 1, indexfile, fname, jp); } else { int pass; @@ -497,6 +510,7 @@ void read_json(FILE *f, char *fname, char *layername, int maxzoom, int minzoom, ix.type = mb_geometry[t]; ix.maxzoom = z; ix.candup = (instances > 1); + ix.minzoom = minzoom; fwrite_check(&ix, sizeof(struct index), 1, indexfile, fname, jp); } } diff --git a/tile.cc b/tile.cc index b490a21..96b1fea 100644 --- a/tile.cc +++ b/tile.cc @@ -371,6 +371,9 @@ long long write_tile(struct index *start, struct index *end, char *metabase, uns if (z > i->maxzoom) { continue; } + if (z + line_detail <= i->minzoom) { + continue; + } if (i->candup) { if (dup.count(i->fpos) != 0) { diff --git a/tile.h b/tile.h index 7ae1a72..120137b 100644 --- a/tile.h +++ b/tile.h @@ -20,8 +20,9 @@ struct pool_val *deserialize_string(char **f, struct pool *p, int type); struct index { unsigned long long index; - long long fpos : 48; - int maxzoom : 8; + long long fpos : 44; + int maxzoom : 6; + int minzoom : 6; int type : 7; int candup : 1; };