mirror of
https://github.com/felt/tippecanoe.git
synced 2026-11-25 18:01:19 +01:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6d05bc317 | ||
|
|
2ec6180003 | ||
|
|
6778aeac52 |
@@ -1,3 +1,17 @@
|
||||
# 2.31.0
|
||||
|
||||
* Fix tile-join crash when trying to join empty tilesets
|
||||
* Add --no-tiny-polygon-reduction-at-maximum-zoom option
|
||||
|
||||
# 2.30.1
|
||||
|
||||
* Fix spurious reports of tiny polygons and 0-length LineStrings in "strategies"
|
||||
|
||||
# 2.30.0
|
||||
|
||||
* Add --extend-zooms-if-still-dropping-maximum option
|
||||
* Add --overzoom option to tile-join
|
||||
|
||||
# 2.29.0
|
||||
|
||||
* Add tippecanoe-overzoom tool
|
||||
|
||||
@@ -67,7 +67,7 @@ tippecanoe-enumerate: enumerate.o
|
||||
tippecanoe-decode: decode.o projection.o mvt.o write_json.o text.o jsonpull/jsonpull.o dirtiles.o pmtiles_file.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3
|
||||
|
||||
tile-join: tile-join.o projection.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpull/jsonpull.o text.o evaluator.o csv.o write_json.o pmtiles_file.o
|
||||
tile-join: tile-join.o projection.o mbtiles.o mvt.o memfile.o dirtiles.o jsonpull/jsonpull.o text.o evaluator.o csv.o write_json.o pmtiles_file.o clip.o
|
||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
||||
|
||||
tippecanoe-json-tool: jsontool.o jsonpull/jsonpull.o csv.o text.o geojson-loop.o
|
||||
@@ -398,14 +398,28 @@ join-test: tile-join
|
||||
./tippecanoe-decode -x generator -x generator_options -x name -x description tests/join-population/empty.pmtiles > tests/join-population/empty.out.json.check
|
||||
cmp tests/join-population/empty.out.json.check tests/join-population/empty.out.json
|
||||
rm -f tests/join-population/empty.pmtiles tests/join-population/empty.out.pmtiles tests/join-population/empty.out.json.check
|
||||
# pmtiles again, with --overzoom
|
||||
./tippecanoe -q -z0 -f -o tests/join-population/empty.pmtiles tests/join-population/empty.json
|
||||
./tile-join --overzoom -f -o tests/join-population/empty.out.pmtiles tests/join-population/empty.pmtiles
|
||||
./tippecanoe-decode -x generator -x generator_options -x name -x description tests/join-population/empty.pmtiles > tests/join-population/empty.out.json.check
|
||||
cmp tests/join-population/empty.out.json.check tests/join-population/empty.out.json
|
||||
rm -f tests/join-population/empty.pmtiles tests/join-population/empty.out.pmtiles tests/join-population/empty.out.json.check
|
||||
# dirtiles:
|
||||
./tippecanoe -q -z0 -f -e tests/join-population/empty.dirtiles tests/join-population/empty.json
|
||||
./tile-join -f -e tests/join-population/empty.out.dirtiles tests/join-population/empty.dirtiles
|
||||
./tippecanoe-decode -x generator -x generator_options -x name -x description tests/join-population/empty.dirtiles > tests/join-population/empty.out.json.check
|
||||
cmp tests/join-population/empty.out.json.check tests/join-population/empty.out.json
|
||||
rm -rf tests/join-population/empty.dirtiles tests/join-population/empty.out.dirtiles tests/join-population/empty.out.json.check
|
||||
|
||||
|
||||
#
|
||||
# Test overzooming of tilesets with different maxzooms
|
||||
#
|
||||
mkdir -p tests/ne_110m_ocean/join
|
||||
./tippecanoe -q -z2 -f -o tests/ne_110m_ocean/join/ocean.mbtiles tests/ne_110m_ocean/in.json
|
||||
./tippecanoe -q -z4 -d8 -y name -f -o tests/ne_110m_ocean/join/countries.mbtiles tests/ne_110m_admin_0_countries/in.json.gz
|
||||
./tile-join --overzoom -f -o tests/ne_110m_ocean/join/joined.mbtiles tests/ne_110m_ocean/join/ocean.mbtiles tests/ne_110m_ocean/join/countries.mbtiles
|
||||
./tippecanoe-decode -x generator tests/ne_110m_ocean/join/joined.mbtiles > tests/ne_110m_ocean/join/joined.mbtiles.json.check
|
||||
cmp tests/ne_110m_ocean/join/joined.mbtiles.json.check tests/ne_110m_ocean/join/joined.mbtiles.json
|
||||
rm -f tests/ne_110m_ocean/join/ocean.mbtiles tests/ne_110m_ocean/join/countries.mbtiles tests/ne_110m_ocean/join/joined.mbtiles tests/ne_110m_ocean/join/joined.mbtiles.json.check
|
||||
|
||||
join-filter-test:
|
||||
# Comes out different from the direct tippecanoe run because null attributes are lost
|
||||
|
||||
@@ -345,6 +345,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.
|
||||
|
||||
@@ -492,6 +494,7 @@ the same layer, enclose them in an `all` expression so they will all be evaluate
|
||||
* `--simplification-at-maximum-zoom=`_scale_: Use the specified _scale_ at maxzoom instead of the standard simplification scale (which still applies at lower zooms)
|
||||
* `-pn` or `--no-simplification-of-shared-nodes`: Don't simplify away nodes that appear in more than one feature or are used multiple times within the same feature, so that the intersection node will not be lost from intersecting roads. (This will not be effective if you also use `--coalesce` or `--detect-shared-borders`.)
|
||||
* `-pt` or `--no-tiny-polygon-reduction`: Don't combine the area of very small polygons into small squares that represent their combined area.
|
||||
* `-pT` or `--no-tiny-polygon-reduction-at-maximum-zoom`: Combine the area of very small polygons into small squares that represent their combined area only at zoom levels below the maximum.
|
||||
* `--tiny-polygon-size=`_size_: Use the specified _size_ for tiny polygons instead of the default 2. Anything above 6 or so will lead to visible artifacts with the default tile detail.
|
||||
* `-av` or `--visvalingam`: Use Visvalingam's simplification algorithm rather than Douglas-Peucker's.
|
||||
|
||||
@@ -769,6 +772,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.
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <mapbox/geometry/snap_rounding.hpp>
|
||||
#include "geometry.hpp"
|
||||
#include "errors.hpp"
|
||||
#include "compression.hpp"
|
||||
#include "mvt.hpp"
|
||||
|
||||
drawvec simple_clip_poly(drawvec &geom, long long minx, long long miny, long long maxx, long long maxy) {
|
||||
drawvec out;
|
||||
@@ -565,3 +567,127 @@ drawvec close_poly(drawvec &geom) {
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int ny,
|
||||
int detail, int buffer, std::set<std::string> const &keep) {
|
||||
mvt_tile tile, outtile;
|
||||
bool was_compressed;
|
||||
|
||||
try {
|
||||
if (!tile.decode(s, was_compressed)) {
|
||||
fprintf(stderr, "Couldn't parse tile %d/%u/%u\n", oz, ox, oy);
|
||||
exit(EXIT_MVT);
|
||||
}
|
||||
} catch (std::exception const &e) {
|
||||
fprintf(stderr, "PBF decoding error in tile %d/%u/%u\n", oz, ox, oy);
|
||||
exit(EXIT_PROTOBUF);
|
||||
}
|
||||
|
||||
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 << det;
|
||||
|
||||
for (auto const &feature : layer.features) {
|
||||
mvt_feature outfeature;
|
||||
drawvec geom;
|
||||
int t = feature.type;
|
||||
|
||||
// Convert feature geometry to world coordinates
|
||||
|
||||
long long tilesize = 1LL << (32 - oz); // source tile size in world coordinates
|
||||
draw ring_closure(0, 0, 0);
|
||||
|
||||
for (auto const &g : feature.geometry) {
|
||||
if (g.op == mvt_closepath) {
|
||||
geom.push_back(ring_closure);
|
||||
} else {
|
||||
geom.emplace_back(g.op,
|
||||
g.x * tilesize / layer.extent + ox * tilesize,
|
||||
g.y * tilesize / layer.extent + oy * tilesize);
|
||||
|
||||
if (g.op == mvt_moveto) {
|
||||
ring_closure = geom.back();
|
||||
ring_closure.op = mvt_lineto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now offset from world coordinates to output tile coordinates,
|
||||
// but retain world scale, because that is what tippecanoe clipping expects
|
||||
|
||||
long long outtilesize = 1LL << (32 - nz); // destination tile size in world coordinates
|
||||
for (auto &g : geom) {
|
||||
g.x -= nx * outtilesize;
|
||||
g.y -= ny * outtilesize;
|
||||
}
|
||||
|
||||
// Clip to output tile
|
||||
|
||||
if (t == VT_LINE) {
|
||||
geom = clip_lines(geom, nz, buffer);
|
||||
} else if (t == VT_POLYGON) {
|
||||
geom = simple_clip_poly(geom, nz, buffer);
|
||||
} else if (t == VT_POINT) {
|
||||
geom = clip_point(geom, nz, buffer);
|
||||
}
|
||||
|
||||
// Scale to output tile extent
|
||||
|
||||
to_tile_scale(geom, nz, det);
|
||||
|
||||
// Clean geometries
|
||||
|
||||
geom = remove_noop(geom, t, 0);
|
||||
if (t == VT_POLYGON) {
|
||||
geom = clean_or_clip_poly(geom, 0, 0, false);
|
||||
geom = close_poly(geom);
|
||||
}
|
||||
|
||||
// Add geometry to output feature
|
||||
|
||||
outfeature.type = t;
|
||||
for (auto const &g : geom) {
|
||||
outfeature.geometry.emplace_back(g.op, g.x, g.y);
|
||||
}
|
||||
|
||||
// ID and attributes, if it didn't get clipped away
|
||||
|
||||
if (outfeature.geometry.size() > 0) {
|
||||
if (feature.has_id) {
|
||||
outfeature.has_id = true;
|
||||
outfeature.id = feature.id;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i + 1 < feature.tags.size(); i += 2) {
|
||||
if (keep.size() == 0 || keep.find(layer.keys[feature.tags[i]]) != keep.end()) {
|
||||
outlayer.tag(outfeature, layer.keys[feature.tags[i]], layer.values[feature.tags[i + 1]]);
|
||||
}
|
||||
}
|
||||
|
||||
outlayer.features.push_back(outfeature);
|
||||
}
|
||||
}
|
||||
|
||||
if (outlayer.features.size() > 0) {
|
||||
outtile.layers.push_back(outlayer);
|
||||
}
|
||||
}
|
||||
|
||||
if (outtile.layers.size() > 0) {
|
||||
std::string pbf = outtile.encode();
|
||||
std::string compressed;
|
||||
compress(pbf, compressed, true);
|
||||
|
||||
return compressed;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
+10
-7
@@ -186,14 +186,15 @@ void check_polygon(drawvec &geom) {
|
||||
}
|
||||
}
|
||||
|
||||
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area, serial_feature *this_feature, serial_feature *tiny_feature) {
|
||||
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *still_needs_simplification, bool *reduced_away, double *accum_area, serial_feature *this_feature, serial_feature *tiny_feature) {
|
||||
drawvec out;
|
||||
const double pixel = (1LL << (32 - detail - z)) * (double) tiny_polygon_size;
|
||||
bool includes_real = false;
|
||||
bool includes_dust = false;
|
||||
|
||||
*reduced = true;
|
||||
bool included_last_outer = false;
|
||||
*still_needs_simplification = false;
|
||||
*reduced_away = false;
|
||||
|
||||
for (size_t i = 0; i < geom.size(); i++) {
|
||||
if (geom[i].op == VT_MOVETO) {
|
||||
@@ -223,9 +224,9 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
|
||||
// cut out of, so we are just subtracting its area from the tiny polygon
|
||||
// rather than trying to deal with it geometrically
|
||||
if ((area > 0 && area <= pixel * pixel) || (area < 0 && !included_last_outer)) {
|
||||
// printf("area is only %f vs %lld so using square\n", area, pixel * pixel);
|
||||
|
||||
*accum_area += area;
|
||||
*reduced_away = true;
|
||||
|
||||
if (area > 0 && *accum_area > pixel * pixel) {
|
||||
// XXX use centroid;
|
||||
|
||||
@@ -248,21 +249,23 @@ drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double
|
||||
// as a real geometry because otherwise we can accumulate enough tiny holes
|
||||
// that we will drop the next several outer rings getting back up to 0.
|
||||
else {
|
||||
// printf("area is %f so keeping instead of %lld\n", area, pixel * pixel);
|
||||
|
||||
for (size_t k = i; k < j && k < geom.size(); k++) {
|
||||
out.push_back(geom[k]);
|
||||
}
|
||||
|
||||
// which means that the overall polygon has a real geometry,
|
||||
// which means that it gets to be simplified.
|
||||
*reduced = false;
|
||||
*still_needs_simplification = true;
|
||||
includes_real = true;
|
||||
|
||||
if (area > 0) {
|
||||
included_last_outer = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// area is 0: doesn't count as either having been reduced away,
|
||||
// since it was probably just degenerate from having been clipped,
|
||||
// or as needing simplification, since it produces no output.
|
||||
}
|
||||
|
||||
i = j - 1;
|
||||
|
||||
+6
-1
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <sqlite3.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -66,7 +68,7 @@ drawvec clip_point(drawvec &geom, int z, long long buffer);
|
||||
drawvec clean_or_clip_poly(drawvec &geom, int z, int buffer, bool clip);
|
||||
drawvec simple_clip_poly(drawvec &geom, int z, int buffer);
|
||||
drawvec close_poly(drawvec &geom);
|
||||
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *reduced, double *accum_area, serial_feature *this_feature, serial_feature *tiny_feature);
|
||||
drawvec reduce_tiny_poly(drawvec &geom, int z, int detail, bool *still_needs_simplification, bool *reduced_away, double *accum_area, serial_feature *this_feature, serial_feature *tiny_feature);
|
||||
int clip(double *x0, double *y0, double *x1, double *y1, double xmin, double ymin, double xmax, double ymax);
|
||||
drawvec clip_lines(drawvec &geom, int z, long long buffer);
|
||||
drawvec stairstep(drawvec &geom, int z, int detail);
|
||||
@@ -88,4 +90,7 @@ drawvec clip_point(drawvec &geom, long long x1, long long y1, long long x2, long
|
||||
void visvalingam(drawvec &ls, size_t start, size_t end, double threshold, size_t retain);
|
||||
int pnpoly(const drawvec &vert, size_t start, size_t nvert, long long testx, long long testy);
|
||||
|
||||
std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int ny,
|
||||
int detail, int buffer, std::set<std::string> const &keep);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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;
|
||||
@@ -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},
|
||||
@@ -2950,6 +2952,7 @@ int main(int argc, char **argv) {
|
||||
{"simplify-only-low-zooms", no_argument, &prevent[P_SIMPLIFY_LOW], 1},
|
||||
{"simplification-at-maximum-zoom", required_argument, 0, '~'},
|
||||
{"no-tiny-polygon-reduction", no_argument, &prevent[P_TINY_POLYGON_REDUCTION], 1},
|
||||
{"no-tiny-polygon-reduction-at-maximum-zoom", no_argument, &prevent[P_TINY_POLYGON_REDUCTION_AT_MAXZOOM], 1},
|
||||
{"tiny-polygon-size", required_argument, 0, '~'},
|
||||
{"no-simplification-of-shared-nodes", no_argument, &prevent[P_SIMPLIFY_SHARED_NODES], 1},
|
||||
{"visvalingam", no_argument, &additional[A_VISVALINGAM], 1},
|
||||
@@ -3138,6 +3141,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);
|
||||
@@ -3585,7 +3590,7 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (extra_detail >= 0) {
|
||||
if (extra_detail >= 0 || additional[A_EXTEND_ZOOMS] || extend_zooms_max > 0) {
|
||||
geometry_scale = 0;
|
||||
} else {
|
||||
geometry_scale = 32 - (full_detail + maxzoom);
|
||||
|
||||
@@ -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;
|
||||
|
||||
+17
-1
@@ -27,7 +27,11 @@ see the shape and relative popularity of every point of interest and every
|
||||
significant travel corridor.
|
||||
.SH Installation
|
||||
.PP
|
||||
For this fork you will need to build from the source repository:
|
||||
The easiest way to install tippecanoe on OSX is with Homebrew \[la]http://brew.sh/\[ra]:
|
||||
.PP
|
||||
$ brew install tippecanoe
|
||||
.PP
|
||||
On Ubuntu it will usually be easiest to build from the source repository:
|
||||
.PP
|
||||
.RS
|
||||
.nf
|
||||
@@ -403,6 +407,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\fC\-\-extend\-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
|
||||
@@ -626,6 +633,8 @@ the line or polygon within one tile unit of its proper location. You can probabl
|
||||
.IP \(bu 2
|
||||
\fB\fC\-pt\fR or \fB\fC\-\-no\-tiny\-polygon\-reduction\fR: Don't combine the area of very small polygons into small squares that represent their combined area.
|
||||
.IP \(bu 2
|
||||
\fB\fC\-pT\fR or \fB\fC\-\-no\-tiny\-polygon\-reduction\-at\-maximum\-zoom\fR: Combine the area of very small polygons into small squares that represent their combined area only at zoom levels below the maximum.
|
||||
.IP \(bu 2
|
||||
\fB\fC\-\-tiny\-polygon\-size=\fR\fIsize\fP: Use the specified \fIsize\fP for tiny polygons instead of the default 2. Anything above 6 or so will lead to visible artifacts with the default tile detail.
|
||||
.IP \(bu 2
|
||||
\fB\fC\-av\fR or \fB\fC\-\-visvalingam\fR: Use Visvalingam's simplification algorithm rather than Douglas\-Peucker's.
|
||||
@@ -965,6 +974,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
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#define P_CLIPPING ((int) 'c')
|
||||
#define P_DUPLICATION ((int) 'D')
|
||||
#define P_TINY_POLYGON_REDUCTION ((int) 't')
|
||||
#define P_TINY_POLYGON_REDUCTION_AT_MAXZOOM ((int) 'T')
|
||||
#define P_TILE_COMPRESSION ((int) 'C')
|
||||
#define P_TILE_STATS ((int) 'g')
|
||||
#define P_USE_SOURCE_POLYGON_WINDING ((int) 'w')
|
||||
|
||||
+1
-119
@@ -15,124 +15,6 @@ int buffer = 5; // tippecanoe-style: mvt buffer == extent * buffer / 256;
|
||||
|
||||
std::set<std::string> keep;
|
||||
|
||||
std::string overzoom(std::string s, int oz, int ox, int oy, int nz, int nx, int ny) {
|
||||
mvt_tile tile, outtile;
|
||||
bool was_compressed;
|
||||
|
||||
try {
|
||||
if (!tile.decode(s, was_compressed)) {
|
||||
fprintf(stderr, "Couldn't parse tile %d/%u/%u\n", oz, ox, oy);
|
||||
exit(EXIT_MVT);
|
||||
}
|
||||
} catch (std::exception const &e) {
|
||||
fprintf(stderr, "PBF decoding error in tile %d/%u/%u\n", oz, ox, oy);
|
||||
exit(EXIT_PROTOBUF);
|
||||
}
|
||||
|
||||
for (auto const &layer : tile.layers) {
|
||||
mvt_layer outlayer = mvt_layer();
|
||||
|
||||
outlayer.name = layer.name;
|
||||
outlayer.version = layer.version;
|
||||
outlayer.extent = 1LL << detail;
|
||||
|
||||
for (auto const &feature : layer.features) {
|
||||
mvt_feature outfeature;
|
||||
drawvec geom;
|
||||
int t = feature.type;
|
||||
|
||||
// Convert feature geometry to world coordinates
|
||||
|
||||
long long tilesize = 1LL << (32 - oz); // source tile size in world coordinates
|
||||
draw ring_closure(0, 0, 0);
|
||||
|
||||
for (auto const &g : feature.geometry) {
|
||||
if (g.op == mvt_closepath) {
|
||||
geom.push_back(ring_closure);
|
||||
} else {
|
||||
geom.emplace_back(g.op,
|
||||
g.x * tilesize / layer.extent + ox * tilesize,
|
||||
g.y * tilesize / layer.extent + oy * tilesize);
|
||||
|
||||
if (g.op == mvt_moveto) {
|
||||
ring_closure = geom.back();
|
||||
ring_closure.op = mvt_lineto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now offset from world coordinates to output tile coordinates,
|
||||
// but retain world scale, because that is what tippecanoe clipping expects
|
||||
|
||||
long long outtilesize = 1LL << (32 - nz); // destination tile size in world coordinates
|
||||
for (auto &g : geom) {
|
||||
g.x -= nx * outtilesize;
|
||||
g.y -= ny * outtilesize;
|
||||
}
|
||||
|
||||
// Clip to output tile
|
||||
|
||||
if (t == VT_LINE) {
|
||||
geom = clip_lines(geom, nz, buffer);
|
||||
} else if (t == VT_POLYGON) {
|
||||
geom = simple_clip_poly(geom, nz, buffer);
|
||||
} else if (t == VT_POINT) {
|
||||
geom = clip_point(geom, nz, buffer);
|
||||
}
|
||||
|
||||
// Scale to output tile extent
|
||||
|
||||
to_tile_scale(geom, nz, detail);
|
||||
|
||||
// Clean geometries
|
||||
|
||||
geom = remove_noop(geom, t, 0);
|
||||
if (t == VT_POLYGON) {
|
||||
geom = clean_or_clip_poly(geom, 0, 0, false);
|
||||
geom = close_poly(geom);
|
||||
}
|
||||
|
||||
// Add geometry to output feature
|
||||
|
||||
outfeature.type = t;
|
||||
for (auto const &g : geom) {
|
||||
outfeature.geometry.emplace_back(g.op, g.x, g.y);
|
||||
}
|
||||
|
||||
// ID and attributes, if it didn't get clipped away
|
||||
|
||||
if (outfeature.geometry.size() > 0) {
|
||||
if (feature.has_id) {
|
||||
outfeature.has_id = true;
|
||||
outfeature.id = feature.id;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i + 1 < feature.tags.size(); i += 2) {
|
||||
if (keep.size() == 0 || keep.find(layer.keys[feature.tags[i]]) != keep.end()) {
|
||||
outlayer.tag(outfeature, layer.keys[feature.tags[i]], layer.values[feature.tags[i + 1]]);
|
||||
}
|
||||
}
|
||||
|
||||
outlayer.features.push_back(outfeature);
|
||||
}
|
||||
}
|
||||
|
||||
if (outlayer.features.size() > 0) {
|
||||
outtile.layers.push_back(outlayer);
|
||||
}
|
||||
}
|
||||
|
||||
if (outtile.layers.size() > 0) {
|
||||
std::string pbf = outtile.encode();
|
||||
std::string compressed;
|
||||
compress(pbf, compressed, true);
|
||||
|
||||
return compressed;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
void usage(char **argv) {
|
||||
fprintf(stderr, "Usage: %s -o newtile.pbf.gz tile.pbf.gz oz/ox/oy nz/nx/ny\n", argv[0]);
|
||||
fprintf(stderr, "to create tile nz/nx/ny from tile oz/ox/oy\n");
|
||||
@@ -209,7 +91,7 @@ int main(int argc, char **argv) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::string out = overzoom(tile, oz, ox, oy, nz, nx, ny);
|
||||
std::string out = overzoom(tile, oz, ox, oy, nz, nx, ny, detail, buffer, keep);
|
||||
fwrite(out.c_str(), sizeof(char), out.size(), f);
|
||||
fclose(f);
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
"maxzoom": "9",
|
||||
"minzoom": "8",
|
||||
"name": "tests/allow-existing/both.mbtiles",
|
||||
"strategies": "[{},{},{},{},{},{},{},{},{\"tiny_polygons\":1},{}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"maxzoom": "1",
|
||||
"minzoom": "0",
|
||||
"name": "tests/border/out/-z1_--detect-shared-borders.json.check.mbtiles",
|
||||
"strategies": "[{\"tiny_polygons\":1},{\"tiny_polygons\":1}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"maxzoom": "1",
|
||||
"minzoom": "0",
|
||||
"name": "tests/coalesce-id/out/-z1_--coalesce_--reorder.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":2}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
-1
@@ -9,7 +9,6 @@
|
||||
"maxzoom": "11",
|
||||
"minzoom": "11",
|
||||
"name": "tests/coalesce-tract/out/-P_--coalesce_--reorder_-z11_-Z11_-y_STATEFP10_-y_COUNTYFP10_-l_merged.json.check.mbtiles",
|
||||
"strategies": "[{},{},{},{},{},{},{},{},{},{},{},{\"tiny_polygons\":5}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"maxzoom": "2",
|
||||
"minzoom": "0",
|
||||
"name": "tests/curve/out/-z2.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":4}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"maxzoom": "2",
|
||||
"minzoom": "0",
|
||||
"name": "tests/curve/out/-z2_--no-clipping.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":10}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"maxzoom": "2",
|
||||
"minzoom": "0",
|
||||
"name": "tests/curve/out/-z2_--no-duplication.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":6},{\"tiny_polygons\":6}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"maxzoom": "5",
|
||||
"minzoom": "0",
|
||||
"name": "tests/dateline/out/-z5.json.check.mbtiles",
|
||||
"strategies": "[{},{},{},{\"tiny_polygons\":1},{},{\"tiny_polygons\":1}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"maxzoom": "5",
|
||||
"minzoom": "0",
|
||||
"name": "tests/dateline/out/-z5_-b0.json.check.mbtiles",
|
||||
"strategies": "[{},{},{},{\"tiny_polygons\":1},{},{}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
@@ -9,6 +9,7 @@
|
||||
"maxzoom": "0",
|
||||
"minzoom": "0",
|
||||
"name": "tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb.json.check.mbtiles",
|
||||
"strategies": "[{\"tiny_polygons\":1}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
+1
@@ -9,6 +9,7 @@
|
||||
"maxzoom": "0",
|
||||
"minzoom": "0",
|
||||
"name": "tests/named/out/-z0_-Lalgeria%3atests%2fnamed%2falg_-Lalbania%3atests%2fnamed%2falb_-lunified.json.check.mbtiles",
|
||||
"strategies": "[{\"tiny_polygons\":1}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"maxzoom": "5",
|
||||
"minzoom": "5",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-R5%2f17%2f11.json.check.mbtiles",
|
||||
"strategies": "[{},{},{},{},{},{\"tiny_polygons\":1}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "5",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-densest-as-needed.json.check.mbtiles",
|
||||
"strategies": "[{\"dropped_as_needed\":171,\"tile_size_desired\":39209},{\"dropped_as_needed\":189,\"tiny_polygons\":1,\"tile_size_desired\":25164},{\"dropped_as_needed\":161,\"tiny_polygons\":2,\"tile_size_desired\":21198},{\"dropped_as_needed\":134,\"tiny_polygons\":12,\"tile_size_desired\":10761},{\"dropped_as_needed\":62,\"tiny_polygons\":20,\"tile_size_desired\":6604},{\"tiny_polygons\":47}]",
|
||||
"strategies": "[{\"dropped_as_needed\":171,\"tile_size_desired\":39209},{\"dropped_as_needed\":189,\"tile_size_desired\":25164},{\"dropped_as_needed\":161,\"tile_size_desired\":21198},{\"dropped_as_needed\":134,\"tile_size_desired\":10761},{\"dropped_as_needed\":62,\"tile_size_desired\":6604},{\"tiny_polygons\":2}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "5",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-fraction-as-needed.json.check.mbtiles",
|
||||
"strategies": "[{\"dropped_as_needed\":160,\"tile_size_desired\":39209},{\"dropped_as_needed\":188,\"tile_size_desired\":25164},{\"dropped_as_needed\":190,\"tiny_polygons\":2,\"tile_size_desired\":21198},{\"dropped_as_needed\":180,\"tiny_polygons\":9,\"tile_size_desired\":10761},{\"dropped_as_needed\":145,\"tiny_polygons\":17,\"tile_size_desired\":6604},{\"tiny_polygons\":47}]",
|
||||
"strategies": "[{\"dropped_as_needed\":160,\"tile_size_desired\":39209},{\"dropped_as_needed\":188,\"tile_size_desired\":25164},{\"dropped_as_needed\":190,\"tile_size_desired\":21198},{\"dropped_as_needed\":180,\"tile_size_desired\":10761},{\"dropped_as_needed\":145,\"tile_size_desired\":6604},{\"tiny_polygons\":2}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "5",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--drop-smallest-as-needed.json.check.mbtiles",
|
||||
"strategies": "[{\"dropped_as_needed\":174,\"tile_size_desired\":39209},{\"dropped_as_needed\":202,\"tile_size_desired\":25164},{\"dropped_as_needed\":190,\"tiny_polygons\":2,\"tile_size_desired\":21198},{\"dropped_as_needed\":156,\"tiny_polygons\":12,\"tile_size_desired\":10761},{\"dropped_as_needed\":80,\"tiny_polygons\":20,\"tile_size_desired\":6604},{\"tiny_polygons\":47}]",
|
||||
"strategies": "[{\"dropped_as_needed\":174,\"tile_size_desired\":39209},{\"dropped_as_needed\":202,\"tile_size_desired\":25164},{\"dropped_as_needed\":190,\"tile_size_desired\":21198},{\"dropped_as_needed\":156,\"tile_size_desired\":10761},{\"dropped_as_needed\":80,\"tile_size_desired\":6604},{\"tiny_polygons\":2}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "5",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-ae_-zg_-M5000_--force-feature-limit.json.check.mbtiles",
|
||||
"strategies": "[{\"dropped_as_needed\":316,\"tile_size_desired\":39209},{\"dropped_as_needed\":287,\"tiny_polygons\":4,\"tile_size_desired\":25164},{\"dropped_as_needed\":223,\"tiny_polygons\":4,\"tile_size_desired\":21198},{\"dropped_as_needed\":93,\"tiny_polygons\":14,\"tile_size_desired\":10761},{\"dropped_as_needed\":9,\"tiny_polygons\":21,\"tile_size_desired\":6604},{\"tiny_polygons\":47}]",
|
||||
"strategies": "[{\"dropped_as_needed\":316,\"tile_size_desired\":39209},{\"dropped_as_needed\":287,\"tiny_polygons\":3,\"tile_size_desired\":25164},{\"dropped_as_needed\":223,\"tiny_polygons\":2,\"tile_size_desired\":21198},{\"dropped_as_needed\":93,\"tile_size_desired\":10761},{\"dropped_as_needed\":9,\"tile_size_desired\":6604},{\"tiny_polygons\":2}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "0",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_100.json.check.mbtiles",
|
||||
"strategies": "[{\"tiny_polygons\":138}]",
|
||||
"strategies": "[{\"tiny_polygons\":150}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "0",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--order-largest-first.json.check.mbtiles",
|
||||
"strategies": "[{\"tiny_polygons\":90}]",
|
||||
"strategies": "[{\"tiny_polygons\":109}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "0",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z0_--tiny-polygon-size_50_--simplification_50.json.check.mbtiles",
|
||||
"strategies": "[{\"tiny_polygons\":90}]",
|
||||
"strategies": "[{\"tiny_polygons\":109}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "2",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z2_--convert-polygons-to-label-points.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3}]",
|
||||
"strategies": "[{},{},{\"tiny_polygons\":1}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "3",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z3_-ai.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3},{\"tiny_polygons\":12}]",
|
||||
"strategies": "[{},{},{\"tiny_polygons\":1},{}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "4",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z4_-yname.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3},{\"tiny_polygons\":12},{\"tiny_polygons\":20}]",
|
||||
"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":1},{},{}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "4",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_--drop-polygons.json.check.mbtiles",
|
||||
"strategies": "[{\"dropped_by_rate\":172},{\"dropped_by_rate\":205,\"tiny_polygons\":1},{\"dropped_by_rate\":189},{\"dropped_by_rate\":166,\"tiny_polygons\":7},{\"tiny_polygons\":20}]",
|
||||
"strategies": "[{\"dropped_by_rate\":172},{\"dropped_by_rate\":205},{\"dropped_by_rate\":189},{\"dropped_by_rate\":166},{}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "4",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3},{\"tiny_polygons\":12},{\"tiny_polygons\":20}]",
|
||||
"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":1},{},{}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "4",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--simplification-at-maximum-zoom_2.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3},{\"tiny_polygons\":12},{\"tiny_polygons\":20}]",
|
||||
"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":1},{},{}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "4",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_-S4_--visvalingam.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":2},{\"tiny_polygons\":3},{\"tiny_polygons\":12},{\"tiny_polygons\":20}]",
|
||||
"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":1},{},{}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"maxzoom": "4",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_-pD.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":45},{\"tiny_polygons\":29},{\"tiny_polygons\":70},{\"tiny_polygons\":120}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"maxzoom": "4",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z4_-yname_-pc.json.check.mbtiles",
|
||||
"strategies": "[{},{\"tiny_polygons\":1},{\"tiny_polygons\":8},{\"tiny_polygons\":32},{\"tiny_polygons\":63}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "5",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-densest-as-needed.json.check.mbtiles",
|
||||
"strategies": "[{\"coalesced_as_needed\":528,\"detail_reduced\":2,\"tile_size_desired\":39204},{\"coalesced_as_needed\":212,\"tile_size_desired\":25156},{\"coalesced_as_needed\":192,\"tiny_polygons\":3,\"tile_size_desired\":21207},{\"coalesced_as_needed\":156,\"tiny_polygons\":11,\"tile_size_desired\":10753},{\"coalesced_as_needed\":65,\"tiny_polygons\":20,\"tile_size_desired\":6588},{\"tiny_polygons\":46}]",
|
||||
"strategies": "[{\"coalesced_as_needed\":528,\"detail_reduced\":2,\"tiny_polygons\":2,\"tile_size_desired\":39204},{\"coalesced_as_needed\":212,\"tile_size_desired\":25156},{\"coalesced_as_needed\":192,\"tiny_polygons\":1,\"tile_size_desired\":21207},{\"coalesced_as_needed\":156,\"tile_size_desired\":10753},{\"coalesced_as_needed\":65,\"tile_size_desired\":6588},{\"tiny_polygons\":1}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "5",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-fraction-as-needed.json.check.mbtiles",
|
||||
"strategies": "[{\"coalesced_as_needed\":528,\"detail_reduced\":2,\"tile_size_desired\":39204},{\"coalesced_as_needed\":217,\"tile_size_desired\":25156},{\"coalesced_as_needed\":218,\"tiny_polygons\":2,\"tile_size_desired\":21207},{\"coalesced_as_needed\":227,\"tiny_polygons\":4,\"tile_size_desired\":10753},{\"coalesced_as_needed\":192,\"tiny_polygons\":13,\"tile_size_desired\":6588},{\"tiny_polygons\":46}]",
|
||||
"strategies": "[{\"coalesced_as_needed\":528,\"detail_reduced\":2,\"tiny_polygons\":2,\"tile_size_desired\":39204},{\"coalesced_as_needed\":217,\"tile_size_desired\":25156},{\"coalesced_as_needed\":218,\"tile_size_desired\":21207},{\"coalesced_as_needed\":227,\"tile_size_desired\":10753},{\"coalesced_as_needed\":192,\"tile_size_desired\":6588},{\"tiny_polygons\":1}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "5",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z5_-M5000_--coalesce-smallest-as-needed.json.check.mbtiles",
|
||||
"strategies": "[{\"coalesced_as_needed\":1272,\"tile_size_desired\":39204},{\"coalesced_as_needed\":1191,\"tiny_polygons\":1,\"tile_size_desired\":25156},{\"coalesced_as_needed\":731,\"tiny_polygons\":3,\"tile_size_desired\":21207},{\"coalesced_as_needed\":178,\"tiny_polygons\":8,\"tile_size_desired\":10753},{\"coalesced_as_needed\":74,\"tiny_polygons\":20,\"tile_size_desired\":6588},{\"tiny_polygons\":46}]",
|
||||
"strategies": "[{\"coalesced_as_needed\":1272,\"tiny_polygons\":5,\"tile_size_desired\":39204},{\"coalesced_as_needed\":1191,\"tile_size_desired\":25156},{\"coalesced_as_needed\":731,\"tiny_polygons\":1,\"tile_size_desired\":21207},{\"coalesced_as_needed\":178,\"tile_size_desired\":10753},{\"coalesced_as_needed\":74,\"tile_size_desired\":6588},{\"tiny_polygons\":1}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "5",
|
||||
"minzoom": "0",
|
||||
"name": "tests/ne_110m_admin_0_countries/out/-z5_-M5000_--drop-smallest-as-needed.json.check.mbtiles",
|
||||
"strategies": "[{\"dropped_as_needed\":174,\"tile_size_desired\":39204},{\"dropped_as_needed\":202,\"tile_size_desired\":25156},{\"dropped_as_needed\":190,\"tiny_polygons\":2,\"tile_size_desired\":21207},{\"dropped_as_needed\":156,\"tiny_polygons\":12,\"tile_size_desired\":10753},{\"dropped_as_needed\":78,\"tiny_polygons\":20,\"tile_size_desired\":6588},{\"tiny_polygons\":46}]",
|
||||
"strategies": "[{\"dropped_as_needed\":174,\"tile_size_desired\":39204},{\"dropped_as_needed\":202,\"tile_size_desired\":25156},{\"dropped_as_needed\":190,\"tile_size_desired\":21207},{\"dropped_as_needed\":156,\"tile_size_desired\":10753},{\"dropped_as_needed\":78,\"tile_size_desired\":6588},{\"tiny_polygons\":1}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+401
File diff suppressed because one or more lines are too long
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "4",
|
||||
"minzoom": "0",
|
||||
"name": "tests/nullisland/out/-b0_-z4.json.check.mbtiles",
|
||||
"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8,\"tiny_polygons\":12},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]",
|
||||
"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"maxzoom": "4",
|
||||
"minzoom": "0",
|
||||
"name": "tests/nullisland/out/-b0_-z4_-ANullIsland.json.check.mbtiles",
|
||||
"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8,\"tiny_polygons\":12},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]",
|
||||
"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"maxzoom": "4",
|
||||
"minzoom": "0",
|
||||
"name": "tests/nullisland/out/-b0_-z4_-NNullIsland.json.check.mbtiles",
|
||||
"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8,\"tiny_polygons\":12},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]",
|
||||
"strategies": "[{\"dropped_by_rate\":4},{\"dropped_by_rate\":8},{\"dropped_by_rate\":8},{\"dropped_by_rate\":3},{}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
"maxzoom": "0",
|
||||
"minzoom": "0",
|
||||
"name": "tests/polygon-winding/out/-z0_--reverse-source-polygon-winding.json.check.mbtiles",
|
||||
"strategies": "[{\"tiny_polygons\":1}]",
|
||||
"type": "overlay",
|
||||
"version": "2"
|
||||
}, "features": [
|
||||
|
||||
+439
-206
@@ -40,6 +40,7 @@
|
||||
#include "jsonpull/jsonpull.h"
|
||||
#include "milo/dtoa_milo.h"
|
||||
#include "errors.hpp"
|
||||
#include "geometry.hpp"
|
||||
|
||||
int pk = false;
|
||||
int pC = false;
|
||||
@@ -52,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;
|
||||
}
|
||||
@@ -80,7 +84,7 @@ void aprintf(std::string *buf, const char *format, ...) {
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::string, layermap_entry> &layermap, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping, std::set<std::string> &exclude, std::set<std::string> &include, std::set<std::string> &keep_layers, std::set<std::string> &remove_layers, int ifmatched, mvt_tile &outtile, json_object *filter) {
|
||||
void append_tile(std::string message, int z, unsigned x, unsigned y, std::map<std::string, layermap_entry> &layermap, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping, std::set<std::string> &exclude, std::set<std::string> &include, std::set<std::string> &keep_layers, std::set<std::string> &remove_layers, int ifmatched, mvt_tile &outtile, json_object *filter) {
|
||||
mvt_tile tile;
|
||||
int features_added = 0;
|
||||
bool was_compressed;
|
||||
@@ -372,27 +376,321 @@ double max(double a, double b) {
|
||||
}
|
||||
}
|
||||
|
||||
struct tilecmp {
|
||||
bool operator()(std::pair<unsigned, unsigned> const &a, std::pair<unsigned, unsigned> const &b) {
|
||||
// must match behavior of reader::operator<()
|
||||
|
||||
if (a.first < b.first) {
|
||||
return true;
|
||||
}
|
||||
if (a.first == b.first) {
|
||||
// Y sorts backwards, in TMS order
|
||||
if (a.second > b.second) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} tilecmp;
|
||||
|
||||
// The `reader` is an iterator through the tiles of a tileset,
|
||||
// in z/x/tms_y order.
|
||||
//
|
||||
// The basic idea is that it is used like this:
|
||||
//
|
||||
// void blah(const char *fname) {
|
||||
// reader r(fname);
|
||||
//
|
||||
// for (; !r.all_done(); r.advance()) {
|
||||
// std::pair<zxy, std::string> tile = r.current();
|
||||
// whatever(tile);
|
||||
// }
|
||||
//
|
||||
// r.close();
|
||||
// }
|
||||
//
|
||||
// The complication is that you can actually keep calling current()
|
||||
// and advance() after the reader claims to be done, in which case
|
||||
// it will produce overzoomed tiles generated from the tiles in
|
||||
// the maxzoom tileset. The parent tiles for those overzoomed tiles
|
||||
// are retrieved internally using get_tile() rather than through the
|
||||
// main iteration query.
|
||||
|
||||
struct reader {
|
||||
// z/x/y and data of the current tile
|
||||
long long zoom = 0;
|
||||
long long x = 0;
|
||||
long long sorty = 0;
|
||||
long long y = 0;
|
||||
int z_flag = 0;
|
||||
|
||||
std::string data = "";
|
||||
bool current_tile_is_overzoomed = false;
|
||||
|
||||
std::vector<zxy> dirtiles;
|
||||
std::string dirbase;
|
||||
std::string name;
|
||||
// "done" means we have read all of the real tiles from the source.
|
||||
// The iterator will continue to produce overzoomed tiles after it is "done."
|
||||
bool done = false;
|
||||
|
||||
// for overzooming
|
||||
int maxzoom_so_far = -1;
|
||||
std::vector<std::pair<unsigned, unsigned>> tiles_at_maxzoom_so_far;
|
||||
std::vector<std::pair<unsigned, unsigned>> overzoomed_tiles;
|
||||
bool overzoom_consumed_at_this_zoom = false;
|
||||
|
||||
// for iterating mbtiles
|
||||
sqlite3 *db = NULL;
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
struct reader *next = NULL;
|
||||
|
||||
// for iterating dirtiles
|
||||
std::vector<zxy> dirtiles;
|
||||
std::string dirbase;
|
||||
std::string name;
|
||||
|
||||
// for iterating pmtiles
|
||||
char *pmtiles_map = NULL;
|
||||
std::vector<pmtiles::entry_zxy> pmtiles_entries;
|
||||
|
||||
reader(const char *fname) {
|
||||
name = fname;
|
||||
struct stat st;
|
||||
if (stat(fname, &st) == 0 && (st.st_mode & S_IFDIR) != 0) {
|
||||
db = NULL;
|
||||
stmt = NULL;
|
||||
next = NULL;
|
||||
|
||||
dirtiles = enumerate_dirtiles(fname, minzoom, maxzoom);
|
||||
dirbase = fname;
|
||||
} else if (pmtiles_has_suffix(fname)) {
|
||||
int pmtiles_fd = open(fname, O_RDONLY | O_CLOEXEC);
|
||||
pmtiles_map = (char *) mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, pmtiles_fd, 0);
|
||||
|
||||
if (pmtiles_map == MAP_FAILED) {
|
||||
perror("mmap in decode");
|
||||
exit(EXIT_MEMORY);
|
||||
}
|
||||
if (::close(pmtiles_fd) != 0) {
|
||||
perror("close");
|
||||
exit(EXIT_CLOSE);
|
||||
}
|
||||
|
||||
pmtiles_entries = pmtiles_entries_tms(pmtiles_map, minzoom, maxzoom);
|
||||
std::reverse(pmtiles_entries.begin(), pmtiles_entries.end());
|
||||
} else {
|
||||
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
|
||||
exit(EXIT_SQLITE);
|
||||
}
|
||||
|
||||
char *err = NULL;
|
||||
if (sqlite3_exec(db, "PRAGMA integrity_check;", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: integrity_check: %s\n", fname, err);
|
||||
exit(EXIT_SQLITE);
|
||||
}
|
||||
|
||||
const char *sql = "SELECT zoom_level, tile_column, tile_row, tile_data from tiles order by zoom_level, tile_column, tile_row;";
|
||||
sqlite3_stmt *query;
|
||||
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &query, NULL) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
|
||||
exit(EXIT_SQLITE);
|
||||
}
|
||||
|
||||
stmt = query;
|
||||
next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Checks the done status not only of this reader but also
|
||||
// the others chained to it in the queue.
|
||||
//
|
||||
// Also claims not to be done if at least one overzoomed tile
|
||||
// has been consumed at this zoom level, in which case they should
|
||||
// all allowed to be consumed before stopping.
|
||||
bool all_done() {
|
||||
if (!done) {
|
||||
return false;
|
||||
}
|
||||
if (overzoom_consumed_at_this_zoom) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (struct reader *r = next; r != NULL; r = r->next) {
|
||||
if (!r->done) {
|
||||
return false;
|
||||
}
|
||||
if (r->overzoom_consumed_at_this_zoom) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::pair<zxy, std::string> current() {
|
||||
if (current_tile_is_overzoomed) {
|
||||
overzoom_consumed_at_this_zoom = true;
|
||||
}
|
||||
|
||||
return std::pair<zxy, std::string>(zxy(zoom, x, y), data);
|
||||
}
|
||||
|
||||
void advance() {
|
||||
if (done) {
|
||||
if (!want_overzoom) {
|
||||
fprintf(stderr, "overzoom advance called without -O\n");
|
||||
exit(EXIT_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
if (overzoomed_tiles.size() == 0) {
|
||||
next_overzoom();
|
||||
overzoom_consumed_at_this_zoom = false;
|
||||
}
|
||||
|
||||
if (overzoomed_tiles.size() == 0) {
|
||||
// we have nothing to overzoom; give up
|
||||
current_tile_is_overzoomed = false;
|
||||
zoom = 32;
|
||||
return;
|
||||
}
|
||||
|
||||
auto xy = overzoomed_tiles.front();
|
||||
overzoomed_tiles.erase(overzoomed_tiles.begin());
|
||||
|
||||
x = xy.first;
|
||||
y = xy.second;
|
||||
data = retrieve_overzoom(zxy(zoom, x, y));
|
||||
current_tile_is_overzoomed = true;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
current_tile_is_overzoomed = false;
|
||||
|
||||
if (db != NULL) {
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
zoom = sqlite3_column_int(stmt, 0);
|
||||
x = sqlite3_column_int(stmt, 1);
|
||||
int tms_y = sqlite3_column_int(stmt, 2);
|
||||
y = (1LL << zoom) - 1 - tms_y;
|
||||
const char *s = (const char *) sqlite3_column_blob(stmt, 3);
|
||||
size_t len = sqlite3_column_bytes(stmt, 3);
|
||||
|
||||
data = std::string(s, len);
|
||||
} else {
|
||||
done = true;
|
||||
}
|
||||
} else if (pmtiles_map != NULL) {
|
||||
if (pmtiles_entries.size() == 0) {
|
||||
done = true;
|
||||
} else {
|
||||
zoom = pmtiles_entries.back().z;
|
||||
x = pmtiles_entries.back().x;
|
||||
y = pmtiles_entries.back().y;
|
||||
data = std::string(pmtiles_map + pmtiles_entries.back().offset, pmtiles_entries.back().length);
|
||||
|
||||
pmtiles_entries.pop_back();
|
||||
}
|
||||
} else {
|
||||
if (dirtiles.size() == 0) {
|
||||
done = true;
|
||||
} else {
|
||||
zoom = dirtiles[0].z;
|
||||
x = dirtiles[0].x;
|
||||
y = dirtiles[0].y;
|
||||
data = dir_read_tile(dirbase, dirtiles[0]);
|
||||
|
||||
dirtiles.erase(dirtiles.begin());
|
||||
}
|
||||
}
|
||||
|
||||
if (done) {
|
||||
if (want_overzoom) {
|
||||
next_overzoom();
|
||||
advance();
|
||||
} else {
|
||||
zoom = 32;
|
||||
}
|
||||
} else {
|
||||
if (zoom > maxzoom_so_far) {
|
||||
maxzoom_so_far = zoom;
|
||||
tiles_at_maxzoom_so_far.clear();
|
||||
}
|
||||
|
||||
if (want_overzoom) {
|
||||
tiles_at_maxzoom_so_far.push_back(std::pair<unsigned, unsigned>(x, y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void close() {
|
||||
if (pmtiles_map) {
|
||||
db = pmtilesmeta2tmp(name.c_str(), pmtiles_map);
|
||||
// json, strategies
|
||||
} else if (db == NULL) {
|
||||
db = dirmeta2tmp(dirbase.c_str());
|
||||
} else {
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
void next_overzoom() {
|
||||
zoom++;
|
||||
overzoomed_tiles.clear();
|
||||
|
||||
long long scale = (1LL << zoom) / (1LL << maxzoom_so_far);
|
||||
|
||||
for (auto const &xy : tiles_at_maxzoom_so_far) {
|
||||
for (long long xx = 0; xx < scale; xx++) {
|
||||
for (long long yy = 0; yy < scale; yy++) {
|
||||
overzoomed_tiles.push_back(std::pair<unsigned, unsigned>(xy.first * scale + xx, xy.second * scale + yy));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(overzoomed_tiles.begin(), overzoomed_tiles.end(), tilecmp);
|
||||
overzoom_consumed_at_this_zoom = false;
|
||||
}
|
||||
|
||||
std::string get_tile(zxy tile) {
|
||||
std::string source;
|
||||
|
||||
if (db != NULL) {
|
||||
const char *sql = "SELECT tile_data from tiles where zoom_level = ? and tile_column = ? and tile_row = ?;";
|
||||
sqlite3_stmt *query;
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &query, NULL) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: select failed: %s\n", name.c_str(), sqlite3_errmsg(db));
|
||||
exit(EXIT_SQLITE);
|
||||
}
|
||||
|
||||
sqlite3_bind_int(query, 1, tile.z);
|
||||
sqlite3_bind_int(query, 2, tile.x);
|
||||
sqlite3_bind_int(query, 3, (1LL << tile.z) - 1 - tile.y);
|
||||
|
||||
if (sqlite3_step(query) == SQLITE_ROW) {
|
||||
const char *s = (const char *) sqlite3_column_blob(query, 0);
|
||||
size_t len = sqlite3_column_bytes(query, 0);
|
||||
|
||||
source = std::string(s, len);
|
||||
}
|
||||
|
||||
sqlite3_finalize(query);
|
||||
} else if (pmtiles_map != NULL) {
|
||||
uint64_t tile_offset;
|
||||
uint32_t tile_length;
|
||||
std::tie(tile_offset, tile_length) = pmtiles_get_tile(pmtiles_map, tile.z, tile.x, tile.y);
|
||||
if (tile_length > 0) {
|
||||
source = std::string(pmtiles_map + tile_offset, tile_length);
|
||||
}
|
||||
} else {
|
||||
source = dir_read_tile(dirbase, tile);
|
||||
}
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
// Sort in z/x/tms_y order, because that is the order of the
|
||||
// straightforward query of the mbtiles tiles table.
|
||||
bool operator<(const struct reader &r) const {
|
||||
// must match behavior of tilecmp
|
||||
|
||||
if (zoom < r.zoom) {
|
||||
return true;
|
||||
}
|
||||
@@ -407,10 +705,13 @@ struct reader {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sorty < r.sorty) {
|
||||
int sorty = (1LL << zoom) - 1 - y;
|
||||
int r_sorty = (1LL << r.zoom) - 1 - r.y;
|
||||
|
||||
if (sorty < r_sorty) {
|
||||
return true;
|
||||
}
|
||||
if (sorty > r.sorty) {
|
||||
if (sorty > r_sorty) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -420,99 +721,44 @@ struct reader {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string retrieve_overzoom(zxy tile) {
|
||||
// lock around sqlite3 access
|
||||
static pthread_mutex_t retrieve_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
zxy parent_tile = tile;
|
||||
while (parent_tile.z > maxzoom_so_far) {
|
||||
parent_tile.z--;
|
||||
parent_tile.x /= 2;
|
||||
parent_tile.y /= 2;
|
||||
}
|
||||
|
||||
if (pthread_mutex_lock(&retrieve_lock) != 0) {
|
||||
perror("pthread_mutex_lock");
|
||||
}
|
||||
|
||||
std::string source = get_tile(parent_tile);
|
||||
|
||||
if (pthread_mutex_unlock(&retrieve_lock) != 0) {
|
||||
perror("pthread_mutex_unlock");
|
||||
}
|
||||
|
||||
if (source.size() != 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
struct reader *begin_reading(char *fname) {
|
||||
struct reader *r = new reader;
|
||||
r->name = fname;
|
||||
struct stat st;
|
||||
if (stat(fname, &st) == 0 && (st.st_mode & S_IFDIR) != 0) {
|
||||
r->db = NULL;
|
||||
r->stmt = NULL;
|
||||
r->next = NULL;
|
||||
|
||||
r->dirtiles = enumerate_dirtiles(fname, minzoom, maxzoom);
|
||||
r->dirbase = fname;
|
||||
|
||||
if (r->dirtiles.size() == 0) {
|
||||
r->zoom = 32;
|
||||
} else {
|
||||
r->zoom = r->dirtiles[0].z;
|
||||
r->x = r->dirtiles[0].x;
|
||||
r->y = r->dirtiles[0].y;
|
||||
r->sorty = (1LL << r->zoom) - 1 - r->y;
|
||||
r->data = dir_read_tile(r->dirbase, r->dirtiles[0]);
|
||||
|
||||
r->dirtiles.erase(r->dirtiles.begin());
|
||||
}
|
||||
} else if (pmtiles_has_suffix(fname)) {
|
||||
int pmtiles_fd = open(fname, O_RDONLY | O_CLOEXEC);
|
||||
r->pmtiles_map = (char *) mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, pmtiles_fd, 0);
|
||||
|
||||
if (r->pmtiles_map == MAP_FAILED) {
|
||||
perror("mmap in decode");
|
||||
exit(EXIT_MEMORY);
|
||||
}
|
||||
if (close(pmtiles_fd) != 0) {
|
||||
perror("close");
|
||||
exit(EXIT_CLOSE);
|
||||
}
|
||||
|
||||
r->pmtiles_entries = pmtiles_entries_tms(r->pmtiles_map, minzoom, maxzoom);
|
||||
std::reverse(r->pmtiles_entries.begin(), r->pmtiles_entries.end());
|
||||
|
||||
if (r->pmtiles_entries.size() == 0) {
|
||||
r->zoom = 32;
|
||||
} else {
|
||||
r->zoom = r->pmtiles_entries.back().z;
|
||||
r->x = r->pmtiles_entries.back().x;
|
||||
r->y = r->pmtiles_entries.back().y;
|
||||
r->sorty = (1LL << r->zoom) - 1 - r->y;
|
||||
|
||||
r->data = std::string(r->pmtiles_map + r->pmtiles_entries.back().offset, r->pmtiles_entries.back().length);
|
||||
r->pmtiles_entries.pop_back();
|
||||
}
|
||||
} else {
|
||||
sqlite3 *db;
|
||||
|
||||
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
|
||||
exit(EXIT_SQLITE);
|
||||
}
|
||||
|
||||
char *err = NULL;
|
||||
if (sqlite3_exec(db, "PRAGMA integrity_check;", NULL, NULL, &err) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: integrity_check: %s\n", fname, err);
|
||||
exit(EXIT_SQLITE);
|
||||
}
|
||||
|
||||
const char *sql = "SELECT zoom_level, tile_column, tile_row, tile_data from tiles order by zoom_level, tile_column, tile_row;";
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
|
||||
exit(EXIT_SQLITE);
|
||||
}
|
||||
|
||||
r->db = db;
|
||||
r->stmt = stmt;
|
||||
r->next = NULL;
|
||||
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
r->zoom = sqlite3_column_int(stmt, 0);
|
||||
r->x = sqlite3_column_int(stmt, 1);
|
||||
r->sorty = sqlite3_column_int(stmt, 2);
|
||||
r->y = (1LL << r->zoom) - 1 - r->sorty;
|
||||
|
||||
const char *data = (const char *) sqlite3_column_blob(stmt, 3);
|
||||
size_t len = sqlite3_column_bytes(stmt, 3);
|
||||
|
||||
r->data = std::string(data, len);
|
||||
} else {
|
||||
r->zoom = 32;
|
||||
}
|
||||
}
|
||||
struct reader *r = new reader(fname);
|
||||
|
||||
// The reason this prefetches is so the reader queue can be
|
||||
// priority-ordered, so the one with the next relevant tile
|
||||
// is first in line.
|
||||
r->advance();
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -530,6 +776,7 @@ struct arg {
|
||||
std::set<std::string> *remove_layers = NULL;
|
||||
int ifmatched = 0;
|
||||
json_object *filter = NULL;
|
||||
struct reader *readers = NULL;
|
||||
};
|
||||
|
||||
void *join_worker(void *v) {
|
||||
@@ -539,7 +786,7 @@ void *join_worker(void *v) {
|
||||
mvt_tile tile;
|
||||
|
||||
for (size_t i = 0; i < ai->second.size(); i++) {
|
||||
handle(ai->second[i], ai->first.z, ai->first.x, ai->first.y, *(a->layermap), *(a->header), *(a->mapping), *(a->exclude), *(a->include), *(a->keep_layers), *(a->remove_layers), a->ifmatched, tile, a->filter);
|
||||
append_tile(ai->second[i], ai->first.z, ai->first.x, ai->first.y, *(a->layermap), *(a->header), *(a->mapping), *(a->exclude), *(a->include), *(a->keep_layers), *(a->remove_layers), a->ifmatched, tile, a->filter);
|
||||
}
|
||||
|
||||
ai->second.clear();
|
||||
@@ -574,7 +821,7 @@ void *join_worker(void *v) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void handle_tasks(std::map<zxy, std::vector<std::string>> &tasks, std::vector<std::map<std::string, layermap_entry>> &layermaps, sqlite3 *outdb, const char *outdir, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping, std::set<std::string> &exclude, std::set<std::string> &include, int ifmatched, std::set<std::string> &keep_layers, std::set<std::string> &remove_layers, json_object *filter) {
|
||||
void dispatch_tasks(std::map<zxy, std::vector<std::string>> &tasks, std::vector<std::map<std::string, layermap_entry>> &layermaps, sqlite3 *outdb, const char *outdir, std::vector<std::string> &header, std::map<std::string, std::vector<std::string>> &mapping, std::set<std::string> &exclude, std::set<std::string> &include, int ifmatched, std::set<std::string> &keep_layers, std::set<std::string> &remove_layers, json_object *filter, struct reader *readers) {
|
||||
pthread_t pthreads[CPUS];
|
||||
std::vector<arg> args;
|
||||
|
||||
@@ -590,6 +837,7 @@ void handle_tasks(std::map<zxy, std::vector<std::string>> &tasks, std::vector<st
|
||||
args[i].remove_layers = &remove_layers;
|
||||
args[i].ifmatched = ifmatched;
|
||||
args[i].filter = filter;
|
||||
args[i].readers = readers;
|
||||
}
|
||||
|
||||
size_t count = 0;
|
||||
@@ -736,22 +984,21 @@ void decode(struct reader *readers, std::map<std::string, layermap_entry> &layer
|
||||
double maxlon2 = INT_MIN;
|
||||
int zoom_for_bbox = -1;
|
||||
|
||||
while (readers != NULL && readers->zoom < 32) {
|
||||
reader *r = readers;
|
||||
readers = readers->next;
|
||||
r->next = NULL;
|
||||
if (r->zoom != zoom_for_bbox) {
|
||||
while (readers != NULL && !readers->all_done()) {
|
||||
std::pair<zxy, std::string> current = readers->current();
|
||||
|
||||
if (current.first.z != zoom_for_bbox) {
|
||||
// Only use highest zoom for bbox calculation
|
||||
// to avoid z0 always covering the world
|
||||
|
||||
minlat = minlon = minlon2 = INT_MAX;
|
||||
maxlat = maxlon = maxlon2 = INT_MIN;
|
||||
zoom_for_bbox = r->zoom;
|
||||
zoom_for_bbox = current.first.z;
|
||||
}
|
||||
|
||||
double lat1, lon1, lat2, lon2;
|
||||
tile2lonlat(r->x, r->y, r->zoom, &lon1, &lat1);
|
||||
tile2lonlat(r->x + 1, r->y + 1, r->zoom, &lon2, &lat2);
|
||||
tile2lonlat(current.first.x, current.first.y, current.first.z, &lon1, &lat1);
|
||||
tile2lonlat(current.first.x + 1, current.first.y + 1, current.first.z, &lon2, &lat2);
|
||||
minlat = min(lat2, minlat);
|
||||
minlon = min(lon1, minlon);
|
||||
maxlat = max(lat1, maxlat);
|
||||
@@ -765,63 +1012,37 @@ void decode(struct reader *readers, std::map<std::string, layermap_entry> &layer
|
||||
minlon2 = min(lon1, minlon2);
|
||||
maxlon2 = max(lon2, maxlon2);
|
||||
|
||||
if (r->zoom >= minzoom && r->zoom <= maxzoom) {
|
||||
zxy tile = zxy(r->zoom, r->x, r->y);
|
||||
if (current.first.z >= minzoom && current.first.z <= maxzoom) {
|
||||
zxy tile = current.first;
|
||||
if (tasks.count(tile) == 0) {
|
||||
tasks.insert(std::pair<zxy, std::vector<std::string>>(tile, std::vector<std::string>()));
|
||||
}
|
||||
auto f = tasks.find(tile);
|
||||
f->second.push_back(r->data);
|
||||
f->second.push_back(current.second);
|
||||
}
|
||||
|
||||
if (readers == NULL || readers->zoom != r->zoom || readers->x != r->x || readers->y != r->y) {
|
||||
if (readers == NULL || readers->zoom != current.first.z || readers->x != current.first.x || readers->y != current.first.y) {
|
||||
if (tasks.size() > 100 * CPUS) {
|
||||
handle_tasks(tasks, layermaps, outdb, outdir, header, mapping, exclude, include, ifmatched, keep_layers, remove_layers, filter);
|
||||
dispatch_tasks(tasks, layermaps, outdb, outdir, header, mapping, exclude, include, ifmatched, keep_layers, remove_layers, filter, readers);
|
||||
tasks.clear();
|
||||
}
|
||||
}
|
||||
|
||||
if (r->db != NULL) {
|
||||
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
|
||||
r->zoom = sqlite3_column_int(r->stmt, 0);
|
||||
r->x = sqlite3_column_int(r->stmt, 1);
|
||||
r->sorty = sqlite3_column_int(r->stmt, 2);
|
||||
r->y = (1LL << r->zoom) - 1 - r->sorty;
|
||||
const char *data = (const char *) sqlite3_column_blob(r->stmt, 3);
|
||||
size_t len = sqlite3_column_bytes(r->stmt, 3);
|
||||
// The reason this prefetches is so the reader queue can be
|
||||
// priority-ordered, so the one with the next relevant tile
|
||||
// is first in line.
|
||||
readers->advance();
|
||||
|
||||
r->data = std::string(data, len);
|
||||
} else {
|
||||
r->zoom = 32;
|
||||
}
|
||||
} else if (r->pmtiles_map != NULL) {
|
||||
if (r->pmtiles_entries.size() == 0) {
|
||||
r->zoom = 32;
|
||||
} else {
|
||||
r->zoom = r->pmtiles_entries.back().z;
|
||||
r->x = r->pmtiles_entries.back().x;
|
||||
r->y = r->pmtiles_entries.back().y;
|
||||
r->sorty = (1LL << r->zoom) - 1 - r->y;
|
||||
r->data = std::string(r->pmtiles_map + r->pmtiles_entries.back().offset, r->pmtiles_entries.back().length);
|
||||
// pull the reader off the front of the queue for reordering
|
||||
|
||||
r->pmtiles_entries.pop_back();
|
||||
}
|
||||
} else {
|
||||
if (r->dirtiles.size() == 0) {
|
||||
r->zoom = 32;
|
||||
} else {
|
||||
r->zoom = r->dirtiles[0].z;
|
||||
r->x = r->dirtiles[0].x;
|
||||
r->y = r->dirtiles[0].y;
|
||||
r->sorty = (1LL << r->zoom) - 1 - r->y;
|
||||
r->data = dir_read_tile(r->dirbase, r->dirtiles[0]);
|
||||
reader *r = readers;
|
||||
readers = readers->next;
|
||||
r->next = NULL;
|
||||
|
||||
r->dirtiles.erase(r->dirtiles.begin());
|
||||
}
|
||||
}
|
||||
// put the reader back onto the queue,
|
||||
// in whatever sequence its next tile calls for
|
||||
|
||||
struct reader **rr;
|
||||
|
||||
for (rr = &readers; *rr != NULL; rr = &((*rr)->next)) {
|
||||
if (*r < **rr) {
|
||||
break;
|
||||
@@ -842,72 +1063,66 @@ void decode(struct reader *readers, std::map<std::string, layermap_entry> &layer
|
||||
st->minlat2 = min(minlat, st->minlat2);
|
||||
st->maxlat2 = max(maxlat, st->maxlat2);
|
||||
|
||||
handle_tasks(tasks, layermaps, outdb, outdir, header, mapping, exclude, include, ifmatched, keep_layers, remove_layers, filter);
|
||||
dispatch_tasks(tasks, layermaps, outdb, outdir, header, mapping, exclude, include, ifmatched, keep_layers, remove_layers, filter, readers);
|
||||
layermap = merge_layermaps(layermaps);
|
||||
|
||||
struct reader *next;
|
||||
for (struct reader *r = readers; r != NULL; r = next) {
|
||||
next = r->next;
|
||||
r->close();
|
||||
|
||||
sqlite3 *db = r->db;
|
||||
if (r->pmtiles_map) {
|
||||
db = pmtilesmeta2tmp(r->name.c_str(), r->pmtiles_map);
|
||||
// json, strategies
|
||||
} else if (db == NULL) {
|
||||
db = dirmeta2tmp(r->dirbase.c_str());
|
||||
} else {
|
||||
sqlite3_finalize(r->stmt);
|
||||
}
|
||||
|
||||
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'minzoom'", -1, &r->stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
|
||||
int minz = max(sqlite3_column_int(r->stmt, 0), minzoom);
|
||||
sqlite3_stmt *stmt;
|
||||
if (sqlite3_prepare_v2(r->db, "SELECT value from metadata where name = 'minzoom'", -1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
int minz = max(sqlite3_column_int(stmt, 0), minzoom);
|
||||
st->minzoom = min(st->minzoom, minz);
|
||||
}
|
||||
sqlite3_finalize(r->stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'maxzoom'", -1, &r->stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
|
||||
int maxz = min(sqlite3_column_int(r->stmt, 0), maxzoom);
|
||||
if (sqlite3_prepare_v2(r->db, "SELECT value from metadata where name = 'maxzoom'", -1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
int maxz = min(sqlite3_column_int(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);
|
||||
}
|
||||
sqlite3_finalize(r->stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'center'", -1, &r->stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(r->stmt, 0);
|
||||
if (sqlite3_prepare_v2(r->db, "SELECT value from metadata where name = 'center'", -1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(stmt, 0);
|
||||
if (s != NULL) {
|
||||
sscanf((char *) s, "%lf,%lf", &st->midlon, &st->midlat);
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(r->stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'attribution'", -1, &r->stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(r->stmt, 0);
|
||||
if (sqlite3_prepare_v2(r->db, "SELECT value from metadata where name = 'attribution'", -1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(stmt, 0);
|
||||
if (s != NULL) {
|
||||
attribution = std::string((char *) s);
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(r->stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'description'", -1, &r->stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(r->stmt, 0);
|
||||
if (sqlite3_prepare_v2(r->db, "SELECT value from metadata where name = 'description'", -1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(stmt, 0);
|
||||
if (s != NULL) {
|
||||
description = std::string((char *) s);
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(r->stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'name'", -1, &r->stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(r->stmt, 0);
|
||||
if (sqlite3_prepare_v2(r->db, "SELECT value from metadata where name = 'name'", -1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(stmt, 0);
|
||||
if (s != NULL) {
|
||||
if (name.size() == 0) {
|
||||
name = std::string((char *) s);
|
||||
@@ -919,11 +1134,11 @@ void decode(struct reader *readers, std::map<std::string, layermap_entry> &layer
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(r->stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'bounds'", -1, &r->stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(r->stmt, 0);
|
||||
if (sqlite3_prepare_v2(r->db, "SELECT value from metadata where name = 'bounds'", -1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(stmt, 0);
|
||||
if (s != NULL) {
|
||||
if (sscanf((char *) s, "%lf,%lf,%lf,%lf", &minlon, &minlat, &maxlon, &maxlat) == 4) {
|
||||
st->minlon = min(minlon, st->minlon);
|
||||
@@ -933,11 +1148,11 @@ void decode(struct reader *readers, std::map<std::string, layermap_entry> &layer
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(r->stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'json'", -1, &r->stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(r->stmt, 0);
|
||||
if (sqlite3_prepare_v2(r->db, "SELECT value from metadata where name = 'json'", -1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(stmt, 0);
|
||||
|
||||
if (s != NULL) {
|
||||
json_pull *jp = json_begin_string((const char *) s);
|
||||
@@ -954,11 +1169,11 @@ void decode(struct reader *readers, std::map<std::string, layermap_entry> &layer
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_finalize(r->stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'generator_options'", -1, &r->stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(r->stmt, 0);
|
||||
if (sqlite3_prepare_v2(r->db, "SELECT value from metadata where name = 'generator_options'", -1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(stmt, 0);
|
||||
if (s != NULL) {
|
||||
if (generator_options.size() != 0) {
|
||||
generator_options.append("; ");
|
||||
@@ -968,19 +1183,19 @@ void decode(struct reader *readers, std::map<std::string, layermap_entry> &layer
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(r->stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
if (sqlite3_prepare_v2(db, "SELECT value from metadata where name = 'strategies'", -1, &r->stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(r->stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(r->stmt, 0);
|
||||
if (sqlite3_prepare_v2(r->db, "SELECT value from metadata where name = 'strategies'", -1, &stmt, NULL) == SQLITE_OK) {
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
const unsigned char *s = sqlite3_column_text(stmt, 0);
|
||||
handle_strategies(s, strategies);
|
||||
}
|
||||
sqlite3_finalize(r->stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
// Closes either real db or temp mirror of metadata.json
|
||||
if (sqlite3_close(db) != SQLITE_OK) {
|
||||
fprintf(stderr, "Could not close database: %s\n", sqlite3_errmsg(db));
|
||||
// Closes either real r->db or temp mirror of metadata.json
|
||||
if (sqlite3_close(r->db) != SQLITE_OK) {
|
||||
fprintf(stderr, "Could not close database: %s\n", sqlite3_errmsg(r->db));
|
||||
exit(EXIT_CLOSE);
|
||||
}
|
||||
|
||||
@@ -1029,6 +1244,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'},
|
||||
@@ -1094,6 +1311,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;
|
||||
@@ -1193,6 +1418,8 @@ int main(int argc, char **argv) {
|
||||
while (getline(read_file, sa)) {
|
||||
char *c = const_cast<char *>(sa.c_str());
|
||||
reader *r = begin_reading(c);
|
||||
|
||||
// put the new reader in priority order
|
||||
struct reader **rr;
|
||||
for (rr = &readers; *rr != NULL; rr = &((*rr)->next)) {
|
||||
if (*r < **rr) {
|
||||
@@ -1250,6 +1477,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);
|
||||
@@ -1278,8 +1510,9 @@ int main(int argc, char **argv) {
|
||||
if (filearg == 0) {
|
||||
for (i = optind; i < argc; i++) {
|
||||
reader *r = begin_reading(argv[i]);
|
||||
struct reader **rr;
|
||||
|
||||
// put the new reader in priority order
|
||||
struct reader **rr;
|
||||
for (rr = &readers; *rr != NULL; rr = &((*rr)->next)) {
|
||||
if (*r < **rr) {
|
||||
break;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -640,10 +640,6 @@ void *partial_feature_worker(void *v) {
|
||||
std::vector<drawvec> geoms; // artifact of former polygon-splitting to reduce geometric complexity
|
||||
geoms.push_back(geom);
|
||||
(*partials)[i].geoms = geoms;
|
||||
|
||||
if (t == VT_POLYGON && !prevent[P_POLYGON_SPLIT]) {
|
||||
geoms = chop_polygon(geoms);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@@ -2142,14 +2138,14 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
|
||||
add_sample_to(extents, sf.extent, extents_increment, seq);
|
||||
// search here is for LLONG_MAX, not minextent, because we are dropping features, not coalescing them,
|
||||
// so we shouldn't expect to find anything small that we can related this feature to.
|
||||
if (sf.extent + coalesced_area <= minextent && find_partial(partials, sf, which_partial, layer_unmaps, LLONG_MAX)) {
|
||||
if (minextent != 0 && sf.extent + coalesced_area <= minextent && find_partial(partials, sf, which_partial, layer_unmaps, LLONG_MAX)) {
|
||||
preserve_attributes(arg->attribute_accum, sf, stringpool, pool_off, partials[which_partial]);
|
||||
strategy->dropped_as_needed++;
|
||||
continue;
|
||||
}
|
||||
} else if (additional[A_COALESCE_SMALLEST_AS_NEEDED]) {
|
||||
add_sample_to(extents, sf.extent, extents_increment, seq);
|
||||
if (sf.extent + coalesced_area <= minextent && find_partial(partials, sf, which_partial, layer_unmaps, minextent)) {
|
||||
if (minextent != 0 && sf.extent + coalesced_area <= minextent && find_partial(partials, sf, which_partial, layer_unmaps, minextent)) {
|
||||
partials[which_partial].geoms.push_back(sf.geometry);
|
||||
partials[which_partial].coalesced = true;
|
||||
coalesced_area += sf.extent;
|
||||
@@ -2186,18 +2182,27 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
|
||||
}
|
||||
fraction_accum -= 1;
|
||||
|
||||
bool reduced = false;
|
||||
bool still_need_simplification_after_reduction = false;
|
||||
if (sf.t == VT_POLYGON) {
|
||||
if (!prevent[P_TINY_POLYGON_REDUCTION] && !additional[A_GRID_LOW_ZOOMS]) {
|
||||
sf.geometry = reduce_tiny_poly(sf.geometry, z, line_detail, &reduced, &accum_area, &sf, &tiny_feature);
|
||||
if (reduced) {
|
||||
bool simplified_away_by_reduction = false;
|
||||
|
||||
bool prevent_tiny = prevent[P_TINY_POLYGON_REDUCTION] ||
|
||||
(prevent[P_TINY_POLYGON_REDUCTION_AT_MAXZOOM] && z == maxzoom);
|
||||
if (!prevent_tiny && !additional[A_GRID_LOW_ZOOMS]) {
|
||||
sf.geometry = reduce_tiny_poly(sf.geometry, z, line_detail, &still_need_simplification_after_reduction, &simplified_away_by_reduction, &accum_area, &sf, &tiny_feature);
|
||||
if (simplified_away_by_reduction) {
|
||||
strategy->tiny_polygons++;
|
||||
}
|
||||
if (sf.geometry.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
still_need_simplification_after_reduction = true; // reduction skipped, so always simplify
|
||||
}
|
||||
} else {
|
||||
still_need_simplification_after_reduction = true; // not a polygon, so simplify
|
||||
}
|
||||
|
||||
if (sf.t == VT_POLYGON || sf.t == VT_LINE) {
|
||||
if (line_is_too_small(sf.geometry, z, line_detail)) {
|
||||
continue;
|
||||
@@ -2224,7 +2229,7 @@ long long write_tile(decompressor *geoms, std::atomic<long long> *geompos_in, ch
|
||||
p.t = sf.t;
|
||||
p.segment = sf.segment;
|
||||
p.original_seq = sf.seq;
|
||||
p.reduced = reduced;
|
||||
p.reduced = !still_need_simplification_after_reduction;
|
||||
p.coalesced = false;
|
||||
p.z = z;
|
||||
p.tx = tx;
|
||||
@@ -3203,6 +3208,7 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *stringpool, std::atomic<
|
||||
}
|
||||
|
||||
bool again = false;
|
||||
bool extend_zooms = false;
|
||||
for (size_t thread = 0; thread < threads; thread++) {
|
||||
void *retval;
|
||||
|
||||
@@ -3242,8 +3248,15 @@ 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) {
|
||||
extend_zooms = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (extend_zooms && (additional[A_EXTEND_ZOOMS] || extend_zooms_max > 0) && z == maxzoom && maxzoom < MAX_ZOOM) {
|
||||
maxzoom++;
|
||||
if (extend_zooms_max > 0) {
|
||||
extend_zooms_max--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#ifndef VERSION_HPP
|
||||
#define VERSION_HPP
|
||||
|
||||
#define VERSION "v2.29.0"
|
||||
#define VERSION "v2.31.0"
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user