From ffe4c953760d8fd74d1564f5ba4a6194ee78fcac Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 14 Nov 2014 12:42:50 -0800 Subject: [PATCH] Calculate point dropping during encoding instead of tiling so it is consistent across tile boundaries, and so every point that exists at zoom x always also exists at zoom x+1. --- geojson.c | 16 ++++++++++++++++ tile.cc | 22 ++++------------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/geojson.c b/geojson.c index f985e166..c26ca7c3 100644 --- a/geojson.c +++ b/geojson.c @@ -445,6 +445,16 @@ 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; + /* + * Note that minzoom for lines is the dimension + * of the geometry in world coordinates, but + * for points is the lowest zoom level (in tiles, + * not in pixels) at which it should be drawn. + * + * So a line that is too small for, say, z8 + * will have minzoom of 18 (if tile detail is 10), + * not 8. + */ int minzoom = 0; if (mb_geometry[t] == VT_LINE) { for (minzoom = 0; minzoom < 31; minzoom++) { @@ -455,6 +465,12 @@ void read_json(FILE *f, char *fname, char *layername, int maxzoom, int minzoom, break; } } + } else if (mb_geometry[t] == VT_POINT) { + double r = ((double) rand()) / RAND_MAX; + if (r == 0) { + r = .00000001; + } + minzoom = maxzoom - floor(log(r) / - log(droprate)); } /* XXX do proper overlap instead of whole bounding box */ diff --git a/tile.cc b/tile.cc index 27f69f28..cb0bcabc 100644 --- a/tile.cc +++ b/tile.cc @@ -354,24 +354,21 @@ long long write_tile(struct index *start, struct index *end, char *metabase, uns pool_init(&values, 0); std::set dup; - double interval = 1; - double seq = 0; long long count = 0; //long long along = 0; double accum_area = 0; - if (z < basezoom) { - interval = exp(log(droprate) * (basezoom - z)); - } - std::vector features; struct index *i; for (i = start; i < end; i++) { + int t = i->type; + if (z > i->maxzoom) { continue; } - if (z + line_detail <= i->minzoom) { + if ((t == VT_LINE && z + line_detail <= i->minzoom) || + (t == VT_POINT && z < i->minzoom)) { continue; } @@ -382,17 +379,6 @@ long long write_tile(struct index *start, struct index *end, char *metabase, uns dup.insert(i->fpos); } - int t = i->type; - if (t == VT_POINT) { - seq++; - - if (seq >= 0) { - seq -= interval; - } else { - continue; - } - } - char *meta = metabase + i->fpos; drawvec geom = decode_geometry(&meta, z, tx, ty, line_detail);