mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 16:35:40 +02:00
Straighten out the extra tilestat attributes in some joined tilesets
The problem was in the case where the CSV provided a new value for an attribute that replaced an existing value. Both the old and new value were being included in the tilestats instead of just the new.
This commit is contained in:
+21
-32
@@ -105,15 +105,12 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
|
||||
mvt_feature outfeature;
|
||||
int matched = 0;
|
||||
|
||||
std::map<std::string, type_and_string> for_tilestats;
|
||||
|
||||
if (feat.has_id) {
|
||||
outfeature.has_id = true;
|
||||
outfeature.id = feat.id;
|
||||
}
|
||||
|
||||
std::map<std::string, mvt_value> attributes;
|
||||
std::map<std::string, int> types;
|
||||
std::map<std::string, std::pair<mvt_value, type_and_string>> attributes;
|
||||
std::vector<std::string> key_order;
|
||||
|
||||
for (size_t t = 0; t + 1 < feat.tags.size(); t += 2) {
|
||||
@@ -152,15 +149,12 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
|
||||
}
|
||||
|
||||
if (exclude.count(std::string(key)) == 0) {
|
||||
attributes.insert(std::pair<std::string, mvt_value>(key, val));
|
||||
types.insert(std::pair<std::string, int>(key, type));
|
||||
key_order.push_back(key);
|
||||
|
||||
type_and_string tas;
|
||||
tas.type = type;
|
||||
tas.string = value;
|
||||
|
||||
for_tilestats.insert(std::pair<std::string, type_and_string>(key, tas));
|
||||
attributes.insert(std::pair<std::string, std::pair<mvt_value, type_and_string>>(key, std::pair<mvt_value, type_and_string>(val, tas)));
|
||||
key_order.push_back(key);
|
||||
}
|
||||
|
||||
if (header.size() > 0 && strcmp(key, header[0].c_str()) == 0) {
|
||||
@@ -199,37 +193,31 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
|
||||
if (fa != attributes.end()) {
|
||||
attributes.erase(fa);
|
||||
}
|
||||
auto ft = types.find(sjoinkey);
|
||||
if (ft != types.end()) {
|
||||
types.erase(ft);
|
||||
}
|
||||
|
||||
attributes.insert(std::pair<std::string, mvt_value>(sjoinkey, outval));
|
||||
types.insert(std::pair<std::string, int>(sjoinkey, attr_type));
|
||||
key_order.push_back(sjoinkey);
|
||||
|
||||
type_and_string tas;
|
||||
tas.type = outval.type;
|
||||
tas.string = joinval;
|
||||
|
||||
for_tilestats.insert(std::pair<std::string, type_and_string>(joinkey, tas));
|
||||
attributes.insert(std::pair<std::string, std::pair<mvt_value, type_and_string>>(joinkey, std::pair<mvt_value, type_and_string>(outval, tas)));
|
||||
key_order.push_back(joinkey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// To keep attributes in their original order instead of alphabetical
|
||||
for (auto k : key_order) {
|
||||
auto fa = attributes.find(k);
|
||||
|
||||
if (fa != attributes.end()) {
|
||||
outlayer.tag(outfeature, k, fa->second);
|
||||
attributes.erase(fa);
|
||||
}
|
||||
}
|
||||
|
||||
if (matched || !ifmatched) {
|
||||
// To keep attributes in their original order instead of alphabetical
|
||||
for (auto k : key_order) {
|
||||
auto fa = attributes.find(k);
|
||||
|
||||
if (fa != attributes.end()) {
|
||||
outlayer.tag(outfeature, k, fa->second.first);
|
||||
add_to_file_keys(file_keys->second.file_keys, k, fa->second.second);
|
||||
attributes.erase(fa);
|
||||
}
|
||||
}
|
||||
|
||||
outfeature.type = feat.type;
|
||||
outfeature.geometry = feat.geometry;
|
||||
|
||||
@@ -243,10 +231,6 @@ void handle(std::string message, int z, unsigned x, unsigned y, std::map<std::st
|
||||
features_added++;
|
||||
outlayer.features.push_back(outfeature);
|
||||
|
||||
for (auto attr : for_tilestats) {
|
||||
add_to_file_keys(file_keys->second.file_keys, attr.first, attr.second);
|
||||
}
|
||||
|
||||
if (z < file_keys->second.minzoom) {
|
||||
file_keys->second.minzoom = z;
|
||||
}
|
||||
@@ -1004,6 +988,11 @@ int main(int argc, char **argv) {
|
||||
int ifmatched = 0;
|
||||
|
||||
CPUS = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
|
||||
const char *TIPPECANOE_MAX_THREADS = getenv("TIPPECANOE_MAX_THREADS");
|
||||
if (TIPPECANOE_MAX_THREADS != NULL) {
|
||||
CPUS = atoi(TIPPECANOE_MAX_THREADS);
|
||||
}
|
||||
if (CPUS < 1) {
|
||||
CPUS = 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user