diff --git a/geojson.cpp b/geojson.cpp index 956825b..a30a326 100644 --- a/geojson.cpp +++ b/geojson.cpp @@ -434,43 +434,12 @@ int serialize_geometry(json_object *geometry, json_object *properties, json_obje } if (tas.type >= 0) { + type_and_string attrib; + attrib.type = metatype[m - 1]; + attrib.string = metaval[m - 1]; + auto fk = layermap->find(layername); - - auto fka = fk->second.file_keys.find(tas.string); - if (fka == fk->second.file_keys.end()) { - fk->second.file_keys.insert(std::pair(tas.string, type_and_string_stats())); - fka = fk->second.file_keys.find(tas.string); - } - - if (track) { - if (fka == fk->second.file_keys.end()) { - fprintf(stderr, "Can't happen (tilestats)\n"); - exit(EXIT_FAILURE); - } - - type_and_string attrib; - attrib.type = metatype[m - 1]; - attrib.string = metaval[m - 1]; - - if (attrib.type == mvt_double) { - double d = atof(attrib.string.c_str()); - - if (d < fka->second.min) { - fka->second.min = d; - } - if (d > fka->second.max) { - fka->second.max = d; - } - } - - if (!fka->second.sample_values.count(attrib)) { - if (fka->second.sample_values.size() < 1000) { - fka->second.sample_values.insert(attrib); - } - } - - fka->second.type |= (1 << attrib.type); - } + add_to_file_keys(fk->second.file_keys, metakey[m - 1], attrib); } } } diff --git a/mbtiles.cpp b/mbtiles.cpp index 937156d..17428ed 100644 --- a/mbtiles.cpp +++ b/mbtiles.cpp @@ -568,3 +568,35 @@ std::map merge_layermaps(std::vector &file_keys, std::string const &attrib, type_and_string const &val) { + auto fka = file_keys.find(attrib); + if (fka == file_keys.end()) { + file_keys.insert(std::pair(attrib, type_and_string_stats())); + fka = file_keys.find(attrib); + } + + if (fka == file_keys.end()) { + fprintf(stderr, "Can't happen (tilestats)\n"); + exit(EXIT_FAILURE); + } + + if (val.type == mvt_double) { + double d = atof(val.string.c_str()); + + if (d < fka->second.min) { + fka->second.min = d; + } + if (d > fka->second.max) { + fka->second.max = d; + } + } + + if (!fka->second.sample_values.count(val)) { + if (fka->second.sample_values.size() < 1000) { + fka->second.sample_values.insert(val); + } + } + + fka->second.type |= (1 << val.type); +} diff --git a/mbtiles.hpp b/mbtiles.hpp index b482e5e..80dcad7 100644 --- a/mbtiles.hpp +++ b/mbtiles.hpp @@ -46,4 +46,6 @@ void aprintf(std::string *buf, const char *format, ...); std::map merge_layermaps(std::vector > const &maps); +void add_to_file_keys(std::map &file_keys, std::string const &layername, type_and_string const &val); + #endif diff --git a/tile-join.cpp b/tile-join.cpp index b6536ff..2a8ce6f 100644 --- a/tile-join.cpp +++ b/tile-join.cpp @@ -154,28 +154,11 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map(key, type)); key_order.push_back(key); - auto st = file_keys->second.file_keys.find(key); - if (st == file_keys->second.file_keys.end()) { - file_keys->second.file_keys.insert(std::pair(key, type_and_string_stats())); - st = file_keys->second.file_keys.find(key); - } + type_and_string tas; + tas.type = type; + tas.string = value; - if (type == mvt_double) { - double d = atof(value.c_str()); - if (d < st->second.min) { - st->second.min = d; - } - if (d > st->second.max) { - st->second.max = d; - } - } - - if (st->second.sample_values.size() < 1000) { - type_and_string tas; - tas.type = type; - tas.string = value; - st->second.sample_values.insert(tas); - } + add_to_file_keys(file_keys->second.file_keys, key, tas); } if (header.size() > 0 && strcmp(key, header[0].c_str()) == 0) { @@ -223,28 +206,11 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map(sjoinkey, attr_type)); key_order.push_back(sjoinkey); - auto st = file_keys->second.file_keys.find(joinkey); - if (st == file_keys->second.file_keys.end()) { - file_keys->second.file_keys.insert(std::pair(joinkey, type_and_string_stats())); - st = file_keys->second.file_keys.find(joinkey); - } + type_and_string tas; + tas.type = outval.type; + tas.string = joinval; - if (st->second.sample_values.size() < 1000) { - type_and_string tas; - tas.type = outval.type; - tas.string = joinval; - st->second.sample_values.insert(tas); - } - - if (outval.type == mvt_double) { - double d = atof(joinval.c_str()); - if (d < st->second.min) { - st->second.min = d; - } - if (d > st->second.max) { - st->second.max = d; - } - } + add_to_file_keys(file_keys->second.file_keys, joinkey, tas); } } }