Skip to content

Commit

Permalink
Add an option to extend zooms if still dropping, but with a limit
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Aug 17, 2023
1 parent 2b133a1 commit 989cd76
Show file tree
Hide file tree
Showing 6 changed files with 420 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ Parallel processing will also be automatic if the input file is in FlatGeobuf fo
* `-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
specified maximum zoom and to any levels added beyond that.
* `extend-zooms-if-still-dropping-maximum=`_count_: Increase the maxzoom if features are still being dropped at that zoom level
by up to _count_ zoom levels.
* `-R` _zoom_`/`_x_`/`_y_ or `--one-tile=`_zoom_`/`_x_`/`_y_: Set the minzoom and maxzoom to _zoom_ and produce only
the single specified tile at that zoom level.

Expand Down
4 changes: 4 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ size_t limit_tile_feature_count_at_maxzoom = 0;
unsigned int drop_denser = 0;
std::map<std::string, serial_val> set_attributes;
unsigned long long preserve_point_density_threshold = 0;
long long extend_zooms_max = 0;

std::vector<order_field> order_by;
bool order_reverse;
Expand Down Expand Up @@ -2892,6 +2893,7 @@ int main(int argc, char **argv) {
{"minimum-zoom", required_argument, 0, 'Z'},
{"smallest-maximum-zoom-guess", required_argument, 0, '~'},
{"extend-zooms-if-still-dropping", no_argument, &additional[A_EXTEND_ZOOMS], 1},
{"extend-zooms-if-still-dropping-maximum", required_argument, 0, '~'},
{"one-tile", required_argument, 0, 'R'},

{"Tile resolution", 0, 0, 0},
Expand Down Expand Up @@ -3138,6 +3140,8 @@ int main(int argc, char **argv) {
}
} else if (strcmp(opt, "preserve-point-density-threshold") == 0) {
preserve_point_density_threshold = atoll_require(optarg, "Preserve point density threshold");
} else if (strcmp(opt, "extend-zooms-if-still-dropping-maximum") == 0) {
extend_zooms_max = atoll_require(optarg, "Maximum number by which to extend zooms");
} else {
fprintf(stderr, "%s: Unrecognized option --%s\n", argv[0], opt);
exit(EXIT_ARGS);
Expand Down
1 change: 1 addition & 0 deletions main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ extern int tiny_polygon_size;
extern size_t limit_tile_feature_count;
extern size_t limit_tile_feature_count_at_maxzoom;
extern std::map<std::string, serial_val> set_attributes;
extern long long extend_zooms_max;

struct order_field {
std::string name;
Expand Down
3 changes: 3 additions & 0 deletions man/tippecanoe.1
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ Parallel processing will also be automatic if the input file is in FlatGeobuf fo
The detail and simplification options that ordinarily apply only to the maximum zoom level will apply both to the originally
specified maximum zoom and to any levels added beyond that.
.IP \(bu 2
\fB\fCextend\-zooms\-if\-still\-dropping\-maximum=\fR\fIcount\fP: Increase the maxzoom if features are still being dropped at that zoom level
by up to \fIcount\fP zoom levels.
.IP \(bu 2
\fB\fC\-R\fR \fIzoom\fP\fB\fC/\fR\fIx\fP\fB\fC/\fR\fIy\fP or \fB\fC\-\-one\-tile=\fR\fIzoom\fP\fB\fC/\fR\fIx\fP\fB\fC/\fR\fIy\fP: Set the minzoom and maxzoom to \fIzoom\fP and produce only
the single specified tile at that zoom level.
.RE
Expand Down

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ struct ordercmp {
} ordercmp;

void rewrite(drawvec &geom, int z, int nextzoom, int maxzoom, long long *bbox, unsigned tx, unsigned ty, int buffer, int *within, std::atomic<long long> *geompos, compressor **geomfile, const char *fname, signed char t, int layer, signed char feature_minzoom, int child_shards, int max_zoom_increment, long long seq, int tippecanoe_minzoom, int tippecanoe_maxzoom, int segment, unsigned *initial_x, unsigned *initial_y, std::vector<long long> &metakeys, std::vector<long long> &metavals, bool has_id, unsigned long long id, unsigned long long index, unsigned long long label_point, long long extent) {
if (geom.size() > 0 && (nextzoom <= maxzoom || additional[A_EXTEND_ZOOMS])) {
if (geom.size() > 0 && (nextzoom <= maxzoom || additional[A_EXTEND_ZOOMS] || extend_zooms_max > 0)) {
int xo, yo;
int span = 1 << (nextzoom - z);

Expand Down Expand Up @@ -3238,9 +3238,14 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic<
z = args[thread].wrote_zoom;
}

if (additional[A_EXTEND_ZOOMS] && z == maxzoom && args[thread].still_dropping && maxzoom < MAX_ZOOM) {
maxzoom++;
}
if (args[thread].still_dropping) {
if (additional[A_EXTEND_ZOOMS] && z == maxzoom && maxzoom < MAX_ZOOM) {
maxzoom++;
} else if (extend_zooms_max > 0 && z == maxzoom && maxzoom < MAX_ZOOM) {
maxzoom++;
extend_zooms_max--;
}
}
}

if ((size_t) z >= strategies.size()) {
Expand Down

0 comments on commit 989cd76

Please sign in to comment.