diff --git a/README.md b/README.md index 45161018..86e18c34 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Options * -D Detail at lower zoom levels (default 10, for tile resolution of 1024) * -x Property (removes the named properties from all features) * -f Force: Delete existing mbtiles file if it already exists. + * -r Rate at which dots are dropped at lower zoom levels (default 2.5) Example ------- diff --git a/geojson.c b/geojson.c index 8cb5f167..ed1a2349 100644 --- a/geojson.c +++ b/geojson.c @@ -233,7 +233,7 @@ struct pool_val *deserialize_string(char **f, struct pool *p, int type) { return ret; } -void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox, struct pool *file_keys, unsigned *midx, unsigned *midy, char *layername, int maxzoom, int minzoom, sqlite3 *outdb) { +void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox, struct pool *file_keys, unsigned *midx, unsigned *midy, char *layername, int maxzoom, int minzoom, sqlite3 *outdb, double droprate) { fprintf(stderr, "\n"); long long most = 0; @@ -269,7 +269,7 @@ void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox, s fprintf(stderr, " %3.1f%% %d/%u/%u %x %x %lld to %lld \r", (((i - ix) + (j - ix)) / 2.0 / n + (maxzoom - z)) / (maxzoom - minzoom + 1) * 100, z, tx, ty, wx, wy, (long long)(i - ix), (long long)(j - ix)); - long long len = write_tile(i, j, metabase, file_bbox, z, tx, ty, z == maxzoom ? full_detail : low_detail, maxzoom, file_keys, layername, outdb); + long long len = write_tile(i, j, metabase, file_bbox, z, tx, ty, z == maxzoom ? full_detail : low_detail, maxzoom, file_keys, layername, outdb, droprate); if (z == maxzoom && len > most) { *midx = tx; @@ -282,7 +282,7 @@ void check(struct index *ix, long long n, char *metabase, unsigned *file_bbox, s fprintf(stderr, "\n"); } -void read_json(FILE *f, char *fname, char *layername, int maxzoom, int minzoom, sqlite3 *outdb, struct pool *exclude) { +void read_json(FILE *f, char *fname, char *layername, int maxzoom, int minzoom, sqlite3 *outdb, struct pool *exclude, double droprate) { char metaname[] = "/tmp/meta.XXXXXXXX"; char indexname[] = "/tmp/index.XXXXXXXX"; @@ -509,7 +509,7 @@ next_feature: } 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, &midx, &midy, layername, maxzoom, minzoom, outdb); + check(index, indexst.st_size / sizeof(struct index), meta, file_bbox, &file_keys, &midx, &midy, layername, maxzoom, minzoom, outdb, droprate); munmap(index, indexst.st_size); munmap(meta, metast.st_size); @@ -545,11 +545,12 @@ int main(int argc, char **argv) { int maxzoom = 14; int minzoom = 0; int force = 0; + double droprate = 2.5; struct pool exclude; pool_init(&exclude, 0); - while ((i = getopt(argc, argv, "l:n:z:Z:d:D:o:x:f")) != -1) { + while ((i = getopt(argc, argv, "l:n:z:Z:d:D:o:x:r:f")) != -1) { switch (i) { case 'n': name = optarg; @@ -583,12 +584,16 @@ int main(int argc, char **argv) { pool(&exclude, optarg, VT_STRING); break; + case 'r': + droprate = atof(optarg); + break; + case 'f': force = 1; break; default: - fprintf(stderr, "Usage: %s -o out.mbtiles [-n name] [-l layername] [-z maxzoom] [-Z minzoom] [-d detail] [-D lower-detail] [-x excluded-field ...] [file.json]\n", argv[0]); + fprintf(stderr, "Usage: %s -o out.mbtiles [-n name] [-l layername] [-z maxzoom] [-Z minzoom] [-d detail] [-D lower-detail] [-x excluded-field ...] [-r droprate] [file.json]\n", argv[0]); exit(EXIT_FAILURE); } } @@ -611,7 +616,7 @@ int main(int argc, char **argv) { if (f == NULL) { fprintf(stderr, "%s: %s: %s\n", argv[0], argv[i], strerror(errno)); } else { - read_json(f, name ? name : argv[i], layer, maxzoom, minzoom, outdb, &exclude); + read_json(f, name ? name : argv[i], layer, maxzoom, minzoom, outdb, &exclude, droprate); fclose(f); } } @@ -619,7 +624,7 @@ int main(int argc, char **argv) { fprintf(stderr, "%s: Only accepts one input file\n", argv[0]); exit(EXIT_FAILURE); } else { - read_json(stdin, name ? name : outdir, layer, maxzoom, minzoom, outdb, &exclude); + read_json(stdin, name ? name : outdir, layer, maxzoom, minzoom, outdb, &exclude, droprate); } mbtiles_close(outdb, argv); diff --git a/tile.cc b/tile.cc index ecec11cb..114b3b3b 100644 --- a/tile.cc +++ b/tile.cc @@ -230,9 +230,9 @@ drawvec remove_noop(drawvec geom, int type) { return out; } -drawvec shrink_lines(drawvec &geom, int z, int detail, int basezoom, long long *here) { +drawvec shrink_lines(drawvec &geom, int z, int detail, int basezoom, long long *here, double droprate) { long long res = 200LL << (32 - 8 - z); - long long portion = res / exp(log(sqrt(2.5)) * (basezoom - z)); + long long portion = res / exp(log(sqrt(droprate)) * (basezoom - z)); unsigned i; drawvec out; @@ -642,7 +642,7 @@ int coalindexcmp(const struct coalesce *c1, const struct coalesce *c2) { 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) { +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, double droprate) { int line_detail; for (line_detail = detail; line_detail >= 7; line_detail--) { @@ -667,7 +667,7 @@ long long write_tile(struct index *start, struct index *end, char *metabase, uns long long along = 0; if (z < basezoom) { - interval = exp(log(2.5) * (basezoom - z)); + interval = exp(log(droprate) * (basezoom - z)); } std::vector features; diff --git a/tile.h b/tile.h index adebcdfc..605d75f2 100644 --- a/tile.h +++ b/tile.h @@ -25,4 +25,4 @@ struct index { }; -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, char *layername, sqlite3 *outdb); +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, char *layername, sqlite3 *outdb, double droprate);