Work on relation extract refactoring to support recursive relations (superrelations)
This commit is contained in:
committed by
Patrick Niklaus
parent
7851de9af8
commit
c42e247d87
@@ -323,29 +323,6 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
|
||||
return boost::apply_visitor(to_lua_object(context.state), value);
|
||||
});
|
||||
|
||||
context.state.new_usertype<osmium::RelationMember>(
|
||||
"RelationMember",
|
||||
"role",
|
||||
&osmium::RelationMember::role,
|
||||
"type",
|
||||
&osmium::RelationMember::type,
|
||||
"id",
|
||||
[](const osmium::RelationMember &member) -> osmium::object_id_type {
|
||||
return member.ref();
|
||||
});
|
||||
|
||||
context.state.new_usertype<osmium::Relation>(
|
||||
"Relation",
|
||||
"get_value_by_key",
|
||||
&get_value_by_key<osmium::Relation>,
|
||||
"id",
|
||||
&osmium::Relation::id,
|
||||
"version",
|
||||
&osmium::Relation::version,
|
||||
"members",
|
||||
[](const osmium::Relation &rel) -> const osmium::RelationMemberList & {
|
||||
return rel.members();
|
||||
});
|
||||
|
||||
context.state.new_usertype<osmium::Node>("Node",
|
||||
"location",
|
||||
@@ -440,17 +417,59 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
|
||||
sol::property([](const ExtractionWay &way) { return way.is_left_hand_driving; },
|
||||
[](ExtractionWay &way, bool flag) { way.is_left_hand_driving = flag; }));
|
||||
|
||||
auto getTypedRefBySol = [](const sol::object & obj) -> ExtractionRelation::OsmIDTyped
|
||||
{
|
||||
if (obj.is<osmium::Way>())
|
||||
{
|
||||
osmium::Way * way = obj.as<osmium::Way*>();
|
||||
return { way->id(), osmium::item_type::way };
|
||||
}
|
||||
|
||||
if (obj.is<osmium::Relation>())
|
||||
{
|
||||
osmium::Relation * rel = obj.as<osmium::Relation*>();
|
||||
return { rel->id(), osmium::item_type::relation };
|
||||
}
|
||||
|
||||
if (obj.is<osmium::Node>())
|
||||
{
|
||||
osmium::Node * node = obj.as<osmium::Node*>();
|
||||
return { node->id(), osmium::item_type::node };
|
||||
}
|
||||
|
||||
return ExtractionRelation::OsmIDTyped(0, osmium::item_type::undefined);
|
||||
};
|
||||
|
||||
context.state.new_usertype<ExtractionRelation::OsmIDTyped>(
|
||||
"OsmIDTyped",
|
||||
"id",
|
||||
&ExtractionRelation::OsmIDTyped::GetID,
|
||||
"type",
|
||||
&ExtractionRelation::OsmIDTyped::GetType);
|
||||
|
||||
context.state.new_usertype<ExtractionRelation>(
|
||||
"ExtractionRelation",
|
||||
sol::meta_function::new_index,
|
||||
[](ExtractionRelation &rel, const osmium::RelationMember &member)
|
||||
-> ExtractionRelation::AttributesMap & { return rel.GetMember(member); },
|
||||
sol::meta_function::index,
|
||||
[](ExtractionRelation &rel, const osmium::RelationMember &member)
|
||||
-> ExtractionRelation::AttributesMap & { return rel.GetMember(member); },
|
||||
"restriction",
|
||||
sol::property([](const ExtractionRelation &rel) { return rel.is_restriction; },
|
||||
[](ExtractionRelation &rel, bool flag) { rel.is_restriction = flag; }));
|
||||
"get_value_by_key",
|
||||
[](ExtractionRelation &rel, const char * key) -> const char * { return rel.GetAttr(key); },
|
||||
"get_role",
|
||||
[&getTypedRefBySol](ExtractionRelation &rel, const sol::object & obj) -> const char *
|
||||
{
|
||||
return rel.GetRole(getTypedRefBySol(obj));
|
||||
});
|
||||
|
||||
context.state.new_usertype<ExtractionRelationContainer>(
|
||||
"ExtractionRelationContainer",
|
||||
"get_relations",
|
||||
[&getTypedRefBySol](ExtractionRelationContainer &cont, const sol::object & obj)
|
||||
-> const ExtractionRelationContainer::RelationIDList &
|
||||
{
|
||||
return cont.GetRelations(getTypedRefBySol(obj));
|
||||
},
|
||||
"relation",
|
||||
[](ExtractionRelationContainer &cont, const ExtractionRelation::OsmIDTyped & rel_id) -> const ExtractionRelation &
|
||||
{
|
||||
return cont.GetRelationData(rel_id);
|
||||
});
|
||||
|
||||
context.state.new_usertype<ExtractionSegment>("ExtractionSegment",
|
||||
"source",
|
||||
@@ -633,14 +652,6 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
|
||||
switch (context.api_version)
|
||||
{
|
||||
case 3:
|
||||
{
|
||||
initV2Context();
|
||||
context.relation_function = function_table.value()["process_relation"];
|
||||
|
||||
context.has_relation_function = context.relation_function.valid();
|
||||
break;
|
||||
}
|
||||
|
||||
case 2:
|
||||
{
|
||||
initV2Context();
|
||||
@@ -719,12 +730,10 @@ void Sol2ScriptingEnvironment::ProcessElements(
|
||||
const ExtractionRelationContainer &relations,
|
||||
std::vector<std::pair<const osmium::Node &, ExtractionNode>> &resulting_nodes,
|
||||
std::vector<std::pair<const osmium::Way &, ExtractionWay>> &resulting_ways,
|
||||
std::vector<std::pair<const osmium::Relation &, ExtractionRelation>> &resulting_relations,
|
||||
std::vector<InputConditionalTurnRestriction> &resulting_restrictions)
|
||||
{
|
||||
ExtractionNode result_node;
|
||||
ExtractionWay result_way;
|
||||
ExtractionRelation result_relation;
|
||||
auto &local_context = this->GetSol2Context();
|
||||
|
||||
for (auto entity = buffer.cbegin(), end = buffer.cend(); entity != end; ++entity)
|
||||
@@ -738,8 +747,7 @@ void Sol2ScriptingEnvironment::ProcessElements(
|
||||
if (local_context.has_node_function &&
|
||||
(!node.tags().empty() || local_context.properties.call_tagless_node_function))
|
||||
{
|
||||
const auto &id = ExtractionRelation::OsmIDTyped(node.id(), osmium::item_type::node);
|
||||
local_context.ProcessNode(node, result_node, relations.Get(id));
|
||||
local_context.ProcessNode(node, result_node, relations);
|
||||
}
|
||||
resulting_nodes.push_back({node, std::move(result_node)});
|
||||
}
|
||||
@@ -750,8 +758,7 @@ void Sol2ScriptingEnvironment::ProcessElements(
|
||||
result_way.clear();
|
||||
if (local_context.has_way_function)
|
||||
{
|
||||
const auto &id = ExtractionRelation::OsmIDTyped(way.id(), osmium::item_type::way);
|
||||
local_context.ProcessWay(way, result_way, relations.Get(id));
|
||||
local_context.ProcessWay(way, result_way, relations);
|
||||
}
|
||||
resulting_ways.push_back({way, std::move(result_way)});
|
||||
}
|
||||
@@ -763,16 +770,6 @@ void Sol2ScriptingEnvironment::ProcessElements(
|
||||
{
|
||||
resulting_restrictions.push_back(*result_res);
|
||||
}
|
||||
|
||||
if (local_context.api_version > 2)
|
||||
{
|
||||
result_relation.clear();
|
||||
if (local_context.has_relation_function)
|
||||
{
|
||||
local_context.ProcessRelation(relation, result_relation);
|
||||
}
|
||||
resulting_relations.push_back({relation, std::move(result_relation)});
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -901,6 +898,18 @@ std::vector<std::string> Sol2ScriptingEnvironment::GetRestrictions()
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> Sol2ScriptingEnvironment::GetRelations()
|
||||
{
|
||||
auto &context = GetSol2Context();
|
||||
switch (context.api_version)
|
||||
{
|
||||
case 3:
|
||||
return Sol2ScriptingEnvironment::GetStringListFromTable("relation_types");
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
void Sol2ScriptingEnvironment::ProcessTurn(ExtractionTurn &turn)
|
||||
{
|
||||
auto &context = GetSol2Context();
|
||||
@@ -992,7 +1001,7 @@ void Sol2ScriptingEnvironment::ProcessSegment(ExtractionSegment &segment)
|
||||
|
||||
void LuaScriptingContext::ProcessNode(const osmium::Node &node,
|
||||
ExtractionNode &result,
|
||||
const ExtractionRelationContainer::RelationList &relations)
|
||||
const ExtractionRelationContainer &relations)
|
||||
{
|
||||
BOOST_ASSERT(state.lua_state() != nullptr);
|
||||
|
||||
@@ -1013,7 +1022,7 @@ void LuaScriptingContext::ProcessNode(const osmium::Node &node,
|
||||
|
||||
void LuaScriptingContext::ProcessWay(const osmium::Way &way,
|
||||
ExtractionWay &result,
|
||||
const ExtractionRelationContainer::RelationList &relations)
|
||||
const ExtractionRelationContainer &relations)
|
||||
{
|
||||
BOOST_ASSERT(state.lua_state() != nullptr);
|
||||
|
||||
@@ -1033,14 +1042,5 @@ void LuaScriptingContext::ProcessWay(const osmium::Way &way,
|
||||
}
|
||||
}
|
||||
|
||||
void LuaScriptingContext::ProcessRelation(const osmium::Relation &relation,
|
||||
ExtractionRelation &result)
|
||||
{
|
||||
BOOST_ASSERT(state.lua_state() != nullptr);
|
||||
BOOST_ASSERT(api_version > 2);
|
||||
|
||||
relation_function(profile_table, relation, result);
|
||||
}
|
||||
|
||||
} // namespace extractor
|
||||
} // namespace osrm
|
||||
|
||||
Reference in New Issue
Block a user