Skip to content

Commit

Permalink
Add command line option to enable or disable overzooming
Browse files Browse the repository at this point in the history
  • Loading branch information
e-n-f committed Aug 18, 2023
1 parent bb107f2 commit 2c1992c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 16 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,11 @@ The options are:
* `-f` or `--force`: Remove *out.mbtiles* if it already exists.
* `-r` or `--read-from`: list of input mbtiles to read from.

### Overzooming

* `--overzoom`: If one of the source tilesets has a larger maxzoom than the others, scale up tiles from the tilesets with the lower maxzooms so they will all have the same maxzoom in the output tileset.
* `--buffer=`_pixels_ or `-b` _pixels_: Set the size of the tile buffer in the overzoomed tiles.

### Tileset description and attribution

* `-A` *attribution* or `--attribution=`*attribution*: Set the attribution string.
Expand Down
9 changes: 7 additions & 2 deletions clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,14 @@ std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int
for (auto const &layer : tile.layers) {
mvt_layer outlayer = mvt_layer();

int det = detail;
if (det <= 0) {
det = std::round(log(layer.extent) / log(2));
}

outlayer.name = layer.name;
outlayer.version = layer.version;
outlayer.extent = 1LL << detail;
outlayer.extent = 1LL << det;

for (auto const &feature : layer.features) {
mvt_feature outfeature;
Expand Down Expand Up @@ -636,7 +641,7 @@ std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int

// Scale to output tile extent

to_tile_scale(geom, nz, detail);
to_tile_scale(geom, nz, det);

// Clean geometries

Expand Down
7 changes: 7 additions & 0 deletions man/tippecanoe.1
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,13 @@ The options are:
.IP \(bu 2
\fB\fC\-r\fR or \fB\fC\-\-read\-from\fR: list of input mbtiles to read from.
.RE
.SS Overzooming
.RS
.IP \(bu 2
\fB\fC\-\-overzoom\fR: If one of the source tilesets has a larger maxzoom than the others, scale up tiles from the tilesets with the lower maxzooms so they will all have the same maxzoom in the output tileset.
.IP \(bu 2
\fB\fC\-\-buffer=\fR\fIpixels\fP or \fB\fC\-b\fR \fIpixels\fP: Set the size of the tile buffer in the overzoomed tiles.
.RE
.SS Tileset description and attribution
.RS
.IP \(bu 2
Expand Down
49 changes: 35 additions & 14 deletions tile-join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ int minzoom = 0;
std::map<std::string, std::string> renames;
bool exclude_all = false;

bool want_overzoom = false;
int buffer = 5;

bool progress_time() {
return false;
}
Expand Down Expand Up @@ -571,7 +574,7 @@ std::string retrieve_overzoom(struct reader *r, zxy tile) {
}

if (source.size() != 0) {
std::string ret = overzoom(source, parent_tile.z, parent_tile.x, parent_tile.y, tile.z, tile.x, tile.y, 12, 5, std::set<std::string>());
std::string ret = overzoom(source, parent_tile.z, parent_tile.x, parent_tile.y, tile.z, tile.x, tile.y, -1, buffer, std::set<std::string>());
return ret;
}

Expand Down Expand Up @@ -601,17 +604,18 @@ void *join_worker(void *v) {
for (auto ai = a->inputs.begin(); ai != a->inputs.end(); ++ai) {
mvt_tile tile;

for (struct reader *r = a->readers; r != NULL; r = r->next) {
if (r->maxzoom_so_far < ai->first.z) {
// if this reader did not produce any tiles at this zoom level,
// and is not ready to produce any tiles at this zoom level,
// it is a candidate for overzooming this tile from whatever
// zoom level it did produce last.

// printf("overzooming %lld/%lld/%lld from zoom %d in %s\n", ai->first.z, ai->first.x, ai->first.y, r->maxzoom_so_far, r->name.c_str());
std::string overzoomed = retrieve_overzoom(r, ai->first);
if (overzoomed.size() != 0) {
ai->second.push_back(overzoomed);
if (want_overzoom) {
for (struct reader *r = a->readers; r != NULL; r = r->next) {
if (r->maxzoom_so_far < ai->first.z) {
// if this reader did not produce any tiles at this zoom level,
// and is not ready to produce any tiles at this zoom level,
// it is a candidate for overzooming this tile from whatever
// zoom level it did produce last.

std::string overzoomed = retrieve_overzoom(r, ai->first);
if (overzoomed.size() != 0) {
ai->second.push_back(overzoomed);
}
}
}
}
Expand Down Expand Up @@ -958,8 +962,10 @@ void decode(struct reader *readers, std::map<std::string, layermap_entry> &layer
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
int maxz = min(sqlite3_column_int(r->stmt, 0), maxzoom);

if (st->maxzoom >= 0 && maxz != st->maxzoom) {
fprintf(stderr, "Warning: mismatched maxzooms: %d in %s vs previous %d\n", maxz, r->name.c_str(), st->maxzoom);
if (!want_overzoom) {
if (st->maxzoom >= 0 && maxz != st->maxzoom) {
fprintf(stderr, "Warning: mismatched maxzooms: %d in %s vs previous %d\n", maxz, r->name.c_str(), st->maxzoom);
}
}

st->maxzoom = max(st->maxzoom, maxz);
Expand Down Expand Up @@ -1117,6 +1123,8 @@ int main(int argc, char **argv) {
{"output", required_argument, 0, 'o'},
{"output-to-directory", required_argument, 0, 'e'},
{"force", no_argument, 0, 'f'},
{"overzoom", no_argument, 0, 'O'},
{"buffer", required_argument, 0, 'b'},
{"if-matched", no_argument, 0, 'i'},
{"attribution", required_argument, 0, 'A'},
{"name", required_argument, 0, 'n'},
Expand Down Expand Up @@ -1182,6 +1190,14 @@ int main(int argc, char **argv) {
force = 1;
break;

case 'O':
want_overzoom = true;
break;

case 'b':
buffer = atoi(optarg);
break;

case 'i':
ifmatched = 1;
break;
Expand Down Expand Up @@ -1338,6 +1354,11 @@ int main(int argc, char **argv) {
exit(EXIT_ARGS);
}

if (buffer < 0) {
fprintf(stderr, "%s: buffer cannot be less than 0\n", argv[0]);
exit(EXIT_ARGS);
}

if (out_mbtiles != NULL) {
if (force) {
unlink(out_mbtiles);
Expand Down

0 comments on commit 2c1992c

Please sign in to comment.