mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-03-23 04:15:15 +00:00
Add the ability to tippecanoe-decode a standalone .pbf tile
This commit is contained in:
parent
7140a3dd91
commit
d960963623
@ -1,3 +1,7 @@
|
||||
## 1.9.4
|
||||
|
||||
* Tippecanoe-decode can decode .pbf files that aren't in an .mbtiles container
|
||||
|
||||
## 1.9.3
|
||||
|
||||
* Don't get stuck in a loop trying to split up very small, very complicated polygons
|
||||
|
@ -338,6 +338,7 @@ on an entire file:
|
||||
or on an individual tile:
|
||||
|
||||
tippecanoe-decode file.mbtiles zoom x y
|
||||
tippecanoe-decode file.vector.pbf zoom x y
|
||||
|
||||
If you decode an entire file, you get a nested `FeatureCollection` identifying each
|
||||
tile and layer separately. Note that the same features generally appear at all zooms,
|
||||
|
27
decode.cc
27
decode.cc
@ -5,6 +5,9 @@
|
||||
#include <string>
|
||||
#include <zlib.h>
|
||||
#include <math.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/mman.h>
|
||||
#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include "vector_tile.pb.h"
|
||||
@ -359,6 +362,30 @@ void decode(char *fname, int z, unsigned x, unsigned y) {
|
||||
int oz = z;
|
||||
unsigned ox = x, oy = y;
|
||||
|
||||
int fd = open(fname, O_RDONLY);
|
||||
if (fd >= 0) {
|
||||
struct stat st;
|
||||
if (fstat(fd, &st) == 0) {
|
||||
if (st.st_size < 50 * 1024 * 1024) {
|
||||
char *map = (char *) mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (map != NULL && map != MAP_FAILED) {
|
||||
if (strcmp(map, "SQLite format 3") != 0) {
|
||||
std::string s = std::string(map, st.st_size);
|
||||
handle(s, z, x, y, 1);
|
||||
munmap(map, st.st_size);
|
||||
return;
|
||||
}
|
||||
}
|
||||
munmap(map, st.st_size);
|
||||
}
|
||||
} else {
|
||||
perror("fstat");
|
||||
}
|
||||
close(fd);
|
||||
} else {
|
||||
perror(fname);
|
||||
}
|
||||
|
||||
if (sqlite3_open(fname, &db) != SQLITE_OK) {
|
||||
fprintf(stderr, "%s: %s\n", fname, sqlite3_errmsg(db));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -399,6 +399,7 @@ or on an individual tile:
|
||||
.RS
|
||||
.nf
|
||||
tippecanoe\-decode file.mbtiles zoom x y
|
||||
tippecanoe\-decode file.vector.pbf zoom x y
|
||||
.fi
|
||||
.RE
|
||||
.PP
|
||||
|
Loading…
x
Reference in New Issue
Block a user