-
Hi. I am currently investigating the new feature to evaluate relations. I want to extract bus and tram routes. I created a relation_scan_function and accept all "route" tags. Within the way_function I am iterating over the relations using way:NextRelation. Generally this works. However, the ways have at most one relation. But in case of bus or tram lines this is different because one way may be part of various routes. My question is whether this use-case is already supported. If it helps I can provide the Lua code. Dirk |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
Code would be helpful - yes please! |
Beta Was this translation helpful? Give feedback.
-
Here is the Lua code: -- nodes to be processed
node_keys = { "highway", "railway" }
-- node attributes to be copied
node_attributes = { "name", "bicycle", "foot", "access", "smoothness", "surface", "type", "bridge", "tunnel", "route", "network", "cycle_network", "roundtrip", "icn_ref", "lcn_ref", "rcn_ref", "ncn_ref" }
-- way attributes to be copied
way_attributes = { "name", "bicycle", "foot", "access", "smoothness", "surface", "type", "bridge", "tunnel" }
-- route attributes to be copied
route_attributes = { "name", "colour", "operator", "lcn", "lcn_ref", "icn", "icn_ref", "rcn", "rcn_ref", "ncn", "ncn_ref", "ref" }
function init_function()
end
function exit_function()
end
function TrySetAttribute(obj, name)
local value = obj:Find(name)
if value~="" then
obj:Attribute(name, value)
end
end
-- try to read attribute from relation and add it to the way object.
-- concatenates the strings if the way object already contains the attribute
function TrySetRelationAttribute(way, rel_name, way_name)
local value = way:FindInRelation(rel_name)
if value~="" then
local way_value = way:Find(way_name)
if way_value~="" then
way_value = way_value..";"..value
else
way_value = value
end
way:Attribute(way_name, way_value)
end
end
function FindTag(obj, tags)
for _,tag in pairs(tags) do
local value = obj:Find(tag)
if value~="" then
return tag, value
end
end
return nil, nil
end
function node_function(node)
-- check whether highway or railway tag exists
local obj_type, obj = FindTag(node, {"highway", "railway"})
if obj_type~=nil then
node:Layer("route", false)
node:Attribute("obj_type", obj_type)
node:Attribute("class", obj)
-- copy attributes
for _,attr in pairs(node_attributes) do
TrySetAttribute(node, attr)
end
end
end
function way_function(way)
-- check whether highway or railway tag exists
local obj_type, obj = FindTag(way, {"highway", "railway"})
if obj_type~=nil then
way:Layer("route", false)
way:Attribute(obj_type.."_class", obj)
-- copy attributes
for _,attr in pairs(way_attributes) do
TrySetAttribute(way, obj_type.."_"..attr)
end
-- iterate of relations in order to copy attributes
while true do
local rel = way:NextRelation()
if not rel then break end
-- read the type of route, such as 'bicycle'
local route = way:FindInRelation("route")
if route~="" then
way:Attribute(route.."_route", "yes")
-- copy attributes from relations to the way
for _,attr in pairs(route_attributes) do
TrySetRelationAttribute(way, attr, route.."_"..attr)
end
end
end
end
end
function relation_scan_function(relation)
if relation:Find("type")=="route" then
local ref = relation:Find("ref")
if ref~="" then
-- accept all routes with a ref number
relation:Accept()
end
end
end |
Beta Was this translation helpful? Give feedback.
Here is the Lua code: