From bd1f6a09398fea3b0cf6f6fda0a1ba09f34ec21e Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Wed, 14 Dec 2022 12:45:38 -0800 Subject: [PATCH] Add an option to adjust the -rp drop rate --- CHANGELOG.md | 1 + README.md | 3 ++- main.cpp | 17 ++++++++++++++++- man/tippecanoe.1 | 3 ++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3aba60aa..10f80405 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Make as-needed dropping and coalescing much faster: Don't keep scanning through the whole layer looking for another small feature. * Don't guess an excessively large maxzoom when there is only one feature +* Add an option to adjust the -rp drop rate ## 2.15.2 diff --git a/README.md b/README.md index 41f40e28..4f9b94ba 100644 --- a/README.md +++ b/README.md @@ -448,7 +448,8 @@ the same layer, enclose them in an `all` expression so they will all be evaluate You can also specify a marker-width with `-rg`*width* to allow fewer features in the densest tile to compensate for the larger marker, or `-rf`*number* to allow at most *number* features in the densest tile. If you use `-rp` with `-zg` or `--smallest-maximum-zoom-guess` it will choose a drop rate from the same - distance-between-features metrics as are used to choose the maxzoom. + distance-between-features metrics as are used to choose the maxzoom. If you use `-rp`*multiplier* it will keep + *multiplier* times as many points in zoom level 0 as it would normally choose. * `-B` _zoom_ or `--base-zoom=`_zoom_: Base zoom, the level at and above which all points are included in the tiles (default maxzoom). If you use `-Bg`, it will guess a zoom level that will keep at most 50,000 features in the densest tile. You can also specify a marker-width with `-Bg`*width* to allow fewer features in the densest tile to diff --git a/main.cpp b/main.cpp index 9a6d30a5..7f1ad1ca 100644 --- a/main.cpp +++ b/main.cpp @@ -86,6 +86,7 @@ std::string attribute_for_id = ""; size_t limit_tile_feature_count = 0; size_t limit_tile_feature_count_at_maxzoom = 0; unsigned int drop_denser = 0; +double drop_rate_multiplier = 1; std::vector order_by; bool order_reverse; @@ -2165,6 +2166,12 @@ int read_input(std::vector &sources, char *fname, int maxzoom, int minzo if (!quiet) { fprintf(stderr, "Choosing a drop rate of %f\n", droprate); } + + droprate /= exp(log(drop_rate_multiplier) / maxzoom); + + if (drop_rate_multiplier != 1 && !quiet) { + fprintf(stderr, "Adjusting drop rate to %f with multiplier\n", droprate); + } } } @@ -3185,8 +3192,16 @@ int main(int argc, char **argv) { case 'r': if (strcmp(optarg, "g") == 0) { droprate = -2; - } else if (strcmp(optarg, "p") == 0) { + } else if (optarg[0] == 'p') { droprate = -3; + + if (optarg[1] != '\0') { + drop_rate_multiplier = atof_require(optarg + 1, "Drop rate multiplier"); + if (drop_rate_multiplier <= 0) { + fprintf(stderr, "%s: Must specify positive multiplier >0 with -r%c\n", argv[0], optarg[0]); + exit(EXIT_ARGS); + } + } } else if (optarg[0] == 'g' || optarg[0] == 'f') { droprate = -2; if (optarg[0] == 'g') { diff --git a/man/tippecanoe.1 b/man/tippecanoe.1 index 7858d3ca..ee6eac85 100644 --- a/man/tippecanoe.1 +++ b/man/tippecanoe.1 @@ -560,7 +560,8 @@ If you use \fB\fC\-rg\fR, it will guess a drop rate that will keep at most 50,00 You can also specify a marker\-width with \fB\fC\-rg\fR\fIwidth\fP to allow fewer features in the densest tile to compensate for the larger marker, or \fB\fC\-rf\fR\fInumber\fP to allow at most \fInumber\fP features in the densest tile. If you use \fB\fC\-rp\fR with \fB\fC\-zg\fR or \fB\fC\-\-smallest\-maximum\-zoom\-guess\fR it will choose a drop rate from the same -distance\-between\-features metrics as are used to choose the maxzoom. +distance\-between\-features metrics as are used to choose the maxzoom. If you use \fB\fC\-rp\fR\fImultiplier\fP it will keep +\fImultiplier\fP times as many points in zoom level 0 as it would normally choose. .IP \(bu 2 \fB\fC\-B\fR \fIzoom\fP or \fB\fC\-\-base\-zoom=\fR\fIzoom\fP: Base zoom, the level at and above which all points are included in the tiles (default maxzoom). If you use \fB\fC\-Bg\fR, it will guess a zoom level that will keep at most 50,000 features in the densest tile.