From 138699d243483b2907ae480fd1d063938fb0e2a6 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Wed, 8 Jul 2015 15:06:21 -0700 Subject: [PATCH] Add option to quiet the chatty progress indicators --- README.md | 1 + geojson.c | 39 ++++++++++++++++++++++++++++++--------- man/tippecanoe.1 | 4 +++- tile.cc | 16 ++++++++++++---- tile.h | 1 + 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 5e8782c..c92b533 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ Options * -po: Don't reorder features to put the same properties in sequence * -pl: Let "dot" simplification apply to lines too * -pd: Dynamically drop some fraction of features from large tiles to keep them under the 500K size limit. It will probably look ugly at the tile boundaries. + * -q: Work quietly instead of reporting progress Example ------- diff --git a/geojson.c b/geojson.c index 4091e37..f432ad0 100644 --- a/geojson.c +++ b/geojson.c @@ -25,6 +25,7 @@ int low_detail = 10; int full_detail = -1; int min_detail = 7; +int quiet = 0; unsigned initial_x = 0, initial_y = 0; int geometry_scale = 0; @@ -297,7 +298,9 @@ static void merge(struct merge *merges, int nmerges, unsigned char *map, FILE *f along++; long long report = 100 * along / nrec; if (report != reported) { - fprintf(stderr, "Merging: %lld%%\r", report); + if (!quiet) { + fprintf(stderr, "Merging: %lld%%\r", report); + } reported = report; } } @@ -705,7 +708,9 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max } if (seq % 10000 == 0) { - fprintf(stderr, "Read %.2f million features\r", seq / 1000000.0); + if (!quiet) { + fprintf(stderr, "Read %.2f million features\r", seq / 1000000.0); + } } seq++; } @@ -794,7 +799,9 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max } *out = '\0'; - printf("using layer %d name %s\n", i, trunc); + if (!quiet) { + printf("using layer %d name %s\n", i, trunc); + } } } @@ -802,7 +809,9 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max { int bytes = sizeof(struct index); - fprintf(stderr, "Sorting %lld features\n", (long long) indexpos / bytes); + if (!quiet) { + fprintf(stderr, "Sorting %lld features\n", (long long) indexpos / bytes); + } int page = sysconf(_SC_PAGESIZE); long long unit = (50 * 1024 * 1024 / bytes) * bytes; @@ -821,7 +830,9 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max } if (nmerges != 1) { - fprintf(stderr, "Sorting part %lld of %d\r", start / unit + 1, nmerges); + if (!quiet) { + fprintf(stderr, "Sorting part %lld of %d\r", start / unit + 1, nmerges); + } } merges[start / unit].start = start; @@ -853,7 +864,9 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max } if (nmerges != 1) { - fprintf(stderr, "\n"); + if (!quiet) { + fprintf(stderr, "\n"); + } } void *map = mmap(NULL, indexpos, PROT_READ, MAP_PRIVATE, indexfd, 0); @@ -927,7 +940,9 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max long long p = 1000 * i / (indexpos / sizeof(struct index)); if (p != progress) { - fprintf(stderr, "Reordering geometry: %3.1f%%\r", p / 10.0); + if (!quiet) { + fprintf(stderr, "Reordering geometry: %3.1f%%\r", p / 10.0); + } progress = p; } } @@ -972,7 +987,9 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max size[j] = 0; } - fprintf(stderr, "%lld features, %lld bytes of geometry, %lld bytes of metadata, %lld bytes of string pool\n", seq, (long long) geomst.st_size, (long long) metast.st_size, poolfile->off); + if (!quiet) { + fprintf(stderr, "%lld features, %lld bytes of geometry, %lld bytes of metadata, %lld bytes of string pool\n", seq, (long long) geomst.st_size, (long long) metast.st_size, poolfile->off); + } int written = traverse_zooms(fd, size, meta, stringpool, file_bbox, file_keys, &midx, &midy, layernames, maxzoom, minzoom, outdb, droprate, buffer, fname, tmpdir, gamma, nlayers, prevent, full_detail, low_detail, min_detail); @@ -1052,7 +1069,7 @@ int main(int argc, char **argv) { prevent[i] = 0; } - while ((i = getopt(argc, argv, "l:n:z:Z:d:D:m:o:x:y:r:b:fXt:g:p:v")) != -1) { + while ((i = getopt(argc, argv, "l:n:z:Z:d:D:m:o:x:y:r:b:fXt:g:p:vq")) != -1) { switch (i) { case 'n': name = optarg; @@ -1119,6 +1136,10 @@ int main(int argc, char **argv) { gamma = atof(optarg); break; + case 'q': + quiet = 1; + break; + case 'p': { char *cp; for (cp = optarg; *cp != '\0'; cp++) { diff --git a/man/tippecanoe.1 b/man/tippecanoe.1 index d1072a3..9fdbfc3 100644 --- a/man/tippecanoe.1 +++ b/man/tippecanoe.1 @@ -78,7 +78,7 @@ it encounters. .IP \(bu 2 \-m \fIdetail\fP: Minimum detail that it will try if tiles are too big at regular detail (default 7) .IP \(bu 2 -\-b \fIpixels\fP: Buffer size where features are duplicated from adjacent tiles (default 5) +\-b \fIpixels\fP: Buffer size where features are duplicated from adjacent tiles. Units are "screen pixels"\-\-1/256th of the tile width or height. (default 5) .RE .SS Properties .RS @@ -114,6 +114,8 @@ it encounters. \-pl: Let "dot" simplification apply to lines too .IP \(bu 2 \-pd: Dynamically drop some fraction of features from large tiles to keep them under the 500K size limit. It will probably look ugly at the tile boundaries. +.IP \(bu 2 +\-q: Work quietly instead of reporting progress .RE .SH Example .PP diff --git a/tile.cc b/tile.cc index ec27700..1d5d8d2 100644 --- a/tile.cc +++ b/tile.cc @@ -529,7 +529,9 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, unsigned *f double progress = floor((((*geoms - geomstart + along) / (double) todo) + z) / (file_maxzoom + 1) * 1000) / 10; if (progress != oprogress) { - fprintf(stderr, " %3.1f%% %d/%u/%u \r", progress, z, tx, ty); + if (!quiet) { + fprintf(stderr, " %3.1f%% %d/%u/%u \r", progress, z, tx, ty); + } oprogress = progress; } @@ -748,7 +750,9 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, unsigned *f compress(s, compressed); if (compressed.size() > 500000 && !prevent['k' & 0xFF]) { - fprintf(stderr, "tile %d/%u/%u size is %lld with detail %d, >500000 \n", z, tx, ty, (long long) compressed.size(), line_detail); + if (!quiet) { + fprintf(stderr, "tile %d/%u/%u size is %lld with detail %d, >500000 \n", z, tx, ty, (long long) compressed.size(), line_detail); + } if (line_detail == min_detail || !evaluated) { evaluated = true; @@ -762,7 +766,9 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, unsigned *f // and probably actually varies based on how much duplicated metadata there is fraction = fraction * 500000 / compressed.size() * 0.95; - fprintf(stderr, "Going to try keeping %0.2f%% of the features to make it fit\n", fraction * 100); + if (!quiet) { + fprintf(stderr, "Going to try keeping %0.2f%% of the features to make it fit\n", fraction * 100); + } line_detail++; // to keep it the same when the loop decrements it } } else { @@ -873,6 +879,8 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo } } - fprintf(stderr, "\n"); + if (!quiet) { + fprintf(stderr, "\n"); + } return maxzoom; } diff --git a/tile.h b/tile.h index 42f9607..87d2506 100644 --- a/tile.h +++ b/tile.h @@ -31,5 +31,6 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo extern unsigned initial_x, initial_y; extern int geometry_scale; +extern int quiet; #define MAX_ZOOM_INCREMENT 3