Update documentation and reduce use of global variables

This commit is contained in:
Eric Fischer 2017-04-07 12:36:34 -07:00
parent b66ab10252
commit 1c1ae6a8be
8 changed files with 42 additions and 46 deletions

View File

@ -67,6 +67,7 @@ Options
### File control
* -o _file_.mbtiles or --output=_file_.mbtiles: Name the output file.
* -e _directory_ or --output-directory=_directory_: Write tiles to the specified *directory* instead of to an mbtiles file.
* -f or --force: Delete the mbtiles file if it already exists instead of giving an error
* -F or --allow-existing: Proceed (without deleting existing data) if the metadata or tiles table already exists
or if metadata fields can't be set
@ -78,7 +79,6 @@ Options
messages may result otherwise.
Performance will be better if the input is a named file that can be mapped into memory
rather than a stream that can only be read sequentially.
* -pC or --raw-tiles: Export to raw uncompressed pbf files rather than to an .mbtiles. This flag will use the output file name (-o) as the folder name.
### Zoom levels and resolution
@ -148,6 +148,7 @@ resolution is obtained than by using a smaller _maxzoom_ or _detail_.
* -pc or --no-clipping: Don't clip features to the size of the tile. If a feature overlaps the tile's bounds or buffer at all, it is included completely. Be careful: this can produce very large tilesets, especially with large polygons.
* -pD or --no-duplication: As with --no-clipping, each feature is included intact instead of cut to tile boundaries. In addition, it is included only in a single tile per zoom level rather than potentially in multiple copies. Clients of the tileset must check adjacent tiles (possibly some distance away) to ensure they have all features.
* -pt or --no-tiny-polygon-reduction: Don't combine the area of very small polygons into small squares that represent their combined area.
* -pC or --no-tile-compression: Don't compress the PBF vector tile data.
* -q or --quiet: Work quietly instead of reporting progress
Environment

View File

@ -58,7 +58,6 @@ 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;
@ -71,8 +70,6 @@ struct source {
std::string file;
};
char *outpbfdir;
size_t CPUS;
size_t TEMP_FILES;
long long MAX_FILES;
@ -1009,7 +1006,7 @@ void choose_first_zoom(long long *file_bbox, struct reader *reader, unsigned *iz
}
}
int read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzoom, int basezoom, double basezoom_marker_width, sqlite3 *outdb, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, double droprate, int buffer, const char *tmpdir, double gamma, int read_parallel, int forcetable, const char *attribution, bool uses_gamma, long long *file_bbox, const char *description) {
int read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzoom, int basezoom, double basezoom_marker_width, sqlite3 *outdb, const char *outdir, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, double droprate, int buffer, const char *tmpdir, double gamma, int read_parallel, int forcetable, const char *attribution, bool uses_gamma, long long *file_bbox, const char *description) {
int ret = EXIT_SUCCESS;
struct reader reader[CPUS];
@ -1783,7 +1780,7 @@ int read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzo
}
unsigned midx = 0, midy = 0;
int written = traverse_zooms(fd, size, meta, stringpool, &midx, &midy, maxzoom, minzoom, basezoom, outdb, droprate, buffer, fname, tmpdir, gamma, full_detail, low_detail, min_detail, meta_off, pool_off, initial_x, initial_y, simplification, layermaps);
int written = traverse_zooms(fd, size, meta, stringpool, &midx, &midy, maxzoom, minzoom, basezoom, outdb, outdir, droprate, buffer, fname, tmpdir, gamma, full_detail, low_detail, min_detail, meta_off, pool_off, initial_x, initial_y, simplification, layermaps);
if (maxzoom != written) {
fprintf(stderr, "\n\n\n*** NOTE TILES ONLY COMPLETE THROUGH ZOOM %d ***\n\n\n", written);
@ -1848,8 +1845,9 @@ int read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzo
ai->second.maxzoom = maxzoom;
}
if (!outdirtable)
if (outdb != NULL) {
mbtiles_write_metadata(outdb, fname, minzoom, maxzoom, minlat, minlon, maxlat, maxlon, midlat, midlon, forcetable, attribution, merged_lm, true, description);
}
return ret;
}
@ -1864,15 +1862,6 @@ static bool has_name(struct option *long_options, int *pl) {
return false;
}
static bool findFlag(int argc, char **argv, std::string str) {
char **ptr = std::find(argv, argv + argc, str);
if (ptr != argv + argc)
return true;
else
return false;
}
int main(int argc, char **argv) {
#ifdef MTRACE
mtrace();
@ -1887,7 +1876,8 @@ int main(int argc, char **argv) {
char *name = NULL;
char *description = NULL;
char *layername = NULL;
char *outdir = NULL;
char *out_mbtiles = NULL;
char *out_directory = NULL;
sqlite3 *outdb = NULL;
int maxzoom = 14;
int minzoom = 0;
@ -2072,12 +2062,11 @@ int main(int argc, char **argv) {
break;
case 'o':
outdir = optarg;
out_mbtiles = optarg;
break;
case 'e':
outpbfdir = optarg;
outdirtable = 1;
out_directory = optarg;
break;
case 'x':
@ -2261,22 +2250,22 @@ int main(int argc, char **argv) {
fprintf(stderr, "Forcing -g0 since -B or -r is not known\n");
}
if (outdir == NULL && outpbfdir == NULL) {
if (out_mbtiles == NULL && out_directory == NULL) {
fprintf(stderr, "%s: must specify -o out.mbtiles or -e directory\n", argv[0]);
exit(EXIT_FAILURE);
}
if ((findFlag(argc, argv, "-o") && findFlag(argc, argv, "-e")) || (findFlag(argc, argv, "--output") && findFlag(argc, argv, "--output-to-directory"))) {
if (out_mbtiles != NULL && out_directory != NULL) {
fprintf(stderr, "%s: Options -o and -e cannot be used together\n", argv[0]);
exit(EXIT_FAILURE);
}
if (out_mbtiles != NULL) {
if (force) {
unlink(outdir);
unlink(out_mbtiles);
}
if (!outdirtable) {
outdb = mbtiles_open(outdir, argv, forcetable);
outdb = mbtiles_open(out_mbtiles, argv, forcetable);
}
int ret = EXIT_SUCCESS;
@ -2303,10 +2292,11 @@ int main(int argc, char **argv) {
long long file_bbox[4] = {UINT_MAX, UINT_MAX, 0, 0};
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);
ret = read_input(sources, name ? name : out_mbtiles ? out_mbtiles : out_directory, maxzoom, minzoom, basezoom, basezoom_marker_width, outdb, out_directory, &exclude, &include, exclude_all, droprate, buffer, tmpdir, gamma, read_parallel, forcetable, attribution, gamma != 0, file_bbox, description);
if (!outdirtable)
if (outdb != NULL) {
mbtiles_close(outdb, argv);
}
#ifdef MTRACE
muntrace();

View File

@ -11,8 +11,6 @@ void checkdisk(struct reader *r, int nreader);
extern int geometry_scale;
extern int quiet;
extern int outdirtable;
extern char *outpbfdir;
extern size_t CPUS;
extern size_t TEMP_FILES;

View File

@ -60,12 +60,16 @@ specified, the files are all merged into the single named layer, even if they tr
\-n \fIname\fP or \-\-name=\fIname\fP: Human\-readable name for the tileset (default file.json)
.IP \(bu 2
\-A \fItext\fP or \-\-attribution=\fItext\fP: Attribution (HTML) to be shown with maps that use data from this tileset.
.IP \(bu 2
\-N \fIdescription\fP or \-\-description=\fIdescription\fP: Description for the tileset (default file.mbtiles)
.RE
.SS File control
.RS
.IP \(bu 2
\-o \fIfile\fP\&.mbtiles or \-\-output=\fIfile\fP\&.mbtiles: Name the output file.
.IP \(bu 2
\-e \fIdirectory\fP or \-\-output\-directory=\fIdirectory\fP: Write tiles to the specified \fIdirectory\fP instead of to an mbtiles file.
.IP \(bu 2
\-f or \-\-force: Delete the mbtiles file if it already exists instead of giving an error
.IP \(bu 2
\-F or \-\-allow\-existing: Proceed (without deleting existing data) if the metadata or tiles table already exists
@ -162,6 +166,8 @@ which may not be what you want.
\-an or \-\-drop\-smallest\-as\-needed: Dynamically drop the smallest features (physically smallest: the shortest lines or the smallest polygons) from each zoom level to keep large tiles under the 500K size limit. This option will not work for point features.
.IP \(bu 2
\-aL or \-\-grid\-low\-zooms: At all zoom levels below \fImaxzoom\fP, snap all lines and polygons to a stairstep grid instead of allowing diagonals. You will also want to specify a tile resolution, probably \fB\fC\-D8\fR\&. This option provides a way to display continuous parcel, gridded, or binned data at low zooms without overwhelming the tiles with tiny polygons, since features will either get stretched out to the grid unit or lost entirely, depending on how they happened to be aligned in the original data.
.IP \(bu 2
\-aw or \-\-detect\-longitude\-wraparound: Detect when adjacent points within a feature jump to the other side of the world, and try to fix the geometry.
.RE
.SS Doing less
.RS
@ -178,7 +184,7 @@ which may not be what you want.
.IP \(bu 2
\-pi or \-\-preserve\-input\-order: Preserve the original input order of features as the drawing order instead of ordering geographically. (This is implemented as a restoration of the original order at the end, so that dot\-dropping is still geographic, which means it also undoes \-ao).
.IP \(bu 2
\-pp or \-\-no\-polygon\-splitting: Don't split complex polygons (over 700 vertices after simplification) into multiple features.
\-pp or \-\-no\-polygon\-splitting: This no longer has any effect.
.IP \(bu 2
\-pc or \-\-no\-clipping: Don't clip features to the size of the tile. If a feature overlaps the tile's bounds or buffer at all, it is included completely. Be careful: this can produce very large tilesets, especially with large polygons.
.IP \(bu 2
@ -186,6 +192,8 @@ which may not be what you want.
.IP \(bu 2
\-pt or \-\-no\-tiny\-polygon\-reduction: Don't combine the area of very small polygons into small squares that represent their combined area.
.IP \(bu 2
\-pC or \-\-no\-tile\-compression: Don't compress the PBF vector tile data.
.IP \(bu 2
\-q or \-\-quiet: Work quietly instead of reporting progress
.RE
.SH Environment
@ -301,9 +309,6 @@ have their probability diffused, so that some of them will be drawn as a square
this minimum size and others will not be drawn at all, preserving the total area that
all of them should have had together.
.PP
Any polygons that have over 700 vertices after line simplification will be split into
multiple features so they can be rendered efficiently, unless you use \-pp to prevent this.
.PP
Features in the same tile that share the same type and attributes are coalesced
together into a single geometry if you use \fB\fC\-\-coalesce\fR\&. You are strongly encouraged to use \-x to exclude
any unnecessary properties to reduce wasted file size.

View File

@ -4,7 +4,7 @@
#include <sys/stat.h>
#include "rawtiles.hpp"
void write_raw_tile(char *outdir, int z, int tx, int ty, std::string pbf) {
void write_raw_tile(const char *outdir, int z, int tx, int ty, std::string const &pbf) {
mkdir(outdir, S_IRWXU | S_IRWXG | S_IRWXO);
std::string curdir(outdir);
std::string slash("/");

View File

@ -1 +1 @@
void write_raw_tile(char *outdir, int z, int tx, int ty, std::string pbf);
void write_raw_tile(const char *outdir, int z, int tx, int ty, std::string const &pbf);

View File

@ -1185,6 +1185,7 @@ struct write_tile_args {
int min_detail;
int basezoom;
sqlite3 *outdb;
const char *outdir;
double droprate;
int buffer;
const char *fname;
@ -1222,7 +1223,7 @@ struct write_tile_args {
double fraction_out;
};
long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *stringpool, int z, unsigned tx, unsigned ty, int detail, int min_detail, int basezoom, sqlite3 *outdb, double droprate, int buffer, const char *fname, FILE **geomfile, int minzoom, int maxzoom, double todo, volatile long long *along, long long alongminus, double gamma, int child_shards, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, volatile int *running, double simplification, std::vector<std::map<std::string, layermap_entry>> *layermaps, std::vector<std::vector<std::string>> *layer_unmaps, size_t pass, size_t passes, unsigned long long mingap, long long minextent, double fraction, write_tile_args *arg) {
long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *stringpool, int z, unsigned tx, unsigned ty, int detail, int min_detail, int basezoom, sqlite3 *outdb, const char *outdir, double droprate, int buffer, const char *fname, FILE **geomfile, int minzoom, int maxzoom, double todo, volatile long long *along, long long alongminus, double gamma, int child_shards, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, volatile int *running, double simplification, std::vector<std::map<std::string, layermap_entry>> *layermaps, std::vector<std::vector<std::string>> *layer_unmaps, size_t pass, size_t passes, unsigned long long mingap, long long minextent, double fraction, write_tile_args *arg) {
int line_detail;
double merge_fraction = 1;
double mingap_fraction = 1;
@ -1917,10 +1918,10 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
exit(EXIT_FAILURE);
}
if (!outdirtable) {
if (outdb != NULL) {
mbtiles_write_tile(outdb, z, tx, ty, compressed.data(), compressed.size());
} else {
write_raw_tile(outpbfdir, z, tx, ty, compressed);
} else if (outdir != NULL) {
write_raw_tile(outdir, z, tx, ty, compressed);
}
if (pthread_mutex_unlock(&db_lock) != 0) {
@ -1983,7 +1984,7 @@ void *run_thread(void *vargs) {
// fprintf(stderr, "%d/%u/%u\n", z, x, y);
long long len = write_tile(geom, &geompos, arg->metabase, arg->stringpool, z, x, y, z == arg->maxzoom ? arg->full_detail : arg->low_detail, arg->min_detail, arg->basezoom, arg->outdb, arg->droprate, arg->buffer, arg->fname, arg->geomfile, arg->minzoom, arg->maxzoom, arg->todo, arg->along, geompos, arg->gamma, arg->child_shards, arg->meta_off, arg->pool_off, arg->initial_x, arg->initial_y, arg->running, arg->simplification, arg->layermaps, arg->layer_unmaps, arg->pass, arg->passes, arg->mingap, arg->minextent, arg->fraction, arg);
long long len = write_tile(geom, &geompos, arg->metabase, arg->stringpool, z, x, y, z == arg->maxzoom ? arg->full_detail : arg->low_detail, arg->min_detail, arg->basezoom, arg->outdb, arg->outdir, arg->droprate, arg->buffer, arg->fname, arg->geomfile, arg->minzoom, arg->maxzoom, arg->todo, arg->along, geompos, arg->gamma, arg->child_shards, arg->meta_off, arg->pool_off, arg->initial_x, arg->initial_y, arg->running, arg->simplification, arg->layermaps, arg->layer_unmaps, arg->pass, arg->passes, arg->mingap, arg->minextent, arg->fraction, arg);
if (len < 0) {
int *err = &arg->err;
@ -2048,7 +2049,7 @@ void *run_thread(void *vargs) {
return NULL;
}
int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpool, unsigned *midx, unsigned *midy, int maxzoom, int minzoom, int basezoom, sqlite3 *outdb, double droprate, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, std::vector<std::map<std::string, layermap_entry>> &layermaps) {
int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpool, unsigned *midx, unsigned *midy, int maxzoom, int minzoom, int basezoom, sqlite3 *outdb, const char *outdir, double droprate, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, std::vector<std::map<std::string, layermap_entry>> &layermaps) {
// Table to map segment and layer number back to layer name
std::vector<std::vector<std::string>> layer_unmaps;
for (size_t seg = 0; seg < layermaps.size(); seg++) {
@ -2183,6 +2184,7 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
args[thread].min_detail = min_detail;
args[thread].basezoom = basezoom;
args[thread].outdb = outdb; // locked with db_lock
args[thread].outdir = outdir;
args[thread].droprate = droprate;
args[thread].buffer = buffer;
args[thread].fname = fname;

View File

@ -1,5 +1,5 @@
long long write_tile(char **geom, char *metabase, char *stringpool, unsigned *file_bbox, int z, unsigned x, unsigned y, int detail, int min_detail, int basezoom, sqlite3 *outdb, double droprate, int buffer, const char *fname, FILE **geomfile, int file_minzoom, int file_maxzoom, double todo, char *geomstart, long long along, double gamma, int nlayers);
long long write_tile(char **geom, char *metabase, char *stringpool, unsigned *file_bbox, int z, unsigned x, unsigned y, int detail, int min_detail, int basezoom, sqlite3 *outdb, const char *outdir, double droprate, int buffer, const char *fname, FILE **geomfile, int file_minzoom, int file_maxzoom, double todo, char *geomstart, long long along, double gamma, int nlayers);
int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpool, unsigned *midx, unsigned *midy, int maxzoom, int minzoom, int basezoom, sqlite3 *outdb, double droprate, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, std::vector<std::map<std::string, layermap_entry> > &layermap);
int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpool, unsigned *midx, unsigned *midy, int maxzoom, int minzoom, int basezoom, sqlite3 *outdb, const char *outdir, double droprate, int buffer, const char *fname, const char *tmpdir, double gamma, int full_detail, int low_detail, int min_detail, long long *meta_off, long long *pool_off, unsigned *initial_x, unsigned *initial_y, double simplification, std::vector<std::map<std::string, layermap_entry> > &layermap);
int manage_gap(unsigned long long index, unsigned long long *previndex, double scale, double gamma, double *gap);