mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-04 17:35:42 +02:00
Merge pull request #376 from mapbox/decode-layer
Add an option to decode only specified layers
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
## 1.16.10
|
||||||
|
|
||||||
|
* Add a tippecanoe-decode option to specify layer names
|
||||||
|
|
||||||
## 1.16.9
|
## 1.16.9
|
||||||
|
|
||||||
* Clean up layer name handling to fix layer merging crash
|
* Clean up layer name handling to fix layer merging crash
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ indent:
|
|||||||
TESTS = $(wildcard tests/*/out/*.json)
|
TESTS = $(wildcard tests/*/out/*.json)
|
||||||
SPACE = $(NULL) $(NULL)
|
SPACE = $(NULL) $(NULL)
|
||||||
|
|
||||||
test: tippecanoe tippecanoe-decode $(addsuffix .check,$(TESTS)) parallel-test pbf-test join-test enumerate-test unit
|
test: tippecanoe tippecanoe-decode $(addsuffix .check,$(TESTS)) parallel-test pbf-test join-test enumerate-test decode-test unit
|
||||||
./unit
|
./unit
|
||||||
|
|
||||||
# Work around Makefile and filename punctuation limits: _ for space, @ for :, % for /
|
# Work around Makefile and filename punctuation limits: _ for space, @ for :, % for /
|
||||||
@@ -111,6 +111,13 @@ parallel-test:
|
|||||||
cmp tests/parallel/linear-file.json tests/parallel/parallel-pipes.json
|
cmp tests/parallel/linear-file.json tests/parallel/parallel-pipes.json
|
||||||
rm tests/parallel/*.mbtiles tests/parallel/*.json
|
rm tests/parallel/*.mbtiles tests/parallel/*.json
|
||||||
|
|
||||||
|
decode-test:
|
||||||
|
mkdir -p tests/muni/decode
|
||||||
|
./tippecanoe -z11 -Z11 -f -o tests/muni/decode/multi.mbtiles tests/muni/*.json
|
||||||
|
./tippecanoe-decode -l subway tests/muni/decode/multi.mbtiles > tests/muni/decode/multi.mbtiles.json.check
|
||||||
|
cmp tests/muni/decode/multi.mbtiles.json.check tests/muni/decode/multi.mbtiles.json
|
||||||
|
rm -f tests/muni/decode/multi.mbtiles.json.check tests/muni/decode/multi.mbtiles
|
||||||
|
|
||||||
pbf-test:
|
pbf-test:
|
||||||
./tippecanoe-decode tests/pbf/11-328-791.vector.pbf 11 328 791 > tests/pbf/11-328-791.vector.pbf.out
|
./tippecanoe-decode tests/pbf/11-328-791.vector.pbf 11 328 791 > tests/pbf/11-328-791.vector.pbf.out
|
||||||
cmp tests/pbf/11-328-791.json tests/pbf/11-328-791.vector.pbf.out
|
cmp tests/pbf/11-328-791.json tests/pbf/11-328-791.vector.pbf.out
|
||||||
|
|||||||
@@ -411,3 +411,4 @@ resolutions.
|
|||||||
* -t _projection_: Specify the projection of the output data. Currently supported are EPSG:4326 (WGS84, the default) and EPSG:3857 (Web Mercator).
|
* -t _projection_: Specify the projection of the output data. Currently supported are EPSG:4326 (WGS84, the default) and EPSG:3857 (Web Mercator).
|
||||||
* -z _maxzoom_: Specify the highest zoom level to decode from the tileset
|
* -z _maxzoom_: Specify the highest zoom level to decode from the tileset
|
||||||
* -Z _minzoom_: Specify the lowest zoom level to decode from the tileset
|
* -Z _minzoom_: Specify the lowest zoom level to decode from the tileset
|
||||||
|
* -l _layer_: Decode only layers with the specified names. (Multiple `-l` options can be specified.)
|
||||||
|
|||||||
+22
-10
@@ -6,6 +6,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@@ -49,7 +50,7 @@ struct lonlat {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
void handle(std::string message, int z, unsigned x, unsigned y, int describe, std::set<std::string> const &to_decode) {
|
||||||
int within = 0;
|
int within = 0;
|
||||||
mvt_tile tile;
|
mvt_tile tile;
|
||||||
|
|
||||||
@@ -77,12 +78,17 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
|||||||
|
|
||||||
printf(", \"features\": [\n");
|
printf(", \"features\": [\n");
|
||||||
|
|
||||||
|
bool first_layer = true;
|
||||||
for (size_t l = 0; l < tile.layers.size(); l++) {
|
for (size_t l = 0; l < tile.layers.size(); l++) {
|
||||||
mvt_layer &layer = tile.layers[l];
|
mvt_layer &layer = tile.layers[l];
|
||||||
int extent = layer.extent;
|
int extent = layer.extent;
|
||||||
|
|
||||||
|
if (to_decode.size() != 0 && !to_decode.count(layer.name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (describe) {
|
if (describe) {
|
||||||
if (l != 0) {
|
if (!first_layer) {
|
||||||
printf(",\n");
|
printf(",\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,6 +99,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
|||||||
printf(" }");
|
printf(" }");
|
||||||
printf(", \"features\": [\n");
|
printf(", \"features\": [\n");
|
||||||
|
|
||||||
|
first_layer = false;
|
||||||
within = 0;
|
within = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,7 +340,7 @@ void handle(std::string message, int z, unsigned x, unsigned y, int describe) {
|
|||||||
printf("] }\n");
|
printf("] }\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void decode(char *fname, int z, unsigned x, unsigned y) {
|
void decode(char *fname, int z, unsigned x, unsigned y, std::set<std::string> const &to_decode) {
|
||||||
sqlite3 *db;
|
sqlite3 *db;
|
||||||
int oz = z;
|
int oz = z;
|
||||||
unsigned ox = x, oy = y;
|
unsigned ox = x, oy = y;
|
||||||
@@ -348,7 +355,7 @@ void decode(char *fname, int z, unsigned x, unsigned y) {
|
|||||||
if (strcmp(map, "SQLite format 3") != 0) {
|
if (strcmp(map, "SQLite format 3") != 0) {
|
||||||
if (z >= 0) {
|
if (z >= 0) {
|
||||||
std::string s = std::string(map, st.st_size);
|
std::string s = std::string(map, st.st_size);
|
||||||
handle(s, z, x, y, 1);
|
handle(s, z, x, y, 1, to_decode);
|
||||||
munmap(map, st.st_size);
|
munmap(map, st.st_size);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@@ -425,7 +432,7 @@ void decode(char *fname, int z, unsigned x, unsigned y) {
|
|||||||
ty = (1LL << tz) - 1 - ty;
|
ty = (1LL << tz) - 1 - ty;
|
||||||
const char *s = (const char *) sqlite3_column_blob(stmt, 0);
|
const char *s = (const char *) sqlite3_column_blob(stmt, 0);
|
||||||
|
|
||||||
handle(std::string(s, len), tz, tx, ty, 1);
|
handle(std::string(s, len), tz, tx, ty, 1, to_decode);
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("] }\n");
|
printf("] }\n");
|
||||||
@@ -453,7 +460,7 @@ void decode(char *fname, int z, unsigned x, unsigned y) {
|
|||||||
fprintf(stderr, "%s: Warning: using tile %d/%u/%u instead of %d/%u/%u\n", fname, z, x, y, oz, ox, oy);
|
fprintf(stderr, "%s: Warning: using tile %d/%u/%u instead of %d/%u/%u\n", fname, z, x, y, oz, ox, oy);
|
||||||
}
|
}
|
||||||
|
|
||||||
handle(std::string(s, len), z, x, y, 0);
|
handle(std::string(s, len), z, x, y, 0, to_decode);
|
||||||
handled = 1;
|
handled = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,7 +479,7 @@ void decode(char *fname, int z, unsigned x, unsigned y) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void usage(char **argv) {
|
void usage(char **argv) {
|
||||||
fprintf(stderr, "Usage: %s [-t projection] [-Z minzoom] [-z maxzoom] file.mbtiles [zoom x y]\n", argv[0]);
|
fprintf(stderr, "Usage: %s [-t projection] [-Z minzoom] [-z maxzoom] [-l layer ...] file.mbtiles [zoom x y]\n", argv[0]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,8 +487,9 @@ int main(int argc, char **argv) {
|
|||||||
extern int optind;
|
extern int optind;
|
||||||
extern char *optarg;
|
extern char *optarg;
|
||||||
int i;
|
int i;
|
||||||
|
std::set<std::string> to_decode;
|
||||||
|
|
||||||
while ((i = getopt(argc, argv, "t:Z:z:")) != -1) {
|
while ((i = getopt(argc, argv, "t:Z:z:l:")) != -1) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 't':
|
case 't':
|
||||||
set_projection_or_exit(optarg);
|
set_projection_or_exit(optarg);
|
||||||
@@ -495,15 +503,19 @@ int main(int argc, char **argv) {
|
|||||||
minzoom = atoi(optarg);
|
minzoom = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
to_decode.insert(optarg);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage(argv);
|
usage(argv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc == optind + 4) {
|
if (argc == optind + 4) {
|
||||||
decode(argv[optind], atoi(argv[optind + 1]), atoi(argv[optind + 2]), atoi(argv[optind + 3]));
|
decode(argv[optind], atoi(argv[optind + 1]), atoi(argv[optind + 2]), atoi(argv[optind + 3]), to_decode);
|
||||||
} else if (argc == optind + 1) {
|
} else if (argc == optind + 1) {
|
||||||
decode(argv[optind], -1, -1, -1);
|
decode(argv[optind], -1, -1, -1, to_decode);
|
||||||
} else {
|
} else {
|
||||||
usage(argv);
|
usage(argv);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -484,4 +484,6 @@ resolutions.
|
|||||||
\-z \fImaxzoom\fP: Specify the highest zoom level to decode from the tileset
|
\-z \fImaxzoom\fP: Specify the highest zoom level to decode from the tileset
|
||||||
.IP \(bu 2
|
.IP \(bu 2
|
||||||
\-Z \fIminzoom\fP: Specify the lowest zoom level to decode from the tileset
|
\-Z \fIminzoom\fP: Specify the lowest zoom level to decode from the tileset
|
||||||
|
.IP \(bu 2
|
||||||
|
\-l \fIlayer\fP: Decode only layers with the specified names. (Multiple \fB\fC\-l\fR options can be specified.)
|
||||||
.RE
|
.RE
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
{ "type": "FeatureCollection", "properties": {
|
||||||
|
"bounds": "-122.538670,37.705764,-12.240000,37.836443",
|
||||||
|
"center": "-122.431641,37.788049,11",
|
||||||
|
"description": "tests/muni/decode/multi.mbtiles",
|
||||||
|
"format": "pbf",
|
||||||
|
"json": "{\"vector_layers\": [ { \"id\": \"muni\", \"description\": \"\", \"minzoom\": 11, \"maxzoom\": 11, \"fields\": {\"name\": \"String\"} }, { \"id\": \"subway\", \"description\": \"\", \"minzoom\": 11, \"maxzoom\": 11, \"fields\": {\"name\": \"String\"} } ] }",
|
||||||
|
"maxzoom": "11",
|
||||||
|
"minzoom": "11",
|
||||||
|
"name": "tests/muni/decode/multi.mbtiles",
|
||||||
|
"type": "overlay",
|
||||||
|
"version": "2"
|
||||||
|
}, "features": [
|
||||||
|
{ "type": "FeatureCollection", "properties": { "zoom": 11, "x": 326, "y": 791 }, "features": [
|
||||||
|
] }
|
||||||
|
,
|
||||||
|
{ "type": "FeatureCollection", "properties": { "zoom": 11, "x": 327, "y": 792 }, "features": [
|
||||||
|
] }
|
||||||
|
,
|
||||||
|
{ "type": "FeatureCollection", "properties": { "zoom": 11, "x": 327, "y": 791 }, "features": [
|
||||||
|
{ "type": "FeatureCollection", "properties": { "layer": "subway", "version": 2, "extent": 4096 }, "features": [
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Castro Station/Outbound" }, "geometry": { "type": "Point", "coordinates": [ -122.435331, 37.762708 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Castro Station/Downtown" }, "geometry": { "type": "Point", "coordinates": [ -122.435246, 37.762641 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Forest Hill Station/Downtown" }, "geometry": { "type": "Point", "coordinates": [ -122.458634, 37.748356 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Montgomery Station/Outbound" }, "geometry": { "type": "Point", "coordinates": [ -122.402158, 37.788794 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Montgomery Station/Downtown" }, "geometry": { "type": "Point", "coordinates": [ -122.401943, 37.788726 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Embarcadero Station/Downtown" }, "geometry": { "type": "Point", "coordinates": [ -122.396579, 37.793033 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Embarcadero Station" }, "geometry": { "type": "Point", "coordinates": [ -122.396450, 37.793168 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Embarcadero Station" }, "geometry": { "type": "Point", "coordinates": [ -122.396407, 37.793168 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Civic Center Station/Downtown" }, "geometry": { "type": "Point", "coordinates": [ -122.412543, 37.780348 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Van Ness Station Outbound" }, "geometry": { "type": "Point", "coordinates": [ -122.419367, 37.775260 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Van Ness Station/Outbound" }, "geometry": { "type": "Point", "coordinates": [ -122.419281, 37.775159 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Van Ness Station" }, "geometry": { "type": "Point", "coordinates": [ -122.419195, 37.775091 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Van Ness Station/Downtown" }, "geometry": { "type": "Point", "coordinates": [ -122.419281, 37.775057 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Civic Center Station/Outbd" }, "geometry": { "type": "Point", "coordinates": [ -122.415032, 37.778686 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Civic Center Station/Downtn" }, "geometry": { "type": "Point", "coordinates": [ -122.414818, 37.778551 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Church Station/Outbound" }, "geometry": { "type": "Point", "coordinates": [ -122.429323, 37.767356 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Church Station/Downtown" }, "geometry": { "type": "Point", "coordinates": [ -122.429194, 37.767221 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Powell Station/Outbound" }, "geometry": { "type": "Point", "coordinates": [ -122.407823, 37.784317 ] } }
|
||||||
|
,
|
||||||
|
{ "type": "Feature", "properties": { "name": "Metro Powell Station/Downtown" }, "geometry": { "type": "Point", "coordinates": [ -122.407737, 37.784215 ] } }
|
||||||
|
] }
|
||||||
|
] }
|
||||||
|
,
|
||||||
|
{ "type": "FeatureCollection", "properties": { "zoom": 11, "x": 954, "y": 791 }, "features": [
|
||||||
|
] }
|
||||||
|
] }
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
#define VERSION "tippecanoe v1.16.9\n"
|
#define VERSION "tippecanoe v1.16.10\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user