From a3202488570ef0be4ae443df897c26f5f21d1c60 Mon Sep 17 00:00:00 2001 From: Shan-Chun Kuo Date: Fri, 7 Apr 2017 13:33:01 +0100 Subject: [PATCH] Do make indent, add flag --output-to-directory or -e to write pbf files to a directory, also add flag --no-tile-compression or -pC to get raw protobuf --- Makefile | 2 +- main.cpp | 23 ++++++++++++++--------- main.hpp | 2 +- options.hpp | 2 +- rawtiles.cpp | 6 +++--- tile.cpp | 12 ++++++------ 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 3be98a6..f9d032b 100644 --- a/Makefile +++ b/Makefile @@ -112,7 +112,7 @@ parallel-test: rm tests/parallel/*.mbtiles tests/parallel/*.json raw-tiles-test: - ./tippecanoe -o tests/raw-tiles/raw-tiles tests/raw-tiles/hackspots.geojson --raw-tiles + ./tippecanoe -e tests/raw-tiles/raw-tiles tests/raw-tiles/hackspots.geojson -pC diff -x '.*' -rq tests/raw-tiles/raw-tiles tests/raw-tiles/compare rm -rf tests/raw-tiles/raw-tiles diff --git a/main.cpp b/main.cpp index 4b85373..b4566f8 100644 --- a/main.cpp +++ b/main.cpp @@ -57,6 +57,7 @@ static int full_detail = -1; static int min_detail = 7; int quiet = 0; +int outdirtable = 0; int geometry_scale = 0; double simplification = 1; size_t max_tile_size = 500000; @@ -1846,7 +1847,7 @@ int read_input(std::vector &sources, char *fname, int maxzoom, int minzo ai->second.maxzoom = maxzoom; } - if(!prevent[P_PBF_COMPRESSION]) + if (!outdirtable) mbtiles_write_metadata(outdb, fname, minzoom, maxzoom, minlat, minlon, maxlat, maxlon, midlat, midlon, forcetable, attribution, merged_lm, true, description); return ret; @@ -1903,6 +1904,7 @@ int main(int argc, char **argv) { static struct option long_options[] = { {"output", required_argument, 0, 'o'}, + {"output-to-directory", required_argument, 0, 'e'}, {"name", required_argument, 0, 'n'}, {"description", required_argument, 0, 'N'}, @@ -1960,7 +1962,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}, + {"no-tile-compression", no_argument, &prevent[P_TILE_COMPRESSION], 1}, {0, 0, 0, 0}, }; @@ -1983,7 +1985,7 @@ int main(int argc, char **argv) { } } - while ((i = getopt_long(argc, argv, "n:l:z:Z:B:d:D:m:o:x:y:r:b:t:g:p:a:XfFqvPL:A:s:S:M:N:", long_options, NULL)) != -1) { + while ((i = getopt_long(argc, argv, "n:l:z:Z:B:d:D:m:o:e:x:y:r:b:t:g:p:a:XfFqvPL:A:s:S:M:N:", long_options, NULL)) != -1) { switch (i) { case 0: break; @@ -2063,6 +2065,11 @@ int main(int argc, char **argv) { outdir = optarg; break; + case 'e': + outpbfdir = optarg; + outdirtable = 1; + break; + case 'x': exclude.insert(std::string(optarg)); break; @@ -2244,8 +2251,8 @@ int main(int argc, char **argv) { fprintf(stderr, "Forcing -g0 since -B or -r is not known\n"); } - if (outdir == NULL) { - fprintf(stderr, "%s: must specify -o out.mbtiles\n", argv[0]); + if (outdir == NULL && outpbfdir == NULL) { + fprintf(stderr, "%s: must specify -o out.mbtiles or -e directory\n", argv[0]); exit(EXIT_FAILURE); } @@ -2253,10 +2260,8 @@ int main(int argc, char **argv) { unlink(outdir); } - if(!prevent[P_PBF_COMPRESSION]){ + if (!outdirtable) { outdb = mbtiles_open(outdir, argv, forcetable); - }else{ - outpbfdir = outdir; } int ret = EXIT_SUCCESS; @@ -2285,7 +2290,7 @@ 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); - if(!prevent[P_PBF_COMPRESSION]) + if (!outdirtable) mbtiles_close(outdb, argv); #ifdef MTRACE diff --git a/main.hpp b/main.hpp index d61c6de..f1df878 100644 --- a/main.hpp +++ b/main.hpp @@ -11,7 +11,7 @@ void checkdisk(struct reader *r, int nreader); extern int geometry_scale; extern int quiet; - +extern int outdirtable; extern char *outpbfdir; extern size_t CPUS; diff --git a/options.hpp b/options.hpp index 97bda01..6081d7d 100644 --- a/options.hpp +++ b/options.hpp @@ -25,7 +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') +#define P_TILE_COMPRESSION ((int) 'C') extern int prevent[256]; extern int additional[256]; diff --git a/rawtiles.cpp b/rawtiles.cpp index ced397a..1de0dec 100644 --- a/rawtiles.cpp +++ b/rawtiles.cpp @@ -7,14 +7,14 @@ void write_raw_tile(char *outdir, int z, int tx, int ty, std::string pbf) { mkdir(outdir, S_IRWXU | S_IRWXG | S_IRWXO); std::string curdir(outdir); - std::string slash( "/" ); + 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::binary); - pbfFile.write (pbf.data(), pbf.size()); + std::ofstream pbfFile(newdir, std::ios::out | std::ios::binary); + pbfFile.write(pbf.data(), pbf.size()); pbfFile.close(); } \ No newline at end of file diff --git a/tile.cpp b/tile.cpp index 521cdd3..ecac670 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1841,9 +1841,9 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s std::string compressed; std::string pbf = tile.encode(); - if(!prevent[P_PBF_COMPRESSION]){ + if (!prevent[P_TILE_COMPRESSION]) { compress(pbf, compressed); - }else{ + } else { compressed = pbf; } @@ -1917,10 +1917,10 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s exit(EXIT_FAILURE); } - if(!prevent[P_PBF_COMPRESSION]){ - mbtiles_write_tile(outdb, z, tx, ty, compressed.data(), compressed.size()); - }else{ - write_raw_tile(outpbfdir, z, tx, ty, pbf); + if (!outdirtable) { + mbtiles_write_tile(outdb, z, tx, ty, compressed.data(), compressed.size()); + } else { + write_raw_tile(outpbfdir, z, tx, ty, compressed); } if (pthread_mutex_unlock(&db_lock) != 0) {