forked from organicmaps/organicmaps-tmp
Using final stage osm ids to feature ids mapping for restriction generation.
This commit is contained in:
parent
cf1f3d1fcc
commit
7ad4551e4c
6 changed files with 56 additions and 51 deletions
|
@ -4,13 +4,14 @@
|
|||
|
||||
#include "base/assert.hpp"
|
||||
|
||||
#include "std/utility.hpp"
|
||||
#include "std/algorithm.hpp"
|
||||
|
||||
#include "std/fstream.hpp"
|
||||
#include "std/iostream.hpp"
|
||||
#include "std/string.hpp"
|
||||
#include "std/utility.hpp"
|
||||
|
||||
namespace gen
|
||||
{
|
||||
|
||||
template <class T> class Accumulator
|
||||
{
|
||||
protected:
|
||||
|
@ -30,6 +31,8 @@ public:
|
|||
{
|
||||
rw::ReadVectorOfPOD(src, m_data);
|
||||
}
|
||||
|
||||
vector<T> const & GetData() const { return m_data; }
|
||||
};
|
||||
|
||||
class OsmID2FeatureID : public Accumulator<pair<uint64_t, uint32_t>>
|
||||
|
@ -63,5 +66,4 @@ public:
|
|||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace gen
|
||||
|
|
|
@ -101,7 +101,7 @@ UNIT_TEST(RestrictionTest_ParseFeatureId2OsmIdsMapping)
|
|||
RestrictionCollector restrictionCollector("" /* restrictionPath */, "" /* featureIdToOsmIdsPath */);
|
||||
|
||||
Platform const & platform = Platform();
|
||||
restrictionCollector.ParseFeatureId2OsmIdsMapping(
|
||||
restrictionCollector.ParseOsmIdToFeatureIdMapping(
|
||||
my::JoinFoldersToPath(platform.WritableDir(), kFeatureIdToOsmIdsPath));
|
||||
|
||||
vector<pair<uint64_t, uint32_t>> const expectedOsmIds2FeatureId = {
|
||||
|
|
|
@ -244,7 +244,7 @@ int main(int argc, char ** argv)
|
|||
{
|
||||
routing::BuildRoadRestrictions(
|
||||
datFile, genInfo.GetIntermediateFileName(genInfo.m_restrictions, "" /* extention */),
|
||||
genInfo.GetIntermediateFileName(genInfo.m_featureIdToOsmIds, "" /* extention */));
|
||||
genInfo.GetTargetFileName(country) + OSM2FEATURE_FILE_EXTENSION);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
#include "generator/restriction_collector.hpp"
|
||||
|
||||
#include "generator/gen_mwm_info.hpp"
|
||||
|
||||
#include "coding/file_reader.hpp"
|
||||
#include "coding/reader.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
#include "base/logging.hpp"
|
||||
#include "base/scope_guard.hpp"
|
||||
|
@ -31,17 +36,17 @@ bool ParseLineOfNumbers(strings::SimpleTokenizer & iter, vector<uint64_t> & numb
|
|||
namespace routing
|
||||
{
|
||||
RestrictionCollector::RestrictionCollector(string const & restrictionPath,
|
||||
string const & featureIdToOsmIdsPath)
|
||||
string const & osmIdsToFeatureIdPath)
|
||||
{
|
||||
MY_SCOPE_GUARD(clean, [this](){
|
||||
m_osmIdToFeatureId.clear();
|
||||
m_restrictions.clear();
|
||||
});
|
||||
|
||||
if (!ParseFeatureId2OsmIdsMapping(featureIdToOsmIdsPath))
|
||||
if (!ParseOsmIdToFeatureIdMapping(osmIdsToFeatureIdPath))
|
||||
{
|
||||
LOG(LWARNING, ("An error happened while parsing feature id to osm ids mapping from file:",
|
||||
featureIdToOsmIdsPath));
|
||||
osmIdsToFeatureIdPath));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -65,34 +70,34 @@ bool RestrictionCollector::IsValid() const
|
|||
[](Restriction const & r) { return !r.IsValid(); }) == end(m_restrictions);
|
||||
}
|
||||
|
||||
bool RestrictionCollector::ParseFeatureId2OsmIdsMapping(string const & featureIdToOsmIdsPath)
|
||||
bool RestrictionCollector::ParseOsmIdToFeatureIdMapping(string const & osmIdsToFeatureIdPath)
|
||||
{
|
||||
ifstream featureIdToOsmIdsStream(featureIdToOsmIdsPath);
|
||||
if (featureIdToOsmIdsStream.fail())
|
||||
return false;
|
||||
LOG(LINFO, ("osmIdsToFeatureIdPath =", osmIdsToFeatureIdPath));
|
||||
|
||||
string line;
|
||||
while (getline(featureIdToOsmIdsStream, line))
|
||||
using OsmIdToFeatureId = pair<uint64_t /* osm id */, uint32_t /* feature id */>;
|
||||
gen::Accumulator<OsmIdToFeatureId> osmIdsToFeatureIds;
|
||||
try
|
||||
{
|
||||
vector<uint64_t> osmIds;
|
||||
strings::SimpleTokenizer iter(line, kDelim);
|
||||
if (!ParseLineOfNumbers(iter, osmIds))
|
||||
{
|
||||
LOG(LWARNING, ("Cannot parse feature id to osm ids mapping. Line:", line));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (osmIds.size() < 2)
|
||||
{
|
||||
LOG(LWARNING, ("Parse result of mapping feature id to osm ids is too small. Line:",
|
||||
line));
|
||||
return false; // Every line should contain feature id and at least one osm id.
|
||||
}
|
||||
|
||||
uint32_t const featureId = static_cast<uint32_t>(osmIds.front());
|
||||
osmIds.erase(osmIds.begin());
|
||||
AddFeatureId(featureId, osmIds);
|
||||
FileReader reader(osmIdsToFeatureIdPath);
|
||||
ReaderSource<FileReader> src(reader);
|
||||
osmIdsToFeatureIds.Read(src);
|
||||
}
|
||||
catch (FileReader::Exception const & e)
|
||||
{
|
||||
LOG(LERROR, ("Exception while reading file:", osmIdsToFeatureIdPath, ". Msg:", e.Msg()));
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<OsmIdToFeatureId> const & mapping = osmIdsToFeatureIds.GetData();
|
||||
if (mapping.empty())
|
||||
{
|
||||
LOG(LINFO, ("No osm ids to feature ids mapping in file", osmIdsToFeatureIdPath));
|
||||
return true;
|
||||
}
|
||||
|
||||
for (auto const osmIdToFeatureId : mapping)
|
||||
AddFeatureId(osmIdToFeatureId.second /* feature id */, osmIdToFeatureId.first /* osm id */);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -150,18 +155,15 @@ bool RestrictionCollector::AddRestriction(Restriction::Type type, vector<uint64_
|
|||
return true;
|
||||
}
|
||||
|
||||
void RestrictionCollector::AddFeatureId(uint32_t featureId, vector<uint64_t> const & osmIds)
|
||||
void RestrictionCollector::AddFeatureId(uint32_t featureId, uint64_t osmId)
|
||||
{
|
||||
// Note. One |featureId| could correspond to several osm ids.
|
||||
// But for road feature |featureId| corresponds to exactly one osm id.
|
||||
for (uint64_t const & osmId : osmIds)
|
||||
auto const result = m_osmIdToFeatureId.insert(make_pair(osmId, featureId));
|
||||
if (result.second == false)
|
||||
{
|
||||
auto const result = m_osmIdToFeatureId.insert(make_pair(osmId, featureId));
|
||||
if (result.second == false)
|
||||
{
|
||||
LOG(LERROR, ("Osm id", osmId, "is included in two feature ids: ", featureId,
|
||||
m_osmIdToFeatureId.find(osmId)->second));
|
||||
}
|
||||
LOG(LERROR, ("Osm id", osmId, "is included in two feature ids: ", featureId,
|
||||
m_osmIdToFeatureId.find(osmId)->second));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,10 +42,10 @@ private:
|
|||
/// 137999, 5170186,
|
||||
/// 138000, 5170209, 5143342,
|
||||
/// 138001, 5170228,
|
||||
/// \param featureIdToOsmIdsPath path to the text file.
|
||||
/// \param osmIdsToFeatureIdPath path to the text file.
|
||||
/// \note Most restrictions consist of type and two linear(road) features.
|
||||
/// \note For the time being only line-point-line restrictions are supported.
|
||||
bool ParseFeatureId2OsmIdsMapping(string const & featureIdToOsmIdsPath);
|
||||
bool ParseOsmIdToFeatureIdMapping(string const & osmIdsToFeatureIdPath);
|
||||
|
||||
/// \brief Parses comma separated text file with line in following format:
|
||||
/// <type of restrictions>, <osm id 1 of the restriction>, <osm id 2>, and so on
|
||||
|
@ -56,9 +56,10 @@ private:
|
|||
/// \param featureIdToOsmIdsPath path to the text file.
|
||||
bool ParseRestrictions(string const & path);
|
||||
|
||||
/// \brief Adds feature id and corresponding vector of |osmIds| to |m_osmIdToFeatureId|.
|
||||
/// \note One feature id (|featureId|) may correspond to several osm ids (|osmIds|).
|
||||
void AddFeatureId(uint32_t featureId, vector<uint64_t> const & osmIds);
|
||||
/// \brief Adds feature id and corresponding |osmId| to |m_osmIdToFeatureId|.
|
||||
/// \note In general one feature id (|featureId|) may correspond to several osm ids (|osmIds|).
|
||||
/// But for road feature one feature id corresponds one osm id.
|
||||
void AddFeatureId(uint32_t featureId, uint64_t osmId);
|
||||
|
||||
/// \brief Adds a restriction (vector of osm id).
|
||||
/// \param type is a type of restriction
|
||||
|
|
|
@ -15,15 +15,15 @@
|
|||
namespace routing
|
||||
{
|
||||
bool BuildRoadRestrictions(string const & mwmPath, string const & restrictionPath,
|
||||
string const & featureIdToOsmIdsPath)
|
||||
string const & osmIdsTofeatureIdsPath)
|
||||
{
|
||||
LOG(LINFO,
|
||||
("BuildRoadRestrictions(", mwmPath, ", ", restrictionPath, ", ", featureIdToOsmIdsPath, ");"));
|
||||
RestrictionCollector restrictionCollector(restrictionPath, featureIdToOsmIdsPath);
|
||||
("BuildRoadRestrictions(", mwmPath, ", ", restrictionPath, ", ", osmIdsTofeatureIdsPath, ");"));
|
||||
RestrictionCollector restrictionCollector(restrictionPath, osmIdsTofeatureIdsPath);
|
||||
if (!restrictionCollector.HasRestrictions() || !restrictionCollector.IsValid())
|
||||
{
|
||||
LOG(LWARNING, ("No valid restrictions for", mwmPath, "It's necessary to check that",
|
||||
restrictionPath, "and", featureIdToOsmIdsPath, "are available."));
|
||||
restrictionPath, "and", osmIdsTofeatureIdsPath, "are available."));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue