Add --accumulate-attribute flag and pass the result to tiling

This commit is contained in:
Eric Fischer 2018-02-20 16:19:49 -08:00
parent 03577cf967
commit b73e710855
3 changed files with 44 additions and 5 deletions

View File

@ -1016,7 +1016,7 @@ void choose_first_zoom(long long *file_bbox, std::vector<struct reader> &readers
}
}
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, json_object *filter, 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 *prefilter, const char *postfilter, const char *description, bool guess_maxzoom, std::map<std::string, int> const *attribute_types, const char *pgm) {
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, json_object *filter, 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 *prefilter, const char *postfilter, const char *description, bool guess_maxzoom, std::map<std::string, int> const *attribute_types, const char *pgm, std::map<std::string, int> const *attribute_accum) {
int ret = EXIT_SUCCESS;
std::vector<struct reader> readers;
@ -2121,7 +2121,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, outdb, outdir, buffer, fname, tmpdir, gamma, full_detail, low_detail, min_detail, meta_off, pool_off, initial_x, initial_y, simplification, layermaps, prefilter, postfilter);
int written = traverse_zooms(fd, size, meta, stringpool, &midx, &midy, maxzoom, minzoom, outdb, outdir, buffer, fname, tmpdir, gamma, full_detail, low_detail, min_detail, meta_off, pool_off, initial_x, initial_y, simplification, layermaps, prefilter, postfilter, attribute_accum);
if (maxzoom != written) {
fprintf(stderr, "\n\n\n*** NOTE TILES ONLY COMPLETE THROUGH ZOOM %d ***\n\n\n", written);
@ -2230,6 +2230,37 @@ void set_attribute_type(std::map<std::string, int> &attribute_types, const char
attribute_types.insert(std::pair<std::string, int>(name, t));
}
void set_attribute_accum(std::map<std::string, int> &attribute_accum, const char *arg) {
const char *s = strchr(arg, ':');
if (s == NULL) {
fprintf(stderr, "-E%s option must be in the form -Tname:method\n", arg);
exit(EXIT_FAILURE);
}
std::string name = std::string(arg, s - arg);
std::string type = std::string(s + 1);
int t = -1;
if (type == "sum") {
t = 1;
} else if (type == "product") {
t = 2;
} else if (type == "mean") {
t = 3;
} else if (type == "geom_mean") {
t = 4;
} else if (type == "stddev") {
t = 5;
} else if (type == "concat") {
t = mvt_bool;
} else {
fprintf(stderr, "Attribute method (%s) must be sum, product, mean, geom_mean, stddev, or concat\n", type.c_str());
exit(EXIT_FAILURE);
}
attribute_accum.insert(std::pair<std::string, int>(name, t));
}
int main(int argc, char **argv) {
#ifdef MTRACE
mtrace();
@ -2265,6 +2296,7 @@ int main(int argc, char **argv) {
std::set<std::string> exclude, include;
std::map<std::string, int> attribute_types;
std::map<std::string, int> attribute_accum;
int exclude_all = 0;
int read_parallel = 0;
int files_open_at_start;
@ -2313,6 +2345,7 @@ int main(int argc, char **argv) {
{"include", required_argument, 0, 'y'},
{"exclude-all", no_argument, 0, 'X'},
{"attribute-type", required_argument, 0, 'T'},
{"accumulate-attribute", required_argument, 0, 'E'},
{"feature-filter-file", required_argument, 0, 'J'},
{"feature-filter", required_argument, 0, 'j'},
@ -2694,6 +2727,10 @@ int main(int argc, char **argv) {
set_attribute_type(attribute_types, optarg);
break;
case 'E':
set_attribute_accum(attribute_accum, optarg);
break;
default: {
int width = 7 + strlen(argv[0]);
fprintf(stderr, "Unknown option -%c\n", i);
@ -2833,7 +2870,7 @@ int main(int argc, char **argv) {
long long file_bbox[4] = {UINT_MAX, UINT_MAX, 0, 0};
ret = read_input(sources, name ? name : out_mbtiles ? out_mbtiles : out_dir, maxzoom, minzoom, basezoom, basezoom_marker_width, outdb, out_dir, &exclude, &include, exclude_all, filter, droprate, buffer, tmpdir, gamma, read_parallel, forcetable, attribution, gamma != 0, file_bbox, prefilter, postfilter, description, guess_maxzoom, &attribute_types, argv[0]);
ret = read_input(sources, name ? name : out_mbtiles ? out_mbtiles : out_dir, maxzoom, minzoom, basezoom, basezoom_marker_width, outdb, out_dir, &exclude, &include, exclude_all, filter, droprate, buffer, tmpdir, gamma, read_parallel, forcetable, attribution, gamma != 0, file_bbox, prefilter, postfilter, description, guess_maxzoom, &attribute_types, argv[0], &attribute_accum);
if (outdb != NULL) {
mbtiles_close(outdb, argv[0]);

View File

@ -1165,6 +1165,7 @@ struct write_tile_args {
double fraction_out = 0;
const char *prefilter = NULL;
const char *postfilter = NULL;
std::map<std::string, int> const *attribute_accum = NULL;
bool still_dropping = false;
int wrote_zoom = 0;
size_t tiling_seg = 0;
@ -2295,7 +2296,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, sqlite3 *outdb, const char *outdir, 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, sqlite3 *outdb, const char *outdir, 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, std::map<std::string, int> const *attribute_accum) {
// 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.
@ -2481,6 +2482,7 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
args[thread].tiling_seg = thread + layermaps_off;
args[thread].prefilter = prefilter;
args[thread].postfilter = postfilter;
args[thread].attribute_accum = attribute_accum;
args[thread].tasks = dispatches[thread].tasks;
args[thread].running = &running;

View File

@ -9,7 +9,7 @@
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, sqlite3 *outdb, const char *outdir, 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, 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, sqlite3 *outdb, const char *outdir, 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, const char *prefilter, const char *postfilter, std::map<std::string, int> const *attribute_accum);
int manage_gap(unsigned long long index, unsigned long long *previndex, double scale, double gamma, double *gap);