mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-01-22 04:18:01 +00:00
Merge per-thread layer names and file keys
This commit is contained in:
parent
c26fa23564
commit
7f49ce5caa
15
geojson.cpp
15
geojson.cpp
@ -167,7 +167,7 @@ long long parse_geometry(int t, json_object *j, long long *bbox, drawvec &out, i
|
||||
return g;
|
||||
}
|
||||
|
||||
int serialize_geometry(json_object *geometry, json_object *properties, json_object *id, const char *reading, int line, volatile long long *layer_seq, volatile long long *progress_seq, long long *metapos, long long *geompos, long long *indexpos, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, FILE *metafile, FILE *geomfile, FILE *indexfile, struct memfile *poolfile, struct memfile *treefile, const char *fname, int basezoom, int layer, double droprate, long long *file_bbox, json_object *tippecanoe, int segment, int *initialized, unsigned *initial_x, unsigned *initial_y, struct reader *readers, std::set<type_and_string> *file_keys, int maxzoom, json_object *feature, std::map<std::string, layermap_entry> *layermap) {
|
||||
int serialize_geometry(json_object *geometry, json_object *properties, json_object *id, const char *reading, int line, volatile long long *layer_seq, volatile long long *progress_seq, long long *metapos, long long *geompos, long long *indexpos, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, FILE *metafile, FILE *geomfile, FILE *indexfile, struct memfile *poolfile, struct memfile *treefile, const char *fname, int basezoom, int layer, double droprate, long long *file_bbox, json_object *tippecanoe, int segment, int *initialized, unsigned *initial_x, unsigned *initial_y, struct reader *readers, std::set<type_and_string> *file_keys, int maxzoom, json_object *feature, std::map<std::string, layermap_entry> *layermap, std::string const &layername) {
|
||||
json_object *geometry_type = json_hash_get(geometry, "type");
|
||||
if (geometry_type == NULL) {
|
||||
static int warned = 0;
|
||||
@ -310,6 +310,9 @@ int serialize_geometry(json_object *geometry, json_object *properties, json_obje
|
||||
|
||||
if (tas.type >= 0) {
|
||||
file_keys->insert(tas);
|
||||
|
||||
auto fk = layermap->find(layername);
|
||||
fk->second.file_keys.insert(tas);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -471,7 +474,7 @@ void check_crs(json_object *j, const char *reading) {
|
||||
}
|
||||
}
|
||||
|
||||
void parse_json(json_pull *jp, const char *reading, volatile long long *layer_seq, volatile long long *progress_seq, long long *metapos, long long *geompos, long long *indexpos, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, FILE *metafile, FILE *geomfile, FILE *indexfile, struct memfile *poolfile, struct memfile *treefile, char *fname, int basezoom, int layer, double droprate, long long *file_bbox, int segment, int *initialized, unsigned *initial_x, unsigned *initial_y, struct reader *readers, std::set<type_and_string> *file_keys, int maxzoom, std::map<std::string, layermap_entry> *layermap) {
|
||||
void parse_json(json_pull *jp, const char *reading, volatile long long *layer_seq, volatile long long *progress_seq, long long *metapos, long long *geompos, long long *indexpos, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, FILE *metafile, FILE *geomfile, FILE *indexfile, struct memfile *poolfile, struct memfile *treefile, char *fname, int basezoom, int layer, double droprate, long long *file_bbox, int segment, int *initialized, unsigned *initial_x, unsigned *initial_y, struct reader *readers, std::set<type_and_string> *file_keys, int maxzoom, std::map<std::string, layermap_entry> *layermap, std::string layername) {
|
||||
long long found_hashes = 0;
|
||||
long long found_features = 0;
|
||||
long long found_geometries = 0;
|
||||
@ -539,7 +542,7 @@ void parse_json(json_pull *jp, const char *reading, volatile long long *layer_se
|
||||
}
|
||||
found_geometries++;
|
||||
|
||||
serialize_geometry(j, NULL, NULL, reading, jp->line, layer_seq, progress_seq, metapos, geompos, indexpos, exclude, include, exclude_all, metafile, geomfile, indexfile, poolfile, treefile, fname, basezoom, layer, droprate, file_bbox, NULL, segment, initialized, initial_x, initial_y, readers, file_keys, maxzoom, j, layermap);
|
||||
serialize_geometry(j, NULL, NULL, reading, jp->line, layer_seq, progress_seq, metapos, geompos, indexpos, exclude, include, exclude_all, metafile, geomfile, indexfile, poolfile, treefile, fname, basezoom, layer, droprate, file_bbox, NULL, segment, initialized, initial_x, initial_y, readers, file_keys, maxzoom, j, layermap, layername);
|
||||
json_free(j);
|
||||
continue;
|
||||
}
|
||||
@ -581,10 +584,10 @@ void parse_json(json_pull *jp, const char *reading, volatile long long *layer_se
|
||||
if (geometries != NULL) {
|
||||
size_t g;
|
||||
for (g = 0; g < geometries->length; g++) {
|
||||
serialize_geometry(geometries->array[g], properties, id, reading, jp->line, layer_seq, progress_seq, metapos, geompos, indexpos, exclude, include, exclude_all, metafile, geomfile, indexfile, poolfile, treefile, fname, basezoom, layer, droprate, file_bbox, tippecanoe, segment, initialized, initial_x, initial_y, readers, file_keys, maxzoom, j, layermap);
|
||||
serialize_geometry(geometries->array[g], properties, id, reading, jp->line, layer_seq, progress_seq, metapos, geompos, indexpos, exclude, include, exclude_all, metafile, geomfile, indexfile, poolfile, treefile, fname, basezoom, layer, droprate, file_bbox, tippecanoe, segment, initialized, initial_x, initial_y, readers, file_keys, maxzoom, j, layermap, layername);
|
||||
}
|
||||
} else {
|
||||
serialize_geometry(geometry, properties, id, reading, jp->line, layer_seq, progress_seq, metapos, geompos, indexpos, exclude, include, exclude_all, metafile, geomfile, indexfile, poolfile, treefile, fname, basezoom, layer, droprate, file_bbox, tippecanoe, segment, initialized, initial_x, initial_y, readers, file_keys, maxzoom, j, layermap);
|
||||
serialize_geometry(geometry, properties, id, reading, jp->line, layer_seq, progress_seq, metapos, geompos, indexpos, exclude, include, exclude_all, metafile, geomfile, indexfile, poolfile, treefile, fname, basezoom, layer, droprate, file_bbox, tippecanoe, segment, initialized, initial_x, initial_y, readers, file_keys, maxzoom, j, layermap, layername);
|
||||
}
|
||||
|
||||
json_free(j);
|
||||
@ -596,7 +599,7 @@ void parse_json(json_pull *jp, const char *reading, volatile long long *layer_se
|
||||
void *run_parse_json(void *v) {
|
||||
struct parse_json_args *pja = (struct parse_json_args *) v;
|
||||
|
||||
parse_json(pja->jp, pja->reading, pja->layer_seq, pja->progress_seq, pja->metapos, pja->geompos, pja->indexpos, pja->exclude, pja->include, pja->exclude_all, pja->metafile, pja->geomfile, pja->indexfile, pja->poolfile, pja->treefile, pja->fname, pja->basezoom, pja->layer, pja->droprate, pja->file_bbox, pja->segment, pja->initialized, pja->initial_x, pja->initial_y, pja->readers, pja->file_keys, pja->maxzoom, pja->layermap);
|
||||
parse_json(pja->jp, pja->reading, pja->layer_seq, pja->progress_seq, pja->metapos, pja->geompos, pja->indexpos, pja->exclude, pja->include, pja->exclude_all, pja->metafile, pja->geomfile, pja->indexfile, pja->poolfile, pja->treefile, pja->fname, pja->basezoom, pja->layer, pja->droprate, pja->file_bbox, pja->segment, pja->initialized, pja->initial_x, pja->initial_y, pja->readers, pja->file_keys, pja->maxzoom, pja->layermap, *pja->layername);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -27,8 +27,9 @@ struct parse_json_args {
|
||||
std::set<type_and_string> *file_keys;
|
||||
int maxzoom;
|
||||
std::map<std::string, layermap_entry> *layermap;
|
||||
std::string *layername;
|
||||
};
|
||||
|
||||
struct json_pull *json_begin_map(char *map, long long len);
|
||||
void parse_json(json_pull *jp, const char *reading, volatile long long *layer_seq, volatile long long *progress_seq, long long *metapos, long long *geompos, long long *indexpos, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, FILE *metafile, FILE *geomfile, FILE *indexfile, struct memfile *poolfile, struct memfile *treefile, char *fname, int basezoom, int layer, double droprate, long long *file_bbox, int segment, int *initialized, unsigned *initial_x, unsigned *initial_y, struct reader *readers, std::set<type_and_string> *file_keys, int maxzoom, std::map<std::string, layermap_entry> *layermap);
|
||||
void parse_json(json_pull *jp, const char *reading, volatile long long *layer_seq, volatile long long *progress_seq, long long *metapos, long long *geompos, long long *indexpos, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, FILE *metafile, FILE *geomfile, FILE *indexfile, struct memfile *poolfile, struct memfile *treefile, char *fname, int basezoom, int layer, double droprate, long long *file_bbox, int segment, int *initialized, unsigned *initial_x, unsigned *initial_y, struct reader *readers, std::set<type_and_string> *file_keys, int maxzoom, std::map<std::string, layermap_entry> *layermap, std::string layername);
|
||||
void *run_parse_json(void *v);
|
||||
|
52
main.cpp
52
main.cpp
@ -300,7 +300,7 @@ void *run_sort(void *v) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void do_read_parallel(char *map, long long len, long long initial_offset, const char *reading, struct reader *reader, volatile long long *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, char *fname, int basezoom, int source, int nlayers, std::vector<std::map<std::string, layermap_entry> > *layermaps, double droprate, int *initialized, unsigned *initial_x, unsigned *initial_y, std::set<type_and_string> *file_keys, int maxzoom) {
|
||||
void do_read_parallel(char *map, long long len, long long initial_offset, const char *reading, struct reader *reader, volatile long long *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, char *fname, int basezoom, int source, int nlayers, std::vector<std::map<std::string, layermap_entry> > *layermaps, double droprate, int *initialized, unsigned *initial_x, unsigned *initial_y, std::set<type_and_string> *file_keys, int maxzoom, std::string layername) {
|
||||
long long segs[CPUS + 1];
|
||||
segs[0] = 0;
|
||||
segs[CPUS] = len;
|
||||
@ -358,6 +358,7 @@ void do_read_parallel(char *map, long long len, long long initial_offset, const
|
||||
pja[i].file_keys = &file_subkeys[i];
|
||||
pja[i].maxzoom = maxzoom;
|
||||
pja[i].layermap = &(*layermaps)[i];
|
||||
pja[i].layername = &layername;
|
||||
|
||||
if (pthread_create(&pthreads[i], NULL, run_parse_json, &pja[i]) != 0) {
|
||||
perror("pthread_create");
|
||||
@ -406,6 +407,7 @@ struct read_parallel_arg {
|
||||
unsigned *initial_x;
|
||||
unsigned *initial_y;
|
||||
std::set<type_and_string> *file_keys;
|
||||
std::string layername;
|
||||
};
|
||||
|
||||
void *run_read_parallel(void *v) {
|
||||
@ -427,7 +429,7 @@ void *run_read_parallel(void *v) {
|
||||
}
|
||||
madvise(map, a->len, MADV_RANDOM); // sequential, but from several pointers at once
|
||||
|
||||
do_read_parallel(map, a->len, a->offset, a->reading, a->reader, a->progress_seq, a->exclude, a->include, a->exclude_all, a->fname, a->basezoom, a->source, a->nlayers, a->layermaps, a->droprate, a->initialized, a->initial_x, a->initial_y, a->file_keys, a->maxzoom);
|
||||
do_read_parallel(map, a->len, a->offset, a->reading, a->reader, a->progress_seq, a->exclude, a->include, a->exclude_all, a->fname, a->basezoom, a->source, a->nlayers, a->layermaps, a->droprate, a->initialized, a->initial_x, a->initial_y, a->file_keys, a->maxzoom, a->layername);
|
||||
|
||||
madvise(map, a->len, MADV_DONTNEED);
|
||||
if (munmap(map, a->len) != 0) {
|
||||
@ -444,7 +446,7 @@ void *run_read_parallel(void *v) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void start_parsing(int fd, FILE *fp, long long offset, long long len, volatile int *is_parsing, pthread_t *parallel_parser, bool &parser_created, const char *reading, struct reader *reader, volatile long long *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, char *fname, int basezoom, int source, int nlayers, std::vector<std::map<std::string, layermap_entry> > &layermaps, double droprate, int *initialized, unsigned *initial_x, unsigned *initial_y, std::set<type_and_string> *file_keys, int maxzoom) {
|
||||
void start_parsing(int fd, FILE *fp, long long offset, long long len, volatile int *is_parsing, pthread_t *parallel_parser, bool &parser_created, const char *reading, struct reader *reader, volatile long long *progress_seq, std::set<std::string> *exclude, std::set<std::string> *include, int exclude_all, char *fname, int basezoom, int source, int nlayers, std::vector<std::map<std::string, layermap_entry> > &layermaps, double droprate, int *initialized, unsigned *initial_x, unsigned *initial_y, std::set<type_and_string> *file_keys, int maxzoom, std::string layername) {
|
||||
// This has to kick off an intermediate thread to start the parser threads,
|
||||
// so the main thread can get back to reading the next input stage while
|
||||
// the intermediate thread waits for the completion of the parser threads.
|
||||
@ -480,6 +482,7 @@ void start_parsing(int fd, FILE *fp, long long offset, long long len, volatile i
|
||||
rpa->initial_y = initial_y;
|
||||
rpa->file_keys = file_keys;
|
||||
rpa->maxzoom = maxzoom;
|
||||
rpa->layername = layername;
|
||||
|
||||
if (pthread_create(parallel_parser, NULL, run_read_parallel, rpa) != 0) {
|
||||
perror("pthread_create");
|
||||
@ -862,6 +865,37 @@ void radix(struct reader *reader, int nreaders, FILE *geomfile, int geomfd, FILE
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry> > const &maps) {
|
||||
std::map<std::string, layermap_entry> out;
|
||||
|
||||
for (size_t i = 0; i < maps.size(); i++) {
|
||||
for (auto map = maps[i].begin(); map != maps[i].end(); ++map) {
|
||||
if (out.count(map->first) == 0) {
|
||||
out.insert(std::pair<std::string, layermap_entry>(map->first, layermap_entry(out.size())));
|
||||
}
|
||||
|
||||
auto out_entry = out.find(map->first);
|
||||
if (out_entry == out.end()) {
|
||||
fprintf(stderr, "Internal error merging layers\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
for (auto fk = map->second.file_keys.begin(); fk != map->second.file_keys.end(); ++fk) {
|
||||
out_entry->second.file_keys.insert(*fk);
|
||||
}
|
||||
|
||||
if (additional[A_CALCULATE_FEATURE_DENSITY]) {
|
||||
type_and_string tas;
|
||||
tas.type = VT_NUMBER;
|
||||
tas.string = "tippecanoe_feature_density";
|
||||
out_entry->second.file_keys.insert(tas);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
int read_input(std::vector<source> &sources, char *fname, const char *layername, 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) {
|
||||
int ret = EXIT_SUCCESS;
|
||||
|
||||
@ -1088,7 +1122,7 @@ int read_input(std::vector<source> &sources, char *fname, const char *layername,
|
||||
}
|
||||
|
||||
if (map != NULL && map != MAP_FAILED) {
|
||||
do_read_parallel(map, st.st_size - off, overall_offset, reading.c_str(), reader, &progress_seq, exclude, include, exclude_all, fname, basezoom, source, nlayers, &layermaps, droprate, initialized, initial_x, initial_y, &file_keys[source < nlayers ? source : 0], maxzoom);
|
||||
do_read_parallel(map, st.st_size - off, overall_offset, reading.c_str(), reader, &progress_seq, exclude, include, exclude_all, fname, basezoom, source, nlayers, &layermaps, droprate, initialized, initial_x, initial_y, &file_keys[source < nlayers ? source : 0], maxzoom, layernames[source < nlayers ? source : 0]);
|
||||
overall_offset += st.st_size - off;
|
||||
checkdisk(reader, CPUS);
|
||||
|
||||
@ -1156,7 +1190,7 @@ int read_input(std::vector<source> &sources, char *fname, const char *layername,
|
||||
}
|
||||
|
||||
fflush(readfp);
|
||||
start_parsing(readfd, readfp, initial_offset, ahead, &is_parsing, ¶llel_parser, parser_created, reading.c_str(), reader, &progress_seq, exclude, include, exclude_all, fname, basezoom, source, nlayers, layermaps, droprate, initialized, initial_x, initial_y, &file_keys[source < nlayers ? source : 0], maxzoom);
|
||||
start_parsing(readfd, readfp, initial_offset, ahead, &is_parsing, ¶llel_parser, parser_created, reading.c_str(), reader, &progress_seq, exclude, include, exclude_all, fname, basezoom, source, nlayers, layermaps, droprate, initialized, initial_x, initial_y, &file_keys[source < nlayers ? source : 0], maxzoom, layernames[source < nlayers ? source : 0]);
|
||||
|
||||
initial_offset += ahead;
|
||||
overall_offset += ahead;
|
||||
@ -1193,7 +1227,7 @@ int read_input(std::vector<source> &sources, char *fname, const char *layername,
|
||||
fflush(readfp);
|
||||
|
||||
if (ahead > 0) {
|
||||
start_parsing(readfd, readfp, initial_offset, ahead, &is_parsing, ¶llel_parser, parser_created, reading.c_str(), reader, &progress_seq, exclude, include, exclude_all, fname, basezoom, source, nlayers, layermaps, droprate, initialized, initial_x, initial_y, &file_keys[source < nlayers ? source : 0], maxzoom);
|
||||
start_parsing(readfd, readfp, initial_offset, ahead, &is_parsing, ¶llel_parser, parser_created, reading.c_str(), reader, &progress_seq, exclude, include, exclude_all, fname, basezoom, source, nlayers, layermaps, droprate, initialized, initial_x, initial_y, &file_keys[source < nlayers ? source : 0], maxzoom, layernames[source < nlayers ? source : 0]);
|
||||
|
||||
if (parser_created) {
|
||||
if (pthread_join(parallel_parser, NULL) != 0) {
|
||||
@ -1210,7 +1244,7 @@ int read_input(std::vector<source> &sources, char *fname, const char *layername,
|
||||
|
||||
long long layer_seq = overall_offset;
|
||||
json_pull *jp = json_begin_file(fp);
|
||||
parse_json(jp, reading.c_str(), &layer_seq, &progress_seq, &reader[0].metapos, &reader[0].geompos, &reader[0].indexpos, exclude, include, exclude_all, reader[0].metafile, reader[0].geomfile, reader[0].indexfile, reader[0].poolfile, reader[0].treefile, fname, basezoom, source < nlayers ? source : 0, droprate, reader[0].file_bbox, 0, &initialized[0], &initial_x[0], &initial_y[0], reader, &file_keys[source < nlayers ? source : 0], maxzoom, &layermaps[0]);
|
||||
parse_json(jp, reading.c_str(), &layer_seq, &progress_seq, &reader[0].metapos, &reader[0].geompos, &reader[0].indexpos, exclude, include, exclude_all, reader[0].metafile, reader[0].geomfile, reader[0].indexfile, reader[0].poolfile, reader[0].treefile, fname, basezoom, source < nlayers ? source : 0, droprate, reader[0].file_bbox, 0, &initialized[0], &initial_x[0], &initial_y[0], reader, &file_keys[source < nlayers ? source : 0], maxzoom, &layermaps[0], layernames[source < nlayers ? source : 0]);
|
||||
json_end(jp);
|
||||
overall_offset = layer_seq;
|
||||
checkdisk(reader, CPUS);
|
||||
@ -1711,7 +1745,9 @@ int read_input(std::vector<source> &sources, char *fname, const char *layername,
|
||||
midlon = maxlon;
|
||||
}
|
||||
|
||||
mbtiles_write_metadata(outdb, fname, layernames, minzoom, maxzoom, minlat, minlon, maxlat, maxlon, midlat, midlon, file_keys, nlayers, forcetable, attribution);
|
||||
std::map<std::string, layermap_entry> merged_lm = merge_layermaps(layermaps);
|
||||
|
||||
mbtiles_write_metadata(outdb, fname, layernames, minzoom, maxzoom, minlat, minlon, maxlat, maxlon, midlat, midlon, file_keys, nlayers, forcetable, attribution, merged_lm);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
15
mbtiles.cpp
15
mbtiles.cpp
@ -10,6 +10,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include "main.hpp"
|
||||
#include "pool.hpp"
|
||||
#include "mbtiles.hpp"
|
||||
@ -132,7 +133,7 @@ bool type_and_string::operator<(const type_and_string &o) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, std::vector<std::string> &layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, std::vector<std::set<type_and_string> > &file_keys, int nlayers, int forcetable, const char *attribution) {
|
||||
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, std::vector<std::string> &layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, std::vector<std::set<type_and_string> > &file_keys, int nlayers, int forcetable, const char *attribution, std::map<std::string, layermap_entry> const &layermap) {
|
||||
char *sql, *err;
|
||||
|
||||
sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES ('name', %Q);", fname);
|
||||
@ -230,19 +231,25 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, std::vector<std::
|
||||
std::string buf("{");
|
||||
aprintf(&buf, "\"vector_layers\": [ ");
|
||||
|
||||
std::vector<std::string> lnames;
|
||||
for (auto ai = layermap.begin(); ai != layermap.end(); ++ai) {
|
||||
lnames.push_back(ai->first);
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i < nlayers; i++) {
|
||||
for (i = 0; i < lnames.size(); i++) {
|
||||
if (i != 0) {
|
||||
aprintf(&buf, ", ");
|
||||
}
|
||||
|
||||
aprintf(&buf, "{ \"id\": \"");
|
||||
quote(&buf, layername[i].c_str());
|
||||
quote(&buf, lnames[i].c_str());
|
||||
aprintf(&buf, "\", \"description\": \"\", \"minzoom\": %d, \"maxzoom\": %d, \"fields\": {", minzoom, maxzoom);
|
||||
|
||||
auto fk = layermap.find(lnames[i]);
|
||||
std::set<type_and_string>::iterator j;
|
||||
bool first = true;
|
||||
for (j = file_keys[i].begin(); j != file_keys[i].end(); ++j) {
|
||||
for (j = fk->second.file_keys.begin(); j != fk->second.file_keys.end(); ++j) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
|
@ -18,7 +18,7 @@ sqlite3 *mbtiles_open(char *dbname, char **argv, int forcetable);
|
||||
|
||||
void mbtiles_write_tile(sqlite3 *outdb, int z, int tx, int ty, const char *data, int size);
|
||||
|
||||
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, std::vector<std::string> &layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, std::vector<std::set<type_and_string> > &file_keys, int nlayers, int forcetable, const char *attribution);
|
||||
void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, std::vector<std::string> &layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, std::vector<std::set<type_and_string> > &file_keys, int nlayers, int forcetable, const char *attribution, std::map<std::string, layermap_entry> const &layermap);
|
||||
|
||||
void mbtiles_close(sqlite3 *outdb, char **argv);
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
"center": "0.000000,18.975561,0",
|
||||
"description": "tests/named/out/-z0_-Lalgeria@tests%named%alg_-Lalbania@tests%named%alb.json.check.mbtiles",
|
||||
"format": "pbf",
|
||||
"json": "{\"vector_layers\": [ { \"id\": \"algeria\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"abbrev\": \"String\", \"abbrev_len\": \"Number\", \"adm0_a3\": \"String\", \"adm0_a3_is\": \"String\", \"adm0_a3_un\": \"Number\", \"adm0_a3_us\": \"String\", \"adm0_a3_wb\": \"Number\", \"adm0_dif\": \"Number\", \"admin\": \"String\", \"brk_a3\": \"String\", \"brk_diff\": \"Number\", \"brk_name\": \"String\", \"continent\": \"String\", \"economy\": \"String\", \"featurecla\": \"String\", \"formal_en\": \"String\", \"gdp_md_est\": \"Number\", \"gdp_year\": \"Number\", \"geou_dif\": \"Number\", \"geounit\": \"String\", \"gu_a3\": \"String\", \"homepart\": \"Number\", \"income_grp\": \"String\", \"iso_a2\": \"String\", \"iso_a3\": \"String\", \"iso_n3\": \"String\", \"labelrank\": \"Number\", \"lastcensus\": \"Number\", \"level\": \"Number\", \"long_len\": \"Number\", \"mapcolor13\": \"Number\", \"mapcolor7\": \"Number\", \"mapcolor8\": \"Number\", \"mapcolor9\": \"Number\", \"name\": \"String\", \"name_len\": \"Number\", \"name_long\": \"String\", \"name_sort\": \"String\", \"pop_est\": \"Number\", \"pop_year\": \"Number\", \"postal\": \"String\", \"region_un\": \"String\", \"region_wb\": \"String\", \"scalerank\": \"Number\", \"sov_a3\": \"String\", \"sovereignt\": \"String\", \"su_a3\": \"String\", \"su_dif\": \"Number\", \"subregion\": \"String\", \"subunit\": \"String\", \"tiny\": \"Number\", \"type\": \"String\", \"un_a3\": \"String\", \"wb_a2\": \"String\", \"wb_a3\": \"String\", \"wikipedia\": \"Number\", \"woe_id\": \"Number\"} }, { \"id\": \"albania\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"abbrev\": \"String\", \"abbrev_len\": \"Number\", \"adm0_a3\": \"String\", \"adm0_a3_is\": \"String\", \"adm0_a3_un\": \"Number\", \"adm0_a3_us\": \"String\", \"adm0_a3_wb\": \"Number\", \"adm0_dif\": \"Number\", \"admin\": \"String\", \"brk_a3\": \"String\", \"brk_diff\": \"Number\", \"brk_name\": \"String\", \"continent\": \"String\", \"economy\": \"String\", \"featurecla\": \"String\", \"formal_en\": \"String\", \"gdp_md_est\": \"Number\", \"gdp_year\": \"Number\", \"geou_dif\": \"Number\", \"geounit\": \"String\", \"gu_a3\": \"String\", \"homepart\": \"Number\", \"income_grp\": \"String\", \"iso_a2\": \"String\", \"iso_a3\": \"String\", \"iso_n3\": \"String\", \"labelrank\": \"Number\", \"lastcensus\": \"Number\", \"level\": \"Number\", \"long_len\": \"Number\", \"mapcolor13\": \"Number\", \"mapcolor7\": \"Number\", \"mapcolor8\": \"Number\", \"mapcolor9\": \"Number\", \"name\": \"String\", \"name_len\": \"Number\", \"name_long\": \"String\", \"name_sort\": \"String\", \"pop_est\": \"Number\", \"pop_year\": \"Number\", \"postal\": \"String\", \"region_un\": \"String\", \"region_wb\": \"String\", \"scalerank\": \"Number\", \"sov_a3\": \"String\", \"sovereignt\": \"String\", \"su_a3\": \"String\", \"su_dif\": \"Number\", \"subregion\": \"String\", \"subunit\": \"String\", \"tiny\": \"Number\", \"type\": \"String\", \"un_a3\": \"String\", \"wb_a2\": \"String\", \"wb_a3\": \"String\", \"wikipedia\": \"Number\", \"woe_id\": \"Number\"} }, { \"id\": \"sweden\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"abbrev\": \"String\", \"abbrev_len\": \"Number\", \"adm0_a3\": \"String\", \"adm0_a3_is\": \"String\", \"adm0_a3_un\": \"Number\", \"adm0_a3_us\": \"String\", \"adm0_a3_wb\": \"Number\", \"adm0_dif\": \"Number\", \"admin\": \"String\", \"brk_a3\": \"String\", \"brk_diff\": \"Number\", \"brk_name\": \"String\", \"continent\": \"String\", \"economy\": \"String\", \"featurecla\": \"String\", \"formal_en\": \"String\", \"gdp_md_est\": \"Number\", \"gdp_year\": \"Number\", \"geou_dif\": \"Number\", \"geounit\": \"String\", \"gu_a3\": \"String\", \"homepart\": \"Number\", \"income_grp\": \"String\", \"iso_a2\": \"String\", \"iso_a3\": \"String\", \"iso_n3\": \"String\", \"labelrank\": \"Number\", \"lastcensus\": \"Number\", \"level\": \"Number\", \"long_len\": \"Number\", \"mapcolor13\": \"Number\", \"mapcolor7\": \"Number\", \"mapcolor8\": \"Number\", \"mapcolor9\": \"Number\", \"name\": \"String\", \"name_len\": \"Number\", \"name_long\": \"String\", \"name_sort\": \"String\", \"pop_est\": \"Number\", \"pop_year\": \"Number\", \"postal\": \"String\", \"region_un\": \"String\", \"region_wb\": \"String\", \"scalerank\": \"Number\", \"sov_a3\": \"String\", \"sovereignt\": \"String\", \"su_a3\": \"String\", \"su_dif\": \"Number\", \"subregion\": \"String\", \"subunit\": \"String\", \"tiny\": \"Number\", \"type\": \"String\", \"un_a3\": \"String\", \"wb_a2\": \"String\", \"wb_a3\": \"String\", \"wikipedia\": \"Number\", \"woe_id\": \"Number\"} } ] }",
|
||||
"json": "{\"vector_layers\": [ { \"id\": \"albania\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"abbrev\": \"String\", \"abbrev_len\": \"Number\", \"adm0_a3\": \"String\", \"adm0_a3_is\": \"String\", \"adm0_a3_un\": \"Number\", \"adm0_a3_us\": \"String\", \"adm0_a3_wb\": \"Number\", \"adm0_dif\": \"Number\", \"admin\": \"String\", \"brk_a3\": \"String\", \"brk_diff\": \"Number\", \"brk_name\": \"String\", \"continent\": \"String\", \"economy\": \"String\", \"featurecla\": \"String\", \"formal_en\": \"String\", \"gdp_md_est\": \"Number\", \"gdp_year\": \"Number\", \"geou_dif\": \"Number\", \"geounit\": \"String\", \"gu_a3\": \"String\", \"homepart\": \"Number\", \"income_grp\": \"String\", \"iso_a2\": \"String\", \"iso_a3\": \"String\", \"iso_n3\": \"String\", \"labelrank\": \"Number\", \"lastcensus\": \"Number\", \"level\": \"Number\", \"long_len\": \"Number\", \"mapcolor13\": \"Number\", \"mapcolor7\": \"Number\", \"mapcolor8\": \"Number\", \"mapcolor9\": \"Number\", \"name\": \"String\", \"name_len\": \"Number\", \"name_long\": \"String\", \"name_sort\": \"String\", \"pop_est\": \"Number\", \"pop_year\": \"Number\", \"postal\": \"String\", \"region_un\": \"String\", \"region_wb\": \"String\", \"scalerank\": \"Number\", \"sov_a3\": \"String\", \"sovereignt\": \"String\", \"su_a3\": \"String\", \"su_dif\": \"Number\", \"subregion\": \"String\", \"subunit\": \"String\", \"tiny\": \"Number\", \"type\": \"String\", \"un_a3\": \"String\", \"wb_a2\": \"String\", \"wb_a3\": \"String\", \"wikipedia\": \"Number\", \"woe_id\": \"Number\"} }, { \"id\": \"algeria\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"abbrev\": \"String\", \"abbrev_len\": \"Number\", \"adm0_a3\": \"String\", \"adm0_a3_is\": \"String\", \"adm0_a3_un\": \"Number\", \"adm0_a3_us\": \"String\", \"adm0_a3_wb\": \"Number\", \"adm0_dif\": \"Number\", \"admin\": \"String\", \"brk_a3\": \"String\", \"brk_diff\": \"Number\", \"brk_name\": \"String\", \"continent\": \"String\", \"economy\": \"String\", \"featurecla\": \"String\", \"formal_en\": \"String\", \"gdp_md_est\": \"Number\", \"gdp_year\": \"Number\", \"geou_dif\": \"Number\", \"geounit\": \"String\", \"gu_a3\": \"String\", \"homepart\": \"Number\", \"income_grp\": \"String\", \"iso_a2\": \"String\", \"iso_a3\": \"String\", \"iso_n3\": \"String\", \"labelrank\": \"Number\", \"lastcensus\": \"Number\", \"level\": \"Number\", \"long_len\": \"Number\", \"mapcolor13\": \"Number\", \"mapcolor7\": \"Number\", \"mapcolor8\": \"Number\", \"mapcolor9\": \"Number\", \"name\": \"String\", \"name_len\": \"Number\", \"name_long\": \"String\", \"name_sort\": \"String\", \"pop_est\": \"Number\", \"pop_year\": \"Number\", \"postal\": \"String\", \"region_un\": \"String\", \"region_wb\": \"String\", \"scalerank\": \"Number\", \"sov_a3\": \"String\", \"sovereignt\": \"String\", \"su_a3\": \"String\", \"su_dif\": \"Number\", \"subregion\": \"String\", \"subunit\": \"String\", \"tiny\": \"Number\", \"type\": \"String\", \"un_a3\": \"String\", \"wb_a2\": \"String\", \"wb_a3\": \"String\", \"wikipedia\": \"Number\", \"woe_id\": \"Number\"} }, { \"id\": \"sweden\", \"description\": \"\", \"minzoom\": 0, \"maxzoom\": 0, \"fields\": {\"abbrev\": \"String\", \"abbrev_len\": \"Number\", \"adm0_a3\": \"String\", \"adm0_a3_is\": \"String\", \"adm0_a3_un\": \"Number\", \"adm0_a3_us\": \"String\", \"adm0_a3_wb\": \"Number\", \"adm0_dif\": \"Number\", \"admin\": \"String\", \"brk_a3\": \"String\", \"brk_diff\": \"Number\", \"brk_name\": \"String\", \"continent\": \"String\", \"economy\": \"String\", \"featurecla\": \"String\", \"formal_en\": \"String\", \"gdp_md_est\": \"Number\", \"gdp_year\": \"Number\", \"geou_dif\": \"Number\", \"geounit\": \"String\", \"gu_a3\": \"String\", \"homepart\": \"Number\", \"income_grp\": \"String\", \"iso_a2\": \"String\", \"iso_a3\": \"String\", \"iso_n3\": \"String\", \"labelrank\": \"Number\", \"lastcensus\": \"Number\", \"level\": \"Number\", \"long_len\": \"Number\", \"mapcolor13\": \"Number\", \"mapcolor7\": \"Number\", \"mapcolor8\": \"Number\", \"mapcolor9\": \"Number\", \"name\": \"String\", \"name_len\": \"Number\", \"name_long\": \"String\", \"name_sort\": \"String\", \"pop_est\": \"Number\", \"pop_year\": \"Number\", \"postal\": \"String\", \"region_un\": \"String\", \"region_wb\": \"String\", \"scalerank\": \"Number\", \"sov_a3\": \"String\", \"sovereignt\": \"String\", \"su_a3\": \"String\", \"su_dif\": \"Number\", \"subregion\": \"String\", \"subunit\": \"String\", \"tiny\": \"Number\", \"type\": \"String\", \"un_a3\": \"String\", \"wb_a2\": \"String\", \"wb_a3\": \"String\", \"wikipedia\": \"Number\", \"woe_id\": \"Number\"} } ] }",
|
||||
"maxzoom": "0",
|
||||
"minzoom": "0",
|
||||
"name": "tests/named/out/-z0_-Lalgeria@tests%named%alg_-Lalbania@tests%named%alb.json.check.mbtiles",
|
||||
|
@ -423,7 +423,13 @@ int main(int argc, char **argv) {
|
||||
decode(argv[i], csv, file_keys, layernames, &nlayers, outdb, &st, header, mapping, exclude, ifmatched, attribution);
|
||||
}
|
||||
|
||||
mbtiles_write_metadata(outdb, outfile, layernames, st.minzoom, st.maxzoom, st.minlat, st.minlon, st.maxlat, st.maxlon, st.midlat, st.midlon, file_keys, nlayers, 0, attribution.size() != 0 ? attribution.c_str() : NULL);
|
||||
std::map<std::string, layermap_entry> layermap;
|
||||
for (i = 0; i < nlayers; i++) {
|
||||
layermap.insert(std::pair<std::string, layermap_entry>(layernames[i], layermap_entry(layermap.size())));
|
||||
layermap.find(layernames[i])->second.file_keys = file_keys[i];
|
||||
}
|
||||
|
||||
mbtiles_write_metadata(outdb, outfile, layernames, st.minzoom, st.maxzoom, st.minlat, st.minlon, st.maxlat, st.maxlon, st.midlat, st.midlon, file_keys, nlayers, 0, attribution.size() != 0 ? attribution.c_str() : NULL, layermap);
|
||||
mbtiles_close(outdb, argv);
|
||||
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user