diff --git a/mbtiles.cpp b/mbtiles.cpp index f56ea043..a9bed67c 100644 --- a/mbtiles.cpp +++ b/mbtiles.cpp @@ -261,7 +261,7 @@ void tilestats(std::map const &layermap1, size_t el state.nospace = true; state.json_write_string(geomtype); - size_t attrib_count = layer.second.file_keys.size(); + size_t attrib_count = layer.second.tilestats.size(); if (attrib_count > max_tilestats_attributes) { attrib_count = max_tilestats_attributes; } @@ -277,7 +277,7 @@ void tilestats(std::map const &layermap1, size_t el state.json_write_array(); size_t attrs = 0; - for (auto attribute : layer.second.file_keys) { + for (auto attribute : layer.second.tilestats) { if (attrs == elements) { break; } @@ -745,7 +745,7 @@ metadata make_metadata(const char *fname, int minzoom, int maxzoom, double minla bool first = true; size_t attribute_count = 0; - for (auto j = fk->second.file_keys.begin(); j != fk->second.file_keys.end(); ++j) { + for (auto j = fk->second.tilestats.begin(); j != fk->second.tilestats.end(); ++j) { if (first) { first = false; } @@ -852,16 +852,16 @@ std::map merge_layermaps(std::vectorsecond.file_keys.begin(); fk != map->second.file_keys.end(); ++fk) { + for (auto fk = map->second.tilestats.begin(); fk != map->second.tilestats.end(); ++fk) { std::string attribname = fk->first; if (trunc) { attribname = truncate16(attribname, 256); } - auto fk2 = out_entry->second.file_keys.find(attribname); + auto fk2 = out_entry->second.tilestats.find(attribname); - if (fk2 == out_entry->second.file_keys.end()) { - out_entry->second.file_keys.insert(std::pair(attribname, fk->second)); + if (fk2 == out_entry->second.tilestats.end()) { + out_entry->second.tilestats.insert(std::pair(attribname, fk->second)); } else { for (auto val : fk->second.sample_values) { auto pt = std::lower_bound(fk2->second.sample_values.begin(), fk2->second.sample_values.end(), val); @@ -901,18 +901,18 @@ std::map merge_layermaps(std::vector &file_keys, std::string const &attrib, serial_val const &val) { +void add_to_tilestats(std::map &tilestats, std::string const &attrib, serial_val const &val) { if (val.type == mvt_null) { return; } - auto fka = file_keys.find(attrib); - if (fka == file_keys.end()) { - file_keys.insert(std::pair(attrib, tilestat())); - fka = file_keys.find(attrib); + auto fka = tilestats.find(attrib); + if (fka == tilestats.end()) { + tilestats.insert(std::pair(attrib, tilestat())); + fka = tilestats.find(attrib); } - if (fka == file_keys.end()) { + if (fka == tilestats.end()) { fprintf(stderr, "Can't happen (tilestats)\n"); exit(EXIT_IMPOSSIBLE); } diff --git a/mbtiles.hpp b/mbtiles.hpp index 52c19517..b1837668 100644 --- a/mbtiles.hpp +++ b/mbtiles.hpp @@ -18,7 +18,7 @@ struct tilestat { struct layermap_entry { size_t id = 0; - std::map file_keys{}; + std::map tilestats{}; int minzoom = 0; int maxzoom = 0; std::string description = ""; @@ -76,7 +76,7 @@ void mbtiles_close(sqlite3 *outdb, const char *pgm); std::map merge_layermaps(std::vector > const &maps); std::map merge_layermaps(std::vector > const &maps, bool trunc); -void add_to_file_keys(std::map &file_keys, std::string const &layername, serial_val const &val); +void add_to_tilestats(std::map &tilestats, std::string const &layername, serial_val const &val); unsigned long long fnv1a(std::string const &s); diff --git a/plugin.cpp b/plugin.cpp index 30ee0fdb..1ace7d96 100644 --- a/plugin.cpp +++ b/plugin.cpp @@ -278,7 +278,7 @@ std::vector parse_layers(int fd, int z, unsigned x, unsigned y, std:: attrib.type = tp; attrib.s = s; - add_to_file_keys(fk->second.file_keys, std::string(properties->value.object.keys[i]->value.string.string), attrib); + add_to_tilestats(fk->second.tilestats, std::string(properties->value.object.keys[i]->value.string.string), attrib); } } @@ -520,7 +520,7 @@ serial_feature parse_feature(json_pull *jp, int z, unsigned x, unsigned y, std:: attrib.type = v.type; if (!postfilter) { - add_to_file_keys(fk->second.file_keys, std::string(properties->value.object.keys[i]->value.string.string), attrib); + add_to_tilestats(fk->second.tilestats, std::string(properties->value.object.keys[i]->value.string.string), attrib); } } } diff --git a/serial.cpp b/serial.cpp index 7317a851..bcd7c540 100644 --- a/serial.cpp +++ b/serial.cpp @@ -828,7 +828,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) { if (!sst->filters) { for (size_t i = 0; i < sf.full_keys.size(); i++) { auto fk = sst->layermap->find(sf.layername); - add_to_file_keys(fk->second.file_keys, sf.full_keys[i], sf.full_values[i]); + add_to_tilestats(fk->second.tilestats, sf.full_keys[i], sf.full_values[i]); } } diff --git a/tile-join.cpp b/tile-join.cpp index 32ed5a52..7354a960 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -149,7 +149,7 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::map(layer.name, layermap_entry(layermap.size()))); - file_keys = layermap.find(layer.name); - file_keys->second.minzoom = z; - file_keys->second.maxzoom = z; + tilestats = layermap.find(layer.name); + tilestats->second.minzoom = z; + tilestats->second.maxzoom = z; } // To keep attributes in their original order instead of alphabetical @@ -282,7 +282,7 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::mapsecond.first); - add_to_file_keys(file_keys->second.file_keys, k, fa->second.second); + add_to_tilestats(tilestats->second.tilestats, k, fa->second.second); attributes.erase(fa); } } @@ -300,19 +300,19 @@ void append_tile(std::string message, int z, unsigned x, unsigned y, std::mapsecond.minzoom) { - file_keys->second.minzoom = z; + if (z < tilestats->second.minzoom) { + tilestats->second.minzoom = z; } - if (z > file_keys->second.maxzoom) { - file_keys->second.maxzoom = z; + if (z > tilestats->second.maxzoom) { + tilestats->second.maxzoom = z; } if (feat.type == mvt_point) { - file_keys->second.points++; + tilestats->second.points++; } else if (feat.type == mvt_linestring) { - file_keys->second.lines++; + tilestats->second.lines++; } else if (feat.type == mvt_polygon) { - file_keys->second.polygons++; + tilestats->second.polygons++; } } } diff --git a/tile.cpp b/tile.cpp index 5b9f8ef2..2e5cd7b0 100644 --- a/tile.cpp +++ b/tile.cpp @@ -1822,7 +1822,7 @@ void add_tilestats(std::string const &layername, int z, std::vectorsecond.file_keys, key, val); + add_to_tilestats(fk->second.tilestats, key, val); } void preserve_attribute(attribute_op op, serial_feature &, char *stringpool, long long *pool_off, std::string &key, serial_val &val, partial &p) {