Support some cases for supperrelations in car.lua
This commit is contained in:
parent
832cdbf566
commit
fc9a89ea8b
@ -406,7 +406,7 @@ function process_way(profile, way, result, relations)
|
|||||||
local rel_id_list = relations:get_relations(way)
|
local rel_id_list = relations:get_relations(way)
|
||||||
for i, rel_id in ipairs(rel_id_list) do
|
for i, rel_id in ipairs(rel_id_list) do
|
||||||
local rel = relations:relation(rel_id)
|
local rel = relations:relation(rel_id)
|
||||||
parsed_rel_list[i] = Relations.parse_route_relation(rel, way)
|
parsed_rel_list[i] = Relations.parse_route_relation(rel, way, relations)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- now process relations data
|
-- now process relations data
|
||||||
|
@ -7,6 +7,10 @@ Utils = require('lib/utils')
|
|||||||
|
|
||||||
Relations = {}
|
Relations = {}
|
||||||
|
|
||||||
|
function is_direction(role)
|
||||||
|
return (role == 'north' or role == 'south' or role == 'west' or role == 'east')
|
||||||
|
end
|
||||||
|
|
||||||
-- match ref values to relations data
|
-- match ref values to relations data
|
||||||
function Relations.match_to_ref(relations, ref)
|
function Relations.match_to_ref(relations, ref)
|
||||||
|
|
||||||
@ -91,37 +95,71 @@ function Relations.match_to_ref(relations, ref)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
function Relations.parse_route_relation(relation, obj)
|
function get_direction_from_superrel(rel, relations)
|
||||||
local t = relation:get_value_by_key("type")
|
local result = nil
|
||||||
local role = relation:get_role(obj)
|
local result_id = nil
|
||||||
|
local rel_id_list = relations:get_relations(rel)
|
||||||
|
|
||||||
|
function set_result(direction, current_rel)
|
||||||
|
if (result ~= nil) and (direction ~= nil) then
|
||||||
|
print('WARNING: relation ' .. rel:id() .. ' is a part of more then one supperrelations ' .. result_id .. ' and ' .. current_rel:id())
|
||||||
|
else
|
||||||
|
result = direction
|
||||||
|
result_id = current_rel:id()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for i, rel_id in ipairs(rel_id_list) do
|
||||||
|
local parent_rel = relations:relation(rel_id)
|
||||||
|
if parent_rel:get_value_by_key('type') == 'route' then
|
||||||
|
local role = parent_rel:get_role(rel)
|
||||||
|
|
||||||
|
if is_direction(role) then
|
||||||
|
set_result(role, parent_rel)
|
||||||
|
else
|
||||||
|
local dir = parent_rel:get_value_by_key('direction')
|
||||||
|
if is_direction(dir) then
|
||||||
|
set_result(dir, parent_rel)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- TODO: support forward/backward
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
function Relations.parse_route_relation(rel, way, relations)
|
||||||
|
local t = rel:get_value_by_key("type")
|
||||||
|
local role = rel:get_role(way)
|
||||||
local result = {}
|
local result = {}
|
||||||
|
|
||||||
function add_extra_data(m)
|
function add_extra_data(m)
|
||||||
local name = relation:get_value_by_key("name")
|
local name = rel:get_value_by_key("name")
|
||||||
if name then
|
if name then
|
||||||
result['route_name'] = name
|
result['route_name'] = name
|
||||||
end
|
end
|
||||||
|
|
||||||
local ref = relation:get_value_by_key("ref")
|
local ref = rel:get_value_by_key("ref")
|
||||||
if ref then
|
if ref then
|
||||||
result['route_ref'] = ref
|
result['route_ref'] = ref
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if t == 'route' then
|
if t == 'route' then
|
||||||
local route = relation:get_value_by_key("route")
|
local route = rel:get_value_by_key("route")
|
||||||
if route == 'road' then
|
if route == 'road' then
|
||||||
-- process case, where directions set as role
|
-- process case, where directions set as role
|
||||||
if role == 'north' or role == 'south' or role == 'west' or role == 'east' then
|
if is_direction(role) then
|
||||||
result['route_direction'] = role
|
result['route_direction'] = role
|
||||||
add_extra_data(m)
|
add_extra_data(m)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local direction = relation:get_value_by_key('direction')
|
local direction = rel:get_value_by_key('direction')
|
||||||
if direction then
|
if direction then
|
||||||
direction = string.lower(direction)
|
direction = string.lower(direction)
|
||||||
if direction == 'north' or direction == 'south' or direction == 'west' or direction == 'east' then
|
if is_direction(direction) then
|
||||||
if role == 'forward' then
|
if role == 'forward' then
|
||||||
result['route_direction'] = direction
|
result['route_direction'] = direction
|
||||||
add_extra_data(m)
|
add_extra_data(m)
|
||||||
@ -130,6 +168,20 @@ function Relations.parse_route_relation(relation, obj)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- process superrelations
|
||||||
|
local super_dir = get_direction_from_superrel(rel, relations)
|
||||||
|
|
||||||
|
-- check if there are data error
|
||||||
|
local dir = result['route_direction']
|
||||||
|
if (dir ~= nil) and (super_dir ~= nil) and (dir ~= super_dir) then
|
||||||
|
print('ERROR: conflicting relation directions found for way ' .. way:id() ..
|
||||||
|
' relation direction is ' .. dir .. ' superrelation direction is ' .. super_dir)
|
||||||
|
end
|
||||||
|
|
||||||
|
if (dir == nil) and (super_dir ~= nil) then
|
||||||
|
result['route_direction'] = super_dir
|
||||||
|
end
|
||||||
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -417,24 +417,23 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
|
|||||||
sol::property([](const ExtractionWay &way) { return way.is_left_hand_driving; },
|
sol::property([](const ExtractionWay &way) { return way.is_left_hand_driving; },
|
||||||
[](ExtractionWay &way, bool flag) { way.is_left_hand_driving = flag; }));
|
[](ExtractionWay &way, bool flag) { way.is_left_hand_driving = flag; }));
|
||||||
|
|
||||||
auto getTypedRefBySol = [](const sol::object & obj) -> ExtractionRelation::OsmIDTyped
|
auto getTypedRefBySol = [](const sol::object &obj) -> ExtractionRelation::OsmIDTyped {
|
||||||
{
|
|
||||||
if (obj.is<osmium::Way>())
|
if (obj.is<osmium::Way>())
|
||||||
{
|
{
|
||||||
osmium::Way * way = obj.as<osmium::Way*>();
|
osmium::Way *way = obj.as<osmium::Way *>();
|
||||||
return { way->id(), osmium::item_type::way };
|
return {way->id(), osmium::item_type::way};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.is<osmium::Relation>())
|
if (obj.is<ExtractionRelation>())
|
||||||
{
|
{
|
||||||
osmium::Relation * rel = obj.as<osmium::Relation*>();
|
ExtractionRelation *rel = obj.as<ExtractionRelation *>();
|
||||||
return { rel->id(), osmium::item_type::relation };
|
return rel->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.is<osmium::Node>())
|
if (obj.is<osmium::Node>())
|
||||||
{
|
{
|
||||||
osmium::Node * node = obj.as<osmium::Node*>();
|
osmium::Node *node = obj.as<osmium::Node *>();
|
||||||
return { node->id(), osmium::item_type::node };
|
return {node->id(), osmium::item_type::node};
|
||||||
}
|
}
|
||||||
|
|
||||||
return ExtractionRelation::OsmIDTyped(0, osmium::item_type::undefined);
|
return ExtractionRelation::OsmIDTyped(0, osmium::item_type::undefined);
|
||||||
@ -449,27 +448,25 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
|
|||||||
|
|
||||||
context.state.new_usertype<ExtractionRelation>(
|
context.state.new_usertype<ExtractionRelation>(
|
||||||
"ExtractionRelation",
|
"ExtractionRelation",
|
||||||
|
"id",
|
||||||
|
[](ExtractionRelation &rel) { return rel.id.GetID(); },
|
||||||
"get_value_by_key",
|
"get_value_by_key",
|
||||||
[](ExtractionRelation &rel, const char * key) -> const char * { return rel.GetAttr(key); },
|
[](ExtractionRelation &rel, const char *key) -> const char * { return rel.GetAttr(key); },
|
||||||
"get_role",
|
"get_role",
|
||||||
[&getTypedRefBySol](ExtractionRelation &rel, const sol::object & obj) -> const char *
|
[&getTypedRefBySol](ExtractionRelation &rel, const sol::object &obj) -> const char * {
|
||||||
{
|
|
||||||
return rel.GetRole(getTypedRefBySol(obj));
|
return rel.GetRole(getTypedRefBySol(obj));
|
||||||
});
|
});
|
||||||
|
|
||||||
context.state.new_usertype<ExtractionRelationContainer>(
|
context.state.new_usertype<ExtractionRelationContainer>(
|
||||||
"ExtractionRelationContainer",
|
"ExtractionRelationContainer",
|
||||||
"get_relations",
|
"get_relations",
|
||||||
[&getTypedRefBySol](ExtractionRelationContainer &cont, const sol::object & obj)
|
[&getTypedRefBySol](ExtractionRelationContainer &cont, const sol::object &obj)
|
||||||
-> const ExtractionRelationContainer::RelationIDList &
|
-> const ExtractionRelationContainer::RelationIDList & {
|
||||||
{
|
return cont.GetRelations(getTypedRefBySol(obj));
|
||||||
return cont.GetRelations(getTypedRefBySol(obj));
|
},
|
||||||
},
|
|
||||||
"relation",
|
"relation",
|
||||||
[](ExtractionRelationContainer &cont, const ExtractionRelation::OsmIDTyped & rel_id) -> const ExtractionRelation &
|
[](ExtractionRelationContainer &cont, const ExtractionRelation::OsmIDTyped &rel_id)
|
||||||
{
|
-> const ExtractionRelation & { return cont.GetRelationData(rel_id); });
|
||||||
return cont.GetRelationData(rel_id);
|
|
||||||
});
|
|
||||||
|
|
||||||
context.state.new_usertype<ExtractionSegment>("ExtractionSegment",
|
context.state.new_usertype<ExtractionSegment>("ExtractionSegment",
|
||||||
"source",
|
"source",
|
||||||
@ -717,7 +714,7 @@ LuaScriptingContext &Sol2ScriptingEnvironment::GetSol2Context()
|
|||||||
auto &ref = script_contexts.local(initialized);
|
auto &ref = script_contexts.local(initialized);
|
||||||
if (!initialized)
|
if (!initialized)
|
||||||
{
|
{
|
||||||
ref = std::make_unique<LuaScriptingContext>(location_dependent_data);
|
ref = std::make_unique<LuaScriptingContext>();
|
||||||
InitContext(*ref);
|
InitContext(*ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1037,7 +1034,6 @@ void LuaScriptingContext::ProcessWay(const osmium::Way &way,
|
|||||||
case 1:
|
case 1:
|
||||||
case 0:
|
case 0:
|
||||||
way_function(way, result);
|
way_function(way, result);
|
||||||
result.is_left_hand_driving = properties.left_hand_driving;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user