mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-01-21 20:08:20 +00:00
Factor out duplicated tilestats code
This commit is contained in:
parent
7b03e1ee87
commit
3cafef89f1
41
geojson.cpp
41
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<std::string, type_and_string_stats>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
32
mbtiles.cpp
32
mbtiles.cpp
@ -568,3 +568,35 @@ std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void add_to_file_keys(std::map<std::string, type_and_string_stats> &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<std::string, type_and_string_stats>(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);
|
||||
}
|
||||
|
@ -46,4 +46,6 @@ void aprintf(std::string *buf, const char *format, ...);
|
||||
|
||||
std::map<std::string, layermap_entry> merge_layermaps(std::vector<std::map<std::string, layermap_entry> > const &maps);
|
||||
|
||||
void add_to_file_keys(std::map<std::string, type_and_string_stats> &file_keys, std::string const &layername, type_and_string const &val);
|
||||
|
||||
#endif
|
||||
|
@ -154,28 +154,11 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
|
||||
types.insert(std::pair<std::string, int>(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<std::string, type_and_string_stats>(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<std::st
|
||||
types.insert(std::pair<std::string, int>(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<std::string, type_and_string_stats>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user