Tag admixer class.

This commit is contained in:
Lev Dragunov 2016-01-26 13:02:23 +03:00 committed by Sergey Yershov
parent 8b618b2ebb
commit 71bf45d883
5 changed files with 95 additions and 7 deletions

View file

@ -66,4 +66,5 @@ HEADERS += \
update_generator.hpp \
ways_merger.hpp \
world_map_generator.hpp \
tag_admixer.hpp

View file

@ -28,5 +28,6 @@ SOURCES += \
osm_type_test.cpp \
source_data.cpp \
source_to_element_test.cpp \
tag_admixer_test.cpp \
tesselator_test.cpp \
triangles_tree_coding_test.cpp \

View file

@ -0,0 +1,19 @@
#include "testing/testing.hpp"
#include "generator/tag_admixer.hpp"
#include <std/map.hpp>
UNIT_TEST(ParserTests)
{
map<uint64_t, string> ways;
WaysParserHelper parser(ways);
parser.ParseString("140247102;world_level\n86398306;another_level\n294584441;world_level");
TEST(ways.find(140247102) != ways.end(), ());
TEST_EQUAL(ways[140247102], string("world_level"), ());
TEST(ways.find(86398306) != ways.end(), ());
TEST_EQUAL(ways[86398306], string("another_level"), ());
TEST(ways.find(294584441) != ways.end(), ());
TEST_EQUAL(ways[294584441], string("world_level"), ());
TEST(ways.find(140247101) == ways.end(), ());
}

View file

@ -2,13 +2,14 @@
#include "generator/feature_generator.hpp"
#include "generator/intermediate_data.hpp"
#include "generator/intermediate_elements.hpp"
#include "generator/osm_translator.hpp"
#include "generator/osm_o5m_source.hpp"
#include "generator/osm_xml_source.hpp"
#include "generator/osm_source.hpp"
#include "generator/polygonizer.hpp"
#include "generator/world_map_generator.hpp"
#include "generator/osm_element.hpp"
#include "generator/osm_o5m_source.hpp"
#include "generator/osm_source.hpp"
#include "generator/osm_translator.hpp"
#include "generator/osm_xml_source.hpp"
#include "generator/polygonizer.hpp"
#include "generator/tag_admixer.hpp"
#include "generator/world_map_generator.hpp"
#include "indexer/classificator.hpp"
#include "geometry/mercator.hpp"
@ -496,7 +497,9 @@ bool GenerateFeaturesImpl(feature::GenerateInfo & info)
bucketer, cache, info.m_makeCoasts ? classif().GetCoastType() : 0,
info.GetAddressesFileName());
auto fn = [&parser](OsmElement * e) { parser.EmitElement(e); };
TagAdmixer tagAdmixer(info.GetIntermediateFileName("ways",".csv"));
// Here we can add new tags to element!!!
auto fn = [&parser, &tagAdmixer](OsmElement * e) { parser.EmitElement(tagAdmixer(e)); };
SourceReader reader = info.m_osmFileName.empty() ? SourceReader() : SourceReader(info.m_osmFileName);
switch (info.m_osmFileType)

64
generator/tag_admixer.hpp Normal file
View file

@ -0,0 +1,64 @@
#pragma once
#include "generator/osm_element.hpp"
#include "coding/file_reader.hpp"
#include "std/map.hpp"
#include "std/string.hpp"
class WaysParserHelper
{
public:
WaysParserHelper(map<uint64_t, string> & ways) : m_ways(ways) {}
void ParseString(string const & input)
{
stringstream stream(input);
string oneLine;
while (getline(stream, oneLine, '\n'))
{
auto pos = oneLine.find(';');
if (pos < oneLine.length())
{
uint64_t wayId = stoll(oneLine.substr(0, pos));
m_ways[wayId] = oneLine.substr(pos + 1, oneLine.length() - pos - 1);
}
}
}
private:
map<uint64_t, string> & m_ways;
};
class TagAdmixer
{
public:
TagAdmixer(string const & fileName) : m_ferryTag("route", "ferry")
{
string data;
FileReader reader(fileName);
reader.ReadAsString(data);
WaysParserHelper parser(m_ways);
parser.ParseString(data);
}
OsmElement * operator()(OsmElement * e)
{
if (e == nullptr)
return e;
if (e->type != OsmElement::EntityType::Way || m_ways.find(e->id) == m_ways.end())
return e;
// Exclude ferry routes.
if (find(e->Tags().begin(), e->Tags().end(), m_ferryTag) != e->Tags().end())
return e;
e->AddTag("highway", m_ways[e->id]);
return e;
}
private:
map<uint64_t, string> m_ways;
OsmElement::Tag const m_ferryTag;
};