Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLev Dragunov <l.dragunov@corp.mail.ru>2016-01-29 11:59:54 +0300
committerSergey Yershov <yershov@corp.mail.ru>2016-03-23 16:17:04 +0300
commit139eebd7e68dd810e82814847004aaa05b6a2bf8 (patch)
treec987bef175675976b5f73bf06ae8086026b79a85
parent73f98de5322f3fdd57a2ede294516b21f7a38685 (diff)
Capitals population update
-rw-r--r--generator/osm_element.cpp12
-rw-r--r--generator/osm_element.hpp1
-rw-r--r--generator/osm_source.cpp2
-rw-r--r--generator/tag_admixer.hpp68
-rwxr-xr-xtools/unix/generate_planet.sh10
5 files changed, 78 insertions, 15 deletions
diff --git a/generator/osm_element.cpp b/generator/osm_element.cpp
index 30335f3305..0c133937c1 100644
--- a/generator/osm_element.cpp
+++ b/generator/osm_element.cpp
@@ -62,6 +62,18 @@ 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
{
diff --git a/generator/osm_element.hpp b/generator/osm_element.hpp
index 20799d90be..c3ba054247 100644
--- a/generator/osm_element.hpp
+++ b/generator/osm_element.hpp
@@ -129,6 +129,7 @@ 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);
};
string DebugPrint(OsmElement const & e);
diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp
index cbc5075814..a75bd84beb 100644
--- a/generator/osm_source.cpp
+++ b/generator/osm_source.cpp
@@ -505,7 +505,7 @@ bool GenerateFeaturesImpl(feature::GenerateInfo & info)
bucketer, cache, info.m_makeCoasts ? classif().GetCoastType() : 0,
info.GetAddressesFileName());
- TagAdmixer tagAdmixer(info.GetIntermediateFileName("ways",".csv"));
+ TagAdmixer tagAdmixer(info.GetIntermediateFileName("ways",".csv"), info.GetIntermediateFileName("towns",".csv"));
// Here we can add new tags to element!!!
auto fn = [&parser, &tagAdmixer](OsmElement * e) { parser.EmitElement(tagAdmixer(e)); };
diff --git a/generator/tag_admixer.hpp b/generator/tag_admixer.hpp
index 5d2b6f33b5..a22a2e5b1e 100644
--- a/generator/tag_admixer.hpp
+++ b/generator/tag_admixer.hpp
@@ -9,10 +9,17 @@
#include "std/map.hpp"
#include "std/string.hpp"
+namespace
+{
+ constexpr char const kPopulationTag[] = "population";
+ constexpr char const kMinimalWorldLevelPopulation[] = "45000";
+} // namespace
+
class WaysParserHelper
{
public:
WaysParserHelper(map<uint64_t, string> & ways) : m_ways(ways) {}
+
void ParseStream(istream & input)
{
string oneLine;
@@ -32,20 +39,56 @@ private:
map<uint64_t, string> & m_ways;
};
+class CapitalsParserHelper
+{
+public:
+ CapitalsParserHelper(set<uint64_t> & capitals) : m_capitals(capitals) {}
+
+ void ParseStream(istream & input)
+ {
+ string oneLine;
+ while (getline(input, oneLine, '\n'))
+ {
+ auto pos = oneLine.find(";");
+ if (pos < oneLine.length())
+ {
+ uint64_t nodeId;
+ if (strings::to_uint64(oneLine.substr(0, pos), nodeId))
+ m_capitals.insert(nodeId);
+ }
+ }
+ }
+
+private:
+ set<uint64_t> m_capitals;
+};
+
class TagAdmixer
{
public:
- TagAdmixer(string const & fileName) : m_ferryTag("route", "ferry")
+ TagAdmixer(string const & waysFile, string const & capitalsFile) : m_ferryTag("route", "ferry")
{
try
{
- ifstream reader(fileName);
+ ifstream reader(waysFile);
WaysParserHelper parser(m_ways);
parser.ParseStream(reader);
}
catch (ifstream::failure const &)
{
- LOG(LWARNING, ("Can't read the world level ways file! Generating world without roads. Path:", fileName));
+ LOG(LWARNING, ("Can't read the world level ways file! Generating world without roads. Path:", waysFile));
+ return;
+ }
+
+ try
+ {
+ ifstream reader(capitalsFile);
+ CapitalsParserHelper parser(m_capitals);
+ parser.ParseStream(reader);
+ }
+ catch (ifstream::failure const &)
+ {
+ LOG(LWARNING, ("Can't read the world level capitals file! Generating world without roads. Path:", capitalsFile));
return;
}
}
@@ -54,18 +97,25 @@ public:
{
if (e == nullptr)
return e;
- if (e->type != OsmElement::EntityType::Way || m_ways.find(e->id) == m_ways.end())
- return e;
+ if (e->type == OsmElement::EntityType::Way && m_ways.find(e->id) != m_ways.end())
+ {
+ // Exclude ferry routes.
+ if (find(e->Tags().begin(), e->Tags().end(), m_ferryTag) != e->Tags().end())
+ return e;
- // Exclude ferry routes.
- if (find(e->Tags().begin(), e->Tags().end(), m_ferryTag) != e->Tags().end())
+ e->AddTag("highway", m_ways[e->id]);
return e;
-
- e->AddTag("highway", m_ways[e->id]);
+ }
+ else if (e->type == OsmElement::EntityType::Node && m_capitals.find(e->id) != m_capitals.end())
+ {
+ if (!e->UpdateTag(kPopulationTag, kMinimalWorldLevelPopulation))
+ e->AddTag(kPopulationTag, kMinimalWorldLevelPopulation);
+ }
return e;
}
private:
map<uint64_t, string> m_ways;
+ set<uint64_t> m_capitals;
OsmElement::Tag const m_ferryTag;
};
diff --git a/tools/unix/generate_planet.sh b/tools/unix/generate_planet.sh
index dce66a66af..a22ecc114f 100755
--- a/tools/unix/generate_planet.sh
+++ b/tools/unix/generate_planet.sh
@@ -258,11 +258,6 @@ if [ "$MODE" == "coast" ]; then
# Preprocess coastlines to separate intermediate directory
"$GENERATOR_TOOL" --intermediate_data_path="$INTCOASTSDIR/" --node_storage=map --osm_file_type=o5m --osm_file_name="$COASTS_O5M" \
-preprocess 2>> "$LOG_PATH/WorldCoasts.log"
- if [ -z "${OSRM_URL-}" ]; then
- log "OSRM_URL variable not set. World roads will not be calculated."
- else
- python "$ROADS_SCRIPT" "$INTCOASTSDIR" "$OSRM_URL" >>"$LOG_PATH"/road_runner.log
- fi
# Generate temporary coastlines file in the coasts intermediate dir
if ! "$GENERATOR_TOOL" --intermediate_data_path="$INTCOASTSDIR/" --node_storage=map --osm_file_type=o5m --osm_file_name="$COASTS_O5M" \
--user_resource_path="$DATA_PATH/" -make_coasts -fail_on_coasts 2>&1 | tee -a "$LOG_PATH/WorldCoasts.log" | { grep -i 'not merged\|coastline polygons' || true; }
@@ -277,6 +272,11 @@ if [ "$MODE" == "coast" ]; then
fail
fi
fi
+ if [ -z "$OSRM_URL-" ]; then
+ log "OSRM_URL variable not set. World roads will not be calculated."
+ else
+ python "$ROADS_SCRIPT" "$INTCOASTSDIR" "$OSRM_URL" >>"$LOG_PATH"/road_runner.log
+ fi
fi
done
# make a working copy of generated coastlines file