From aee12ac1fed0ad4f913c037e9ab400a6965869aa Mon Sep 17 00:00:00 2001 From: Shan-Chun Kuo Date: Wed, 5 Apr 2017 00:34:54 +0100 Subject: [PATCH] Add flag --raw-tiles or -pC to get raw protobuf --- main.cpp | 18 +++++++++++++++--- main.hpp | 2 ++ mvt.cpp | 5 +---- options.hpp | 1 + tile.cpp | 26 ++++++++++++++++++++++++-- 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index 418ea7f..b2584d6 100644 --- a/main.cpp +++ b/main.cpp @@ -69,6 +69,8 @@ struct source { std::string file; }; +char *outpbfdir; + size_t CPUS; size_t TEMP_FILES; long long MAX_FILES; @@ -1843,7 +1845,9 @@ int read_input(std::vector &sources, char *fname, int maxzoom, int minzo ai->second.minzoom = minzoom; ai->second.maxzoom = maxzoom; } - mbtiles_write_metadata(outdb, fname, minzoom, maxzoom, minlat, minlon, maxlat, maxlon, midlat, midlon, forcetable, attribution, merged_lm, true, description); + + if(!prevent[P_PBF_COMPRESSION]) + mbtiles_write_metadata(outdb, fname, minzoom, maxzoom, minlat, minlon, maxlat, maxlon, midlat, midlon, forcetable, attribution, merged_lm, true, description); return ret; } @@ -1873,6 +1877,7 @@ int main(int argc, char **argv) { char *description = NULL; char *layername = NULL; char *outdir = NULL; + sqlite3 *outdb = NULL; int maxzoom = 14; int minzoom = 0; int basezoom = -1; @@ -1955,6 +1960,7 @@ int main(int argc, char **argv) { {"no-clipping", no_argument, &prevent[P_CLIPPING], 1}, {"no-duplication", no_argument, &prevent[P_DUPLICATION], 1}, {"no-tiny-polygon-reduction", no_argument, &prevent[P_TINY_POLYGON_REDUCTION], 1}, + {"raw-tiles", no_argument, &prevent[P_PBF_COMPRESSION], 1}, {0, 0, 0, 0}, }; @@ -2247,7 +2253,12 @@ int main(int argc, char **argv) { unlink(outdir); } - sqlite3 *outdb = mbtiles_open(outdir, argv, forcetable); + if(!prevent[P_PBF_COMPRESSION]){ + outdb = mbtiles_open(outdir, argv, forcetable); + }else{ + outpbfdir = outdir; + } + int ret = EXIT_SUCCESS; for (i = optind; i < argc; i++) { @@ -2274,7 +2285,8 @@ int main(int argc, char **argv) { ret = read_input(sources, name ? name : outdir, maxzoom, minzoom, basezoom, basezoom_marker_width, outdb, &exclude, &include, exclude_all, droprate, buffer, tmpdir, gamma, read_parallel, forcetable, attribution, gamma != 0, file_bbox, description); - mbtiles_close(outdb, argv); + if(!prevent[P_PBF_COMPRESSION]) + mbtiles_close(outdb, argv); #ifdef MTRACE muntrace(); diff --git a/main.hpp b/main.hpp index e06908b..d61c6de 100644 --- a/main.hpp +++ b/main.hpp @@ -12,6 +12,8 @@ void checkdisk(struct reader *r, int nreader); extern int geometry_scale; extern int quiet; +extern char *outpbfdir; + extern size_t CPUS; extern size_t TEMP_FILES; diff --git a/mvt.cpp b/mvt.cpp index f11164b..22198e9 100644 --- a/mvt.cpp +++ b/mvt.cpp @@ -367,10 +367,7 @@ std::string mvt_tile::encode() { writer.add_message(3, layer_string); } - std::string compressed; - compress(data, compressed); - - return compressed; + return data; } bool mvt_value::operator<(const mvt_value &o) const { diff --git a/options.hpp b/options.hpp index 4079369..97bda01 100644 --- a/options.hpp +++ b/options.hpp @@ -25,6 +25,7 @@ #define P_CLIPPING ((int) 'c') #define P_DUPLICATION ((int) 'D') #define P_TINY_POLYGON_REDUCTION ((int) 't') +#define P_PBF_COMPRESSION ((int) 'C') extern int prevent[256]; extern int additional[256]; diff --git a/tile.cpp b/tile.cpp index f972327..317295d 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1837,7 +1837,14 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s } } - std::string compressed = tile.encode(); + std::string compressed; + std::string pbf = tile.encode(); + + if(!prevent[P_PBF_COMPRESSION]){ + compress(pbf, compressed); + }else{ + compressed = pbf; + } if (compressed.size() > max_tile_size && !prevent[P_KILOBYTE_LIMIT]) { if (!quiet) { @@ -1909,7 +1916,22 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s exit(EXIT_FAILURE); } - mbtiles_write_tile(outdb, z, tx, ty, compressed.data(), compressed.size()); + if(!prevent[P_PBF_COMPRESSION]){ + mbtiles_write_tile(outdb, z, tx, ty, compressed.data(), compressed.size()); + }else{ + mkdir(outpbfdir, S_IRWXU | S_IRWXG | S_IRWXO); + std::string curdir(outpbfdir); + std::string slash( "/" ); + std::string newdir = curdir + slash + std::to_string(z); + mkdir(newdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); + newdir = newdir + "/" + std::to_string(tx); + mkdir(newdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO); + newdir = newdir + "/" + std::to_string(ty) + ".pbf"; + + std::ofstream pbfFile (newdir, std::ios::out | std::ios::app | std::ios::binary); + pbfFile.write (pbf.data(), pbf.size()); + pbfFile.close(); + } if (pthread_mutex_unlock(&db_lock) != 0) { perror("pthread_mutex_unlock");