Merge pull request #441 from ibikecph/lua_bike_oneways_and_names

update bike profile - oneways and way names
This commit is contained in:
Project OSRM 2012-09-27 00:59:36 -07:00
commit bb09cac7f4
2 changed files with 109 additions and 158 deletions

View File

@ -25,8 +25,8 @@ Feature: Street names in instructions
| bc | track | | | bc | track | |
When I route I should get When I route I should get
| from | to | route | | from | to | route |
| a | c | cycleway,trac | | a | c | cycleway,track |
Scenario: Don't create instructions for every node of unnamed ways Scenario: Don't create instructions for every node of unnamed ways
Given the node map Given the node map

View File

@ -3,7 +3,7 @@
-- Begin of globals -- Begin of globals
bollards_whitelist = { [""] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["no"] = true, ["sally_port"] = true, ["gate"] = true} bollards_whitelist = { [""] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["no"] = true, ["sally_port"] = true, ["gate"] = true}
access_tag_whitelist = { ["yes"] = true, ["vehicle"] = true, ["permissive"] = true, ["designated"] = true } access_tag_whitelist = { ["yes"] = true, ["vehicle"] = true, ["permissive"] = true, ["designated"] = true }
access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestery"] = true } access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestery"] = true }
access_tag_restricted = { ["destination"] = true, ["delivery"] = true } access_tag_restricted = { ["destination"] = true, ["delivery"] = true }
access_tags = { "bicycle", "vehicle" } access_tags = { "bicycle", "vehicle" }
@ -11,24 +11,24 @@ service_tag_restricted = { ["parking_aisle"] = true }
ignore_in_grid = { ["ferry"] = true } ignore_in_grid = { ["ferry"] = true }
speed_profile = { speed_profile = {
["cycleway"] = 18, ["cycleway"] = 18,
["primary"] = 17, ["primary"] = 17,
["primary_link"] = 17, ["primary_link"] = 17,
["secondary"] = 18, ["secondary"] = 18,
["secondary_link"] = 18, ["secondary_link"] = 18,
["tertiary"] = 18, ["tertiary"] = 18,
["residential"] = 18, ["residential"] = 18,
["unclassified"] = 16, ["unclassified"] = 16,
["living_street"] = 16, ["living_street"] = 16,
["road"] = 16, ["road"] = 16,
["service"] = 16, ["service"] = 16,
["track"] = 13, ["track"] = 13,
["path"] = 13, ["path"] = 13,
["footway"] = 5, ["footway"] = 5,
["pedestrian"] = 5, ["pedestrian"] = 5,
["pier"] = 5, ["pier"] = 5,
["steps"] = 1, ["steps"] = 1,
["default"] = 18 ["default"] = 18
} }
@ -43,151 +43,102 @@ u_turn_penalty = 20
-- End of globals -- End of globals
function node_function (node) function node_function (node)
local barrier = node.tags:Find ("barrier") local barrier = node.tags:Find ("barrier")
local access = node.tags:Find ("access") local access = node.tags:Find ("access")
local traffic_signal = node.tags:Find("highway") local traffic_signal = node.tags:Find("highway")
--flag node if it carries a traffic light --flag node if it carries a traffic light
if traffic_signal == "traffic_signals" then if traffic_signal == "traffic_signals" then
node.traffic_light = true; node.traffic_light = true;
end end
if obey_bollards then if obey_bollards then
--flag node as unpassable if it black listed as unpassable --flag node as unpassable if it black listed as unpassable
if access_tag_blacklist[barrier] then if access_tag_blacklist[barrier] then
node.bollard = true; node.bollard = true;
end end
--reverse the previous flag if there is an access tag specifying entrance --reverse the previous flag if there is an access tag specifying entrance
if node.bollard and not bollards_whitelist[barrier] and not access_tag_whitelist[barrier] then if node.bollard and not bollards_whitelist[barrier] and not access_tag_whitelist[barrier] then
node.bollard = false; node.bollard = false;
end end
end end
return 1 return 1
end end
function way_function (way, numberOfNodesInWay) function way_function (way, numberOfNodesInWay)
-- A way must have two nodes or more
-- A way must have two nodes or more if(numberOfNodesInWay < 2) then
if(numberOfNodesInWay < 2) then
return 0;
end
-- 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")
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 cycleway = way.tags:Find("cycleway")
local duration = way.tags:Find("duration")
local service = way.tags:Find("service")
local area = way.tags:Find("area")
local access = way.tags:Find("access")
-- Second parse the way according to these properties
if ignore_areas and ("yes" == area) then
return 0
end
-- Check if we are allowed to access the way
if access_tag_blacklist[access] ~=nil and access_tag_blacklist[access] then
return 0; return 0;
end end
-- Check if our vehicle types are forbidden -- First, get the properties of each way that we come across
for i,v in ipairs(access_tags) do local highway = way.tags:Find("highway")
local mode_value = way.tags:Find(v) local name = way.tags:Find("name")
if nil ~= mode_value and "no" == mode_value then local ref = way.tags:Find("ref")
return 0; local junction = way.tags:Find("junction")
end local route = way.tags:Find("route")
end 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")
local duration = way.tags:Find("duration")
local service = way.tags:Find("service")
local area = way.tags:Find("area")
local access = way.tags:Find("access")
-- Set the name that will be used for instructions -- Set the name that will be used for instructions
if "" ~= ref then if "" ~= ref then
way.name = ref way.name = ref
elseif "" ~= name then elseif "" ~= name then
way.name = name way.name = name
else
way.name = highway -- if no name exists, use way type
end end
if "roundabout" == junction then -- Set the avg speed on the way if it is accessible by road class
way.roundabout = true; if (speed_profile[highway] ~= nil and way.speed == -1 ) then
if (0 < maxspeed and not take_minimum_of_speeds) or (maxspeed == 0) then
maxspeed = math.huge
end
way.speed = math.min(speed_profile[highway], maxspeed)
end end
-- Handling ferries and piers -- Set the avg speed on ways that are marked accessible
if access_tag_whitelist[access] and way.speed == -1 then
if (0 < maxspeed and not take_minimum_of_speeds) or maxspeed == 0 then
maxspeed = math.huge
end
way.speed = math.min(speed_profile["default"], maxspeed)
end
if (speed_profile[route] ~= nil and speed_profile[route] > 0) or -- Set direction according to tags on way
(speed_profile[man_made] ~= nil and speed_profile[man_made] > 0) if obey_oneway then
then if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then
if durationIsValid(duration) then way.direction = Way.oneway
way.speed = parseDuration / math.max(1, numberOfSegments-1); elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then
way.is_duration_set = true; way.direction = Way.bidirectional
end elseif onewayClass == "-1" then
way.direction = Way.bidirectional; way.direction = Way.opposite
if speed_profile[route] ~= nil then elseif oneway == "no" or oneway == "0" or oneway == "false" then
highway = route; way.direction = Way.bidirectional
elseif speed_profile[man_made] ~= nil then elseif cycleway == "opposite" or cycleway == "opposite_track" or cycleway == "opposite_lane" then
highway = man_made; way.direction = Way.bidirectional
end elseif oneway == "-1" then
if not way.is_duration_set then way.direction = Way.opposite
way.speed = speed_profile[highway] elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then
end way.direction = Way.oneway
else
way.direction = Way.bidirectional
end
else
way.direction = Way.bidirectional
end
end way.type = 1
return 1
-- Set the avg speed on the way if it is accessible by road class
if (speed_profile[highway] ~= nil and way.speed == -1 ) then
if (0 < maxspeed and not take_minimum_of_speeds) or (maxspeed == 0) then
maxspeed = math.huge
end
way.speed = math.min(speed_profile[highway], maxspeed)
end
-- Set the avg speed on ways that are marked accessible
if access_tag_whitelist[access] and way.speed == -1 then
if (0 < maxspeed and not take_minimum_of_speeds) or maxspeed == 0 then
maxspeed = math.huge
end
way.speed = math.min(speed_profile["default"], maxspeed)
end
-- Set access restriction flag if access is allowed under certain restrictions only
if access ~= "" and access_tag_restricted[access] then
way.is_access_restricted = true
end
-- Set access restriction flag if service is allowed under certain restrictions only
if service ~= "" and service_tag_restricted[service] then
way.is_access_restricted = true
end
-- Set direction according to tags on way
if obey_oneway then
if oneway == "no" or oneway == "0" or oneway == "false" then
way.direction = Way.bidirectional
elseif oneway == "-1" then
way.direction = Way.opposite
elseif oneway == "yes" or oneway == "1" or oneway == "true" or junction == "roundabout" or highway == "motorway_link" or highway == "motorway" then
way.direction = Way.oneway
else
way.direction = Way.bidirectional
end
else
way.direction = Way.bidirectional
end
-- Override general direction settings of there is a specific one for our mode of travel
if ignore_in_grid[highway] ~= nil and ignore_in_grid[highway] then
way.ignore_in_grid = true
end
way.type = 1
return 1
end end