Skip to content

Commit

Permalink
Set base zoom if requested as part of maxzoom guessing (#63)
Browse files Browse the repository at this point in the history
* Set base zoom if requested as part of maxzoom guessing

* Add a test for guessing the maxzoom of a single point

* Don't guess an excessively large maxzoom when there is only one feature

* Update changelog
  • Loading branch information
e-n-f authored Jan 26, 2023
1 parent 54b47a6 commit 3cb6e4d
Show file tree
Hide file tree
Showing 7 changed files with 2,295 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.19.0

* Don't guess an excessively large maxzoom when there is only one feature
* Set the base zoom for -Bg as part of the --smallest-maximum-zoom-guess logic

## 2.18.0

* Fix crash when using tile-join to join an empty pmtiles tileset
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ Parallel processing will also be automatic if the input file is in FlatGeobuf fo

* `-z` _zoom_ or `--maximum-zoom=`_zoom_: Maxzoom: the highest zoom level for which tiles are generated (default 14)
* `-zg` or `--maximum-zoom=g`: Guess what is probably a reasonable maxzoom based on the spacing of features.
* `--smallest-maximum-zoom-guess=`_zoom_: Guess what is probably a reasonable maxzoom based on the spacing of features, but using the specified _zoom_ if a lower maxzoom is guessed.
* `--smallest-maximum-zoom-guess=`_zoom_: Guess what is probably a reasonable maxzoom based on the spacing of features, but using the specified _zoom_ if a lower maxzoom is guessed. If `-Bg` is also set, the base zoom will be set to the guessed maxzoom, with all the points carried forward into additional zooms through the one specified.
* `-Z` _zoom_ or `--minimum-zoom=`_zoom_: Minzoom: the lowest zoom level for which tiles are generated (default 0)
* `-ae` or `--extend-zooms-if-still-dropping`: Increase the maxzoom if features are still being dropped at that zoom level.
The detail and simplification options that ordinarily apply only to the maximum zoom level will apply both to the originally
Expand Down
18 changes: 15 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,12 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
exit(EXIT_NODATA);
}

if (count > 0) {
if (count == 0 && dist_count == 0) {
maxzoom = minimum_maxzoom;
if (droprate < 0) {
droprate = 1;
}
} else if (count > 0) {
double stddev = sqrt(m2 / count);

// Geometric mean is appropriate because distances between features
Expand Down Expand Up @@ -2206,6 +2211,13 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i
}
}

if (basezoom == -2 && basezoom_marker_width == 1) { // -Bg, not -Bg###
basezoom = maxzoom;
if (!quiet) {
fprintf(stderr, "Using base zoom of -z%d\n", basezoom);
}
}

if (maxzoom < minimum_maxzoom) {
if (!quiet) {
fprintf(stderr, "Using minimum maxzoom of -z%d\n", minimum_maxzoom);
Expand All @@ -2222,7 +2234,7 @@ std::pair<int, metadata> read_input(std::vector<source> &sources, char *fname, i

fix_dropping = true;

if (basezoom == -1) {
if (basezoom == -1) { // basezoom unspecified
basezoom = maxzoom;
}
}
Expand Down Expand Up @@ -3434,7 +3446,7 @@ int main(int argc, char **argv) {
fprintf(stderr, "%s: Reducing minimum detail to match low detail %d\n", argv[0], min_detail);
}

if (basezoom == -1) {
if (basezoom == -1) { // basezoom unspecified
if (!guess_maxzoom) {
basezoom = maxzoom;
}
Expand Down
2,235 changes: 2,235 additions & 0 deletions tests/ne_110m_populated_places/out/--smallest-maximum-zoom-guess_3_-Bg.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/onefeature-point/in.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[-122,37]}}
37 changes: 37 additions & 0 deletions tests/onefeature-point/out/--smallest-maximum-zoom-guess_3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{ "type": "FeatureCollection", "properties": {
"bounds": "-122.000000,37.000000,-122.000000,37.000000",
"center": "-122.000000,37.000000,3",
"description": "tests/onefeature-point/out/--smallest-maximum-zoom-guess_3.json.check.mbtiles",
"format": "pbf",
"generator_options": "./tippecanoe -q -a@ -f -o tests/onefeature-point/out/--smallest-maximum-zoom-guess_3.json.check.mbtiles --smallest-maximum-zoom-guess 3 tests/onefeature-point/in.json",
"json": "{\"vector_layers\":[{\"id\":\"in\",\"description\":\"\",\"minzoom\":0,\"maxzoom\":3,\"fields\":{}}],\"tilestats\":{\"layerCount\":1,\"layers\":[{\"layer\":\"in\",\"count\":1,\"geometry\":\"Point\",\"attributeCount\":0,\"attributes\":[]}]}}",
"maxzoom": "3",
"minzoom": "0",
"name": "tests/onefeature-point/out/--smallest-maximum-zoom-guess_3.json.check.mbtiles",
"type": "overlay",
"version": "2"
}, "features": [
{ "type": "FeatureCollection", "properties": { "zoom": 0, "x": 0, "y": 0 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -122.080078, 37.020098 ] } }
] }
] }
,
{ "type": "FeatureCollection", "properties": { "zoom": 1, "x": 0, "y": 0 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -122.036133, 37.020098 ] } }
] }
] }
,
{ "type": "FeatureCollection", "properties": { "zoom": 2, "x": 0, "y": 1 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -122.014160, 37.002553 ] } }
] }
] }
,
{ "type": "FeatureCollection", "properties": { "zoom": 3, "x": 1, "y": 3 }, "features": [
{ "type": "FeatureCollection", "properties": { "layer": "in", "version": 2, "extent": 4096 }, "features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -122.003174, 37.002553 ] } }
] }
] }
] }
2 changes: 1 addition & 1 deletion version.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef VERSION_HPP
#define VERSION_HPP

#define VERSION "v2.18.0"
#define VERSION "v2.19.0"

#endif

0 comments on commit 3cb6e4d

Please sign in to comment.