From d960963623a871599d6bfe42cb6a89727c4c3015 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Tue, 22 Mar 2016 16:50:01 -0700 Subject: [PATCH] Add the ability to tippecanoe-decode a standalone .pbf tile --- CHANGELOG.md | 4 ++++ README.md | 1 + decode.cc | 27 +++++++++++++++++++++++++++ man/tippecanoe.1 | 1 + version.h | 2 +- 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0c252c..eebed5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index b46b31f..03f8755 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/decode.cc b/decode.cc index 2fc6eae..e0ced1d 100644 --- a/decode.cc +++ b/decode.cc @@ -5,6 +5,9 @@ #include #include #include +#include +#include +#include #include #include #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); diff --git a/man/tippecanoe.1 b/man/tippecanoe.1 index 1dd9ab5..762d3a2 100644 --- a/man/tippecanoe.1 +++ b/man/tippecanoe.1 @@ -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 diff --git a/version.h b/version.h index 1966d93..4c2bdf0 100644 --- a/version.h +++ b/version.h @@ -1 +1 @@ -#define VERSION "tippecanoe v1.9.3\n" +#define VERSION "tippecanoe v1.9.4\n"