Merge branch 'master' into plugins

This commit is contained in:
Eric Fischer
2017-07-06 22:28:35 -07:00
60 changed files with 25959 additions and 1901 deletions
+38 -8
View File
@@ -28,7 +28,7 @@
#include <sys/wait.h>
#include "mvt.hpp"
#include "mbtiles.hpp"
#include "rawtiles.hpp"
#include "dirtiles.hpp"
#include "geometry.hpp"
#include "tile.hpp"
#include "pool.hpp"
@@ -206,7 +206,7 @@ int metacmp(int m1, const std::vector<long long> &keys1, const std::vector<long
}
void rewrite(drawvec &geom, int z, int nextzoom, int maxzoom, long long *bbox, unsigned tx, unsigned ty, int buffer, int line_detail, int *within, long long *geompos, FILE **geomfile, const char *fname, signed char t, int layer, long long metastart, signed char feature_minzoom, int child_shards, int max_zoom_increment, long long seq, int tippecanoe_minzoom, int tippecanoe_maxzoom, int segment, unsigned *initial_x, unsigned *initial_y, int m, std::vector<long long> &metakeys, std::vector<long long> &metavals, bool has_id, unsigned long long id, unsigned long long index, long long extent) {
if (geom.size() > 0 && nextzoom <= maxzoom) {
if (geom.size() > 0 && (nextzoom <= maxzoom || additional[A_EXTEND_ZOOMS])) {
int xo, yo;
int span = 1 << (nextzoom - z);
@@ -1176,6 +1176,8 @@ struct write_tile_args {
double fraction_out;
const char *prefilter;
const char *postfilter;
bool still_dropping;
int wrote_zoom;
size_t tiling_seg;
};
@@ -1337,7 +1339,6 @@ struct run_prefilter_args {
std::vector<std::vector<std::string>> *layer_unmaps;
char *stringpool;
long long *pool_off;
FILE *prefilter_fp;
};
@@ -1887,6 +1888,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
if (gamma > arg->gamma_out) {
arg->gamma_out = gamma;
arg->still_dropping = true;
}
if (!quiet) {
@@ -1896,9 +1898,14 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
continue;
} else if (additional[A_DROP_DENSEST_AS_NEEDED]) {
mingap_fraction = mingap_fraction * 200000.0 / totalsize * 0.90;
mingap = choose_mingap(indices, mingap_fraction);
unsigned long long mg = choose_mingap(indices, mingap_fraction);
if (mg <= mingap) {
mg = mingap * 1.5;
}
mingap = mg;
if (mingap > arg->mingap_out) {
arg->mingap_out = mingap;
arg->still_dropping = true;
}
if (!quiet) {
fprintf(stderr, "Going to try keeping the sparsest %0.2f%% of the features to make it fit\n", mingap_fraction * 100.0);
@@ -1912,6 +1919,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
minextent = m;
if (minextent > arg->minextent_out) {
arg->minextent_out = minextent;
arg->still_dropping = true;
}
if (!quiet) {
fprintf(stderr, "Going to try keeping the biggest %0.2f%% of the features to make it fit\n", minextent_fraction * 100.0);
@@ -1926,11 +1934,12 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
}
if (additional[A_DROP_FRACTION_AS_NEEDED] && fraction < arg->fraction_out) {
arg->fraction_out = fraction;
arg->still_dropping = true;
}
line_detail++; // to keep it the same when the loop decrements it
continue;
} else {
fprintf(stderr, "Try using -B (and --drop-lines or --drop-polygons if needed) to set a higher base zoom level.\n");
fprintf(stderr, "Try using --drop-fraction-as-needed or --drop-densest-as-needed.\n");
return -1;
}
}
@@ -1964,6 +1973,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
if (gamma > arg->gamma_out) {
arg->gamma_out = gamma;
arg->still_dropping = true;
}
if (!quiet) {
@@ -1972,9 +1982,14 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
line_detail++; // to keep it the same when the loop decrements it
} else if (additional[A_DROP_DENSEST_AS_NEEDED]) {
mingap_fraction = mingap_fraction * max_tile_size / compressed.size() * 0.90;
mingap = choose_mingap(indices, mingap_fraction);
unsigned long long mg = choose_mingap(indices, mingap_fraction);
if (mg <= mingap) {
mg = mingap * 1.5;
}
mingap = mg;
if (mingap > arg->mingap_out) {
arg->mingap_out = mingap;
arg->still_dropping = true;
}
if (!quiet) {
fprintf(stderr, "Going to try keeping the sparsest %0.2f%% of the features to make it fit\n", mingap_fraction * 100.0);
@@ -1987,6 +2002,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
minextent = m;
if (minextent > arg->minextent_out) {
arg->minextent_out = minextent;
arg->still_dropping = true;
}
if (!quiet) {
fprintf(stderr, "Going to try keeping the biggest %0.2f%% of the features to make it fit\n", minextent_fraction * 100.0);
@@ -2004,6 +2020,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
}
if (additional[A_DROP_FRACTION_AS_NEEDED] && fraction < arg->fraction_out) {
arg->fraction_out = fraction;
arg->still_dropping = true;
}
line_detail++; // to keep it the same when the loop decrements it
}
@@ -2017,7 +2034,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
if (outdb != NULL) {
mbtiles_write_tile(outdb, z, tx, ty, compressed.data(), compressed.size());
} else if (outdir != NULL) {
write_raw_tile(outdir, z, tx, ty, compressed);
dir_write_tile(outdir, z, tx, ty, compressed);
}
if (pthread_mutex_unlock(&db_lock) != 0) {
@@ -2078,6 +2095,8 @@ void *run_thread(void *vargs) {
deserialize_uint_io(geom, &x, &geompos);
deserialize_uint_io(geom, &y, &geompos);
arg->wrote_zoom = z;
// 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->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->tiling_seg, arg->pass, arg->passes, arg->mingap, arg->minextent, arg->fraction, arg->prefilter, arg->postfilter, arg);
@@ -2145,7 +2164,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, 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, const char *prefilter, const char *postfilter) {
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, const char *prefilter, const char *postfilter) {
// The existing layermaps are one table per input thread.
// We need to add another one per *tiling* thread so that it can be
// safely changed during tiling.
@@ -2329,6 +2348,8 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
args[thread].running = &running;
args[thread].pass = pass;
args[thread].passes = 2 - start;
args[thread].wrote_zoom = -1;
args[thread].still_dropping = false;
if (pthread_create(&pthreads[thread], NULL, run_thread, &args[thread]) != 0) {
perror("pthread_create");
@@ -2359,6 +2380,15 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
if (args[thread].fraction_out < zoom_fraction) {
zoom_fraction = args[thread].fraction_out;
}
// Zoom counter might be lower than reality if zooms are being skipped
if (args[thread].wrote_zoom > i) {
i = args[thread].wrote_zoom;
}
if (additional[A_EXTEND_ZOOMS] && i == maxzoom && args[thread].still_dropping && maxzoom < MAX_ZOOM) {
maxzoom++;
}
}
}