Add the ability to tippecanoe-decode a standalone .pbf tile

This commit is contained in:
Eric Fischer 2016-03-22 16:50:01 -07:00
parent 7140a3dd91
commit d960963623
5 changed files with 34 additions and 1 deletions

View File

@ -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

View File

@ -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,

View File

@ -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);

View File

@ -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

View File

@ -1 +1 @@
#define VERSION "tippecanoe v1.9.3\n"
#define VERSION "tippecanoe v1.9.4\n"