Capital filtration enhancements.

This commit is contained in:
Lev Dragunov 2016-02-02 18:01:11 +03:00 committed by Sergey Yershov
parent 139eebd7e6
commit ecb8d9705d
2 changed files with 30 additions and 6 deletions

View file

@ -25,8 +25,9 @@ public:
string oneLine;
while (getline(input, oneLine, '\n'))
{
// String format: <<id;tag>>.
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: <<lat;lon;id;is_capital>>.
// 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;
}
}

View file

@ -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<int>::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);
}