From ecb8d9705d1b90f3dce219b0e34c6c7939319729 Mon Sep 17 00:00:00 2001 From: Lev Dragunov Date: Tue, 2 Feb 2016 18:01:11 +0300 Subject: [PATCH] Capital filtration enhancements. --- generator/tag_admixer.hpp | 24 ++++++++++++++++++------ generator/towns_dumper.hpp | 12 ++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/generator/tag_admixer.hpp b/generator/tag_admixer.hpp index a22a2e5b1e..30f4ece48d 100644 --- a/generator/tag_admixer.hpp +++ b/generator/tag_admixer.hpp @@ -25,8 +25,9 @@ public: string oneLine; while (getline(input, oneLine, '\n')) { + // String format: <>. auto pos = oneLine.find(';'); - if (pos < oneLine.length()) + if (pos != string::npos) { uint64_t wayId; CHECK(strings::to_uint64(oneLine.substr(0, pos), wayId),()); @@ -49,12 +50,23 @@ public: string oneLine; while (getline(input, oneLine, '\n')) { + // String format: <>. + // First ';'. auto pos = oneLine.find(";"); - if (pos < oneLine.length()) + if (pos != string::npos) { - uint64_t nodeId; - if (strings::to_uint64(oneLine.substr(0, pos), nodeId)) - m_capitals.insert(nodeId); + // Second ';'. + pos = oneLine.find(";", pos + 1); + if (pos != string::npos) + { + uint64_t nodeId; + // Third ';'. + auto endPos = oneLine.find(";", pos + 1); + if (endPos == string::npos) + endPos = oneLine.length() - 1; + if (strings::to_uint64(oneLine.substr(pos + 1, endPos - pos), nodeId)) + m_capitals.insert(nodeId); + } } } } @@ -88,7 +100,7 @@ public: } catch (ifstream::failure const &) { - LOG(LWARNING, ("Can't read the world level capitals file! Generating world without roads. Path:", capitalsFile)); + LOG(LWARNING, ("Can't read the world level capitals file! Generating world without towns admixing. Path:", capitalsFile)); return; } } diff --git a/generator/towns_dumper.hpp b/generator/towns_dumper.hpp index 61ec3d9991..d0fa465517 100644 --- a/generator/towns_dumper.hpp +++ b/generator/towns_dumper.hpp @@ -6,6 +6,7 @@ #include "base/string_utils.hpp" +#include "std/limits.hpp" #include "std/string.hpp" #include "std/vector.hpp" @@ -22,6 +23,7 @@ public: uint64_t population = 1; bool town = false; bool capital = false; + int admin_level = numeric_limits::max(); for (auto const & tag : em.Tags()) { string key(tag.key), value(tag.value); @@ -30,6 +32,11 @@ public: if (!strings::to_uint64(value, population)) continue; } + else if (key == "admin_level") + { + if (!strings::to_int(value, admin_level)) + continue; + } else if (key == "capital" && value == "yes") { capital = true; @@ -39,6 +46,11 @@ public: town = true; } } + + // Ignore regional capitals. + if (capital && admin_level > 2) + capital = false; + if (town || capital) m_records.emplace_back(em.lat, em.lon, em.id, capital, population); }