2012-09-19 12:35:45 -04:00
|
|
|
-- Begin of globals
|
2012-10-03 13:04:56 -04:00
|
|
|
barrier_whitelist = { [""] = true, ["bollard"] = true, ["entrance"] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["no"] = true, ["sally_port"] = true, ["gate"] = true}
|
2012-10-04 02:36:14 -04:00
|
|
|
access_tag_whitelist = { ["yes"] = true, ["permissive"] = true, ["designated"] = true }
|
|
|
|
access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestery"] = true }
|
2012-09-19 12:35:45 -04:00
|
|
|
access_tag_restricted = { ["destination"] = true, ["delivery"] = true }
|
2012-10-04 02:36:14 -04:00
|
|
|
access_tags_hierachy = { "bicycle", "vehicle", "access" }
|
2012-10-05 06:06:42 -04:00
|
|
|
cycleway_tags = {["track"]=true,["lane"]=true,["opposite"]=true,["opposite_lane"]=true,["opposite_track"]=true,["share_busway"]=true,["sharrow"]=true,["shared"]=true }
|
2012-09-19 12:35:45 -04:00
|
|
|
service_tag_restricted = { ["parking_aisle"] = true }
|
|
|
|
|
2012-10-11 10:50:17 -04:00
|
|
|
default_speed = 16
|
|
|
|
|
|
|
|
main_speeds = {
|
2012-09-27 02:46:36 -04:00
|
|
|
["cycleway"] = 18,
|
|
|
|
["primary"] = 17,
|
|
|
|
["primary_link"] = 17,
|
|
|
|
["secondary"] = 18,
|
|
|
|
["secondary_link"] = 18,
|
|
|
|
["tertiary"] = 18,
|
2012-09-30 08:40:59 -04:00
|
|
|
["tertiary_link"] = 18,
|
2012-09-27 02:46:36 -04:00
|
|
|
["residential"] = 18,
|
|
|
|
["unclassified"] = 16,
|
|
|
|
["living_street"] = 16,
|
|
|
|
["road"] = 16,
|
|
|
|
["service"] = 16,
|
|
|
|
["track"] = 13,
|
|
|
|
["path"] = 13,
|
2012-10-11 10:50:17 -04:00
|
|
|
["footway"] = 12,
|
|
|
|
["pedestrian"] = 12,
|
|
|
|
["pier"] = 12,
|
|
|
|
["steps"] = 2
|
|
|
|
}
|
|
|
|
|
|
|
|
pedestrian_speeds = {
|
2012-09-27 02:46:36 -04:00
|
|
|
["footway"] = 5,
|
|
|
|
["pedestrian"] = 5,
|
|
|
|
["pier"] = 5,
|
2012-10-11 10:50:17 -04:00
|
|
|
["steps"] = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
railway_speeds = {
|
|
|
|
["train"] = 10,
|
|
|
|
["railway"] = 10,
|
|
|
|
["subway"] = 10,
|
|
|
|
["light_rail"] = 10,
|
|
|
|
["monorail"] = 10,
|
|
|
|
["tram"] = 10
|
|
|
|
}
|
|
|
|
|
|
|
|
route_speeds = {
|
|
|
|
["ferry"] = 5
|
2012-09-19 12:35:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
take_minimum_of_speeds = true
|
|
|
|
obey_oneway = true
|
|
|
|
obey_bollards = false
|
|
|
|
use_restrictions = true
|
|
|
|
ignore_areas = true -- future feature
|
|
|
|
traffic_signal_penalty = 2
|
|
|
|
u_turn_penalty = 20
|
|
|
|
|
|
|
|
-- End of globals
|
|
|
|
|
2012-10-04 02:36:14 -04:00
|
|
|
--find first tag in access hierachy which is set
|
|
|
|
function find_access_tag(source)
|
|
|
|
for i,v in ipairs(access_tags_hierachy) do
|
|
|
|
local tag = source.tags:Find(v)
|
|
|
|
if tag ~= '' then --and tag ~= "" then
|
|
|
|
return tag
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2012-09-19 12:35:45 -04:00
|
|
|
function node_function (node)
|
2012-09-27 02:46:36 -04:00
|
|
|
local barrier = node.tags:Find ("barrier")
|
2012-10-04 02:36:14 -04:00
|
|
|
local access = find_access_tag(node)
|
2012-09-27 02:46:36 -04:00
|
|
|
local traffic_signal = node.tags:Find("highway")
|
|
|
|
|
2012-10-03 13:04:56 -04:00
|
|
|
-- flag node if it carries a traffic light
|
2012-09-27 02:46:36 -04:00
|
|
|
if traffic_signal == "traffic_signals" then
|
2012-10-03 13:04:56 -04:00
|
|
|
node.traffic_light = true
|
2012-09-27 02:46:36 -04:00
|
|
|
end
|
|
|
|
|
2012-10-03 13:04:56 -04:00
|
|
|
-- parse access and barrier tags
|
2012-10-04 02:36:14 -04:00
|
|
|
if access and access ~= "" then
|
2012-10-03 13:04:56 -04:00
|
|
|
if access_tag_blacklist[access] then
|
|
|
|
node.bollard = true
|
|
|
|
else
|
|
|
|
node.bollard = false
|
2012-09-27 02:46:36 -04:00
|
|
|
end
|
2012-10-04 02:36:14 -04:00
|
|
|
elseif barrier and barrier ~= "" then
|
2012-10-03 13:04:56 -04:00
|
|
|
if barrier_whitelist[barrier] then
|
|
|
|
node.bollard = false
|
|
|
|
else
|
|
|
|
node.bollard = true
|
2012-09-27 02:46:36 -04:00
|
|
|
end
|
|
|
|
end
|
2012-10-03 13:04:56 -04:00
|
|
|
|
2012-09-27 02:46:36 -04:00
|
|
|
return 1
|
2012-09-19 12:35:45 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
function way_function (way, numberOfNodesInWay)
|
2012-09-27 02:46:36 -04:00
|
|
|
-- A way must have two nodes or more
|
|
|
|
if(numberOfNodesInWay < 2) then
|
|
|
|
return 0;
|
2012-09-19 12:35:45 -04:00
|
|
|
end
|
2012-09-27 02:46:36 -04:00
|
|
|
|
|
|
|
-- First, get the properties of each way that we come across
|
|
|
|
local highway = way.tags:Find("highway")
|
|
|
|
local name = way.tags:Find("name")
|
|
|
|
local ref = way.tags:Find("ref")
|
|
|
|
local junction = way.tags:Find("junction")
|
|
|
|
local route = way.tags:Find("route")
|
2012-10-10 12:25:15 -04:00
|
|
|
local railway = way.tags:Find("railway")
|
2012-09-27 02:46:36 -04:00
|
|
|
local maxspeed = parseMaxspeed(way.tags:Find ( "maxspeed") )
|
|
|
|
local man_made = way.tags:Find("man_made")
|
|
|
|
local barrier = way.tags:Find("barrier")
|
|
|
|
local oneway = way.tags:Find("oneway")
|
|
|
|
local onewayClass = way.tags:Find("oneway:bicycle")
|
|
|
|
local cycleway = way.tags:Find("cycleway")
|
2012-10-05 06:06:42 -04:00
|
|
|
local cycleway_left = way.tags:Find("cycleway:left")
|
|
|
|
local cycleway_right = way.tags:Find("cycleway:right")
|
2012-09-27 02:46:36 -04:00
|
|
|
local duration = way.tags:Find("duration")
|
|
|
|
local service = way.tags:Find("service")
|
|
|
|
local area = way.tags:Find("area")
|
2012-10-04 02:36:14 -04:00
|
|
|
local access = find_access_tag(way)
|
2012-09-27 02:46:36 -04:00
|
|
|
|
2012-10-05 09:39:23 -04:00
|
|
|
-- only route on things with highway tag set (not buildings, boundaries, etc)
|
2012-10-10 12:25:15 -04:00
|
|
|
if (not highway or highway == '') and (not route or route == '') and (not railway or railway=='') then
|
2012-10-05 09:39:23 -04:00
|
|
|
return 0
|
|
|
|
end
|
2012-09-19 12:35:45 -04:00
|
|
|
|
2012-10-05 09:39:23 -04:00
|
|
|
-- access
|
2012-10-04 02:36:14 -04:00
|
|
|
if access_tag_blacklist[access] then
|
2012-10-03 13:04:56 -04:00
|
|
|
return 0
|
|
|
|
end
|
|
|
|
|
2012-10-05 09:39:23 -04:00
|
|
|
-- name
|
2012-09-19 12:35:45 -04:00
|
|
|
if "" ~= ref then
|
2012-09-27 02:46:36 -04:00
|
|
|
way.name = ref
|
2012-09-19 12:35:45 -04:00
|
|
|
elseif "" ~= name then
|
2012-09-27 02:46:36 -04:00
|
|
|
way.name = name
|
|
|
|
else
|
|
|
|
way.name = highway -- if no name exists, use way type
|
2012-09-19 12:35:45 -04:00
|
|
|
end
|
|
|
|
|
2012-10-11 10:50:17 -04:00
|
|
|
if route_speeds[route] then
|
|
|
|
-- ferries
|
|
|
|
way.direction = Way.bidirectional
|
|
|
|
way.ignore_in_grid = true
|
2012-10-05 09:39:23 -04:00
|
|
|
if durationIsValid(duration) then
|
2012-10-11 10:50:17 -04:00
|
|
|
way.speed = math.max( parseDuration(duration) / math.max(1, numberOfNodesInWay-1) )
|
|
|
|
way.is_duration_set = true
|
|
|
|
else
|
|
|
|
way.speed = route_speeds[route]
|
2012-10-05 09:39:23 -04:00
|
|
|
end
|
2012-10-11 10:50:17 -04:00
|
|
|
elseif railway and railway_speeds[railway] then
|
2012-10-10 12:25:15 -04:00
|
|
|
-- trains and subways
|
|
|
|
if access and access_tag_whitelist[access] then
|
2012-10-11 10:50:17 -04:00
|
|
|
way.speed = railway_speeds[railway]
|
2012-10-10 12:25:15 -04:00
|
|
|
way.direction = Way.bidirectional
|
|
|
|
end
|
2012-10-11 10:50:17 -04:00
|
|
|
elseif pedestrian_speeds[highway] and main_speeds[highway] then
|
|
|
|
-- pedestrian areas
|
|
|
|
if access_tag_whitelist[access] then
|
|
|
|
way.speed = main_speeds[highway] -- biking
|
|
|
|
else
|
|
|
|
way.speed = pedestrian_speeds[highway] -- pushing bikes
|
|
|
|
end
|
2012-10-10 12:25:15 -04:00
|
|
|
else
|
2012-10-11 10:50:17 -04:00
|
|
|
-- regular ways
|
|
|
|
if main_speeds[highway] then
|
|
|
|
way.speed = main_speeds[highway]
|
|
|
|
elseif main_speeds[man_made] then
|
|
|
|
way.speed = main_speeds[man_made]
|
|
|
|
elseif access_tag_whitelist[access] then
|
|
|
|
way.speed = default_speed
|
2012-09-27 02:46:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-10-05 09:39:23 -04:00
|
|
|
-- maxspeed
|
|
|
|
if take_minimum_of_speeds then
|
|
|
|
if maxspeed and maxspeed>0 then
|
|
|
|
way.speed = math.min(way.speed, maxspeed)
|
|
|
|
end
|
|
|
|
end
|
2012-10-05 06:06:42 -04:00
|
|
|
|
2012-10-05 09:39:23 -04:00
|
|
|
-- direction
|
2012-10-05 06:06:42 -04:00
|
|
|
way.direction = Way.bidirectional
|
|
|
|
local impliedOneway = false
|
|
|
|
if junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then
|
|
|
|
way.direction = Way.oneway
|
|
|
|
impliedOneway = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then
|
|
|
|
way.direction = Way.oneway
|
|
|
|
elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then
|
|
|
|
way.direction = Way.bidirectional
|
|
|
|
elseif onewayClass == "-1" then
|
|
|
|
way.direction = Way.opposite
|
|
|
|
elseif oneway == "no" or oneway == "0" or oneway == "false" then
|
|
|
|
way.direction = Way.bidirectional
|
|
|
|
elseif cycleway and string.find(cycleway, "opposite") == 1 then
|
|
|
|
if impliedOneway then
|
2012-09-27 02:46:36 -04:00
|
|
|
way.direction = Way.opposite
|
2012-10-05 06:06:42 -04:00
|
|
|
else
|
2012-09-27 02:46:36 -04:00
|
|
|
way.direction = Way.bidirectional
|
2012-10-05 06:06:42 -04:00
|
|
|
end
|
|
|
|
elseif cycleway_left and cycleway_tags[cycleway_left] and cycleway_right and cycleway_tags[cycleway_right] then
|
|
|
|
way.direction = Way.bidirectional
|
|
|
|
elseif cycleway_left and cycleway_tags[cycleway_left] then
|
|
|
|
if impliedOneway then
|
2012-09-27 02:46:36 -04:00
|
|
|
way.direction = Way.opposite
|
2012-10-05 06:06:42 -04:00
|
|
|
else
|
|
|
|
way.direction = Way.bidirectional
|
|
|
|
end
|
|
|
|
elseif cycleway_right and cycleway_tags[cycleway_right] then
|
|
|
|
if impliedOneway then
|
2012-09-27 02:46:36 -04:00
|
|
|
way.direction = Way.oneway
|
|
|
|
else
|
|
|
|
way.direction = Way.bidirectional
|
|
|
|
end
|
2012-10-05 06:06:42 -04:00
|
|
|
elseif oneway == "-1" then
|
|
|
|
way.direction = Way.opposite
|
|
|
|
elseif oneway == "yes" or oneway == "1" or oneway == "true" then
|
|
|
|
way.direction = Way.oneway
|
2012-09-27 02:46:36 -04:00
|
|
|
end
|
|
|
|
|
2012-10-05 09:39:23 -04:00
|
|
|
-- cycleways
|
2012-10-05 06:06:42 -04:00
|
|
|
if cycleway and cycleway_tags[cycleway] then
|
2012-10-11 10:50:17 -04:00
|
|
|
way.speed = main_speeds["cycleway"]
|
2012-10-05 06:06:42 -04:00
|
|
|
elseif cycleway_left and cycleway_tags[cycleway_left] then
|
2012-10-11 10:50:17 -04:00
|
|
|
way.speed = main_speeds["cycleway"]
|
2012-10-05 06:06:42 -04:00
|
|
|
elseif cycleway_right and cycleway_tags[cycleway_right] then
|
2012-10-11 10:50:17 -04:00
|
|
|
way.speed = main_speeds["cycleway"]
|
2012-10-05 06:06:42 -04:00
|
|
|
end
|
|
|
|
|
2012-09-27 02:46:36 -04:00
|
|
|
way.type = 1
|
|
|
|
return 1
|
2012-09-19 12:35:45 -04:00
|
|
|
end
|