From 1a50ff67daaca26aaa7c058f50411b2647439345 Mon Sep 17 00:00:00 2001 From: vng Date: Thu, 18 Feb 2016 17:39:52 +0300 Subject: [PATCH] =?UTF-8?q?[generator]=20Fixed=20bug=20with=20capital?= =?UTF-8?q?=E2=80=99s=20population=20admixing.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- generator/osm_element.cpp | 17 ++++------------- generator/osm_element.hpp | 18 +++++++++++++++++- generator/tag_admixer.hpp | 16 +++++++++------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/generator/osm_element.cpp b/generator/osm_element.cpp index 0c133937c1..cf22bf41b2 100644 --- a/generator/osm_element.cpp +++ b/generator/osm_element.cpp @@ -32,6 +32,10 @@ string DebugPrint(OsmElement::EntityType e) void OsmElement::AddTag(string const & k, string const & v) { + // Seems like source osm data has empty values. They are useless for us. + if (k.empty() || v.empty()) + return; + #define SKIP_KEY(key) if (strncmp(k.data(), key, sizeof(key)-1) == 0) return; // OSM technical info tags SKIP_KEY("created_by"); @@ -62,19 +66,6 @@ void OsmElement::AddTag(string const & k, string const & v) m_tags.emplace_back(k, v); } -bool OsmElement::UpdateTag(string const & k, string const & v) -{ - for (auto & tag : m_tags) - { - if (tag.key == k) - { - tag.value = v; - return true; - } - } - return false; -} - string OsmElement::ToString(string const & shift) const { stringstream ss; diff --git a/generator/osm_element.hpp b/generator/osm_element.hpp index c3ba054247..4f30ef90a6 100644 --- a/generator/osm_element.hpp +++ b/generator/osm_element.hpp @@ -128,8 +128,24 @@ struct OsmElement { m_members.emplace_back(ref, type, role); } + void AddTag(string const & k, string const & v); - bool UpdateTag(string const & k, string const & v); + template void UpdateTag(string const & k, TFn && fn) + { + for (auto & tag : m_tags) + { + if (tag.key == k) + { + fn(tag.value); + return; + } + } + + string v; + fn(v); + if (!v.empty()) + AddTag(k, v); + } }; string DebugPrint(OsmElement const & e); diff --git a/generator/tag_admixer.hpp b/generator/tag_admixer.hpp index b19e96f5c0..227432209a 100644 --- a/generator/tag_admixer.hpp +++ b/generator/tag_admixer.hpp @@ -9,11 +9,6 @@ #include "std/map.hpp" #include "std/string.hpp" -namespace -{ - constexpr char const kPopulationTag[] = "population"; - constexpr char const kMinimalWorldLevelPopulation[] = "45000"; -} // namespace class WaysParserHelper { @@ -121,8 +116,15 @@ public: } else if (e->type == OsmElement::EntityType::Node && m_capitals.find(e->id) != m_capitals.end()) { - if (!e->UpdateTag(kPopulationTag, kMinimalWorldLevelPopulation)) - e->AddTag(kPopulationTag, kMinimalWorldLevelPopulation); + // Our goal here - to make some capitals visible in World map. + // The simplest way is to upgrade population to 45000, + // according to our visibility rules in mapcss files. + e->UpdateTag("population", [] (string & v) + { + uint64_t n; + if (!strings::to_uint64(v, n) || n < 45000) + v = "45000"; + }); } return e; }