Also sort the keys

This commit is contained in:
Eric Fischer 2018-07-23 15:19:18 -07:00
parent e8011c59ba
commit b7dc84bdd7

23
mvt.cpp
View File

@ -636,14 +636,21 @@ void mvt_layer::tag_v3(mvt_feature &feature, std::string key, mvt_value value) {
void mvt_layer::reorder_values() {
std::vector<mvt_value> orig_values = values;
std::vector<std::string> orig_keys = keys;
std::sort(values.begin(), values.end());
std::sort(keys.begin(), keys.end());
std::map<mvt_value, size_t> new_value_map;
for (size_t i = 0; i < values.size(); i++) {
new_value_map.insert(std::pair<mvt_value, size_t>(values[i], i));
}
std::map<std::string, size_t> new_key_map;
for (size_t i = 0; i < keys.size(); i++) {
new_key_map.insert(std::pair<std::string, size_t>(keys[i], i));
}
for (size_t i = 0; i < features.size(); i++) {
for (size_t j = 1; j < features[i].tags.size(); j += 2) {
mvt_value v = orig_values[features[i].tags[j]];
@ -652,12 +659,18 @@ void mvt_layer::reorder_values() {
if (f == new_value_map.end()) {
std::string vs = v.toString();
fprintf(stderr, "Internal error: value %s was lost\n", vs.c_str());
#if 0
for (auto a = new_value_map.begin(); a != new_value_map.end(); ++a) {
std::string const vs2 = a->first.toString();
fprintf(stderr, "%s: %zu\n", vs2.c_str(), a->second);
exit(EXIT_FAILURE);
}
#endif
features[i].tags[j] = f->second;
}
for (size_t j = 0; j < features[i].tags.size(); j += 2) {
std::string k = orig_keys[features[i].tags[j]];
auto f = new_key_map.find(k);
if (f == new_key_map.end()) {
fprintf(stderr, "Internal error: key %s was lost\n", k.c_str());
exit(EXIT_FAILURE);
}