Fixes issue #579
This commit is contained in:
parent
bb1064ac42
commit
572b176401
@ -31,4 +31,4 @@ Feature: Car - Max speed restrictions
|
|||||||
When I route I should get
|
When I route I should get
|
||||||
| from | to | route | time |
|
| from | to | route | time |
|
||||||
| a | b | ab | 144s ~10% |
|
| a | b | ab | 144s ~10% |
|
||||||
| b | c | bc | 144s ~10% |
|
| b | c | bc | 63s ~10% |
|
||||||
|
297
profiles/car.lua
297
profiles/car.lua
@ -12,24 +12,24 @@ ignore_in_grid = { ["ferry"] = true }
|
|||||||
restriction_exception_tags = { "motorcar", "motor_vehicle", "vehicle" }
|
restriction_exception_tags = { "motorcar", "motor_vehicle", "vehicle" }
|
||||||
|
|
||||||
speed_profile = {
|
speed_profile = {
|
||||||
["motorway"] = 90,
|
["motorway"] = 90,
|
||||||
["motorway_link"] = 75,
|
["motorway_link"] = 75,
|
||||||
["trunk"] = 85,
|
["trunk"] = 85,
|
||||||
["trunk_link"] = 70,
|
["trunk_link"] = 70,
|
||||||
["primary"] = 65,
|
["primary"] = 65,
|
||||||
["primary_link"] = 60,
|
["primary_link"] = 60,
|
||||||
["secondary"] = 55,
|
["secondary"] = 55,
|
||||||
["secondary_link"] = 50,
|
["secondary_link"] = 50,
|
||||||
["tertiary"] = 40,
|
["tertiary"] = 40,
|
||||||
["tertiary_link"] = 30,
|
["tertiary_link"] = 30,
|
||||||
["unclassified"] = 25,
|
["unclassified"] = 25,
|
||||||
["residential"] = 25,
|
["residential"] = 25,
|
||||||
["living_street"] = 10,
|
["living_street"] = 10,
|
||||||
["service"] = 15,
|
["service"] = 15,
|
||||||
-- ["track"] = 5,
|
-- ["track"] = 5,
|
||||||
["ferry"] = 5,
|
["ferry"] = 5,
|
||||||
["shuttle_train"] = 10,
|
["shuttle_train"] = 10,
|
||||||
["default"] = 50
|
["default"] = 50
|
||||||
}
|
}
|
||||||
|
|
||||||
take_minimum_of_speeds = false
|
take_minimum_of_speeds = false
|
||||||
@ -43,171 +43,158 @@ u_turn_penalty = 20
|
|||||||
-- End of globals
|
-- End of globals
|
||||||
|
|
||||||
function get_exceptions(vector)
|
function get_exceptions(vector)
|
||||||
for i,v in ipairs(restriction_exception_tags) do
|
for i,v in ipairs(restriction_exception_tags) do
|
||||||
vector:Add(v)
|
vector:Add(v)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local function parse_maxspeed(source)
|
|
||||||
if source == nil then
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
local n = tonumber(source:match("%d*"))
|
|
||||||
if n == nil then
|
|
||||||
n = 0
|
|
||||||
end
|
|
||||||
if string.match(source, "mph") or string.match(source, "mp/h") then
|
|
||||||
n = (n*1609)/1000;
|
|
||||||
end
|
|
||||||
return math.abs(n)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function node_function (node)
|
function node_function (node)
|
||||||
local barrier = node.tags:Find ("barrier")
|
local barrier = node.tags:Find ("barrier")
|
||||||
local access = Access.find_access_tag(node, access_tags_hierachy)
|
local access = Access.find_access_tag(node, access_tags_hierachy)
|
||||||
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
|
||||||
|
|
||||||
|
-- parse access and barrier tags
|
||||||
|
if access and access ~= "" then
|
||||||
|
if access_tag_blacklist[access] then
|
||||||
|
node.bollard = true
|
||||||
|
end
|
||||||
|
elseif barrier and barrier ~= "" then
|
||||||
|
if barrier_whitelist[barrier] then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
node.bollard = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
return 1
|
||||||
-- parse access and barrier tags
|
|
||||||
if access and access ~= "" then
|
|
||||||
if access_tag_blacklist[access] then
|
|
||||||
node.bollard = true
|
|
||||||
end
|
|
||||||
elseif barrier and barrier ~= "" then
|
|
||||||
if barrier_whitelist[barrier] then
|
|
||||||
return
|
|
||||||
else
|
|
||||||
node.bollard = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
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;
|
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 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 = Access.find_access_tag(way, access_tags_hierachy)
|
||||||
|
|
||||||
|
-- Second, parse the way according to these properties
|
||||||
|
|
||||||
|
if ignore_areas and ("yes" == area) then
|
||||||
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- First, get the properties of each way that we come across
|
-- Check if we are allowed to access the way
|
||||||
local highway = way.tags:Find("highway")
|
if access_tag_blacklist[access] then
|
||||||
local name = way.tags:Find("name")
|
return 0
|
||||||
local ref = way.tags:Find("ref")
|
end
|
||||||
local junction = way.tags:Find("junction")
|
|
||||||
local route = way.tags:Find("route")
|
|
||||||
local maxspeed = parse_maxspeed(way.tags:Find ( "maxspeed") )
|
|
||||||
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 = Access.find_access_tag(way, access_tags_hierachy)
|
|
||||||
|
|
||||||
-- Second, parse the way according to these properties
|
-- Set the name that will be used for instructions
|
||||||
|
if "" ~= ref then
|
||||||
if ignore_areas and ("yes" == area) then
|
way.name = ref
|
||||||
return 0
|
elseif "" ~= name then
|
||||||
end
|
way.name = name
|
||||||
|
|
||||||
-- Check if we are allowed to access the way
|
|
||||||
if access_tag_blacklist[access] then
|
|
||||||
return 0
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Set the name that will be used for instructions
|
|
||||||
if "" ~= ref then
|
|
||||||
way.name = ref
|
|
||||||
elseif "" ~= name then
|
|
||||||
way.name = name
|
|
||||||
-- else
|
-- else
|
||||||
-- way.name = highway -- if no name exists, use way type
|
-- way.name = highway -- if no name exists, use way type
|
||||||
end
|
end
|
||||||
|
|
||||||
if "roundabout" == junction then
|
if "roundabout" == junction then
|
||||||
way.roundabout = true;
|
way.roundabout = true;
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Handling ferries and piers
|
-- Handling ferries and piers
|
||||||
if (speed_profile[route] ~= nil and speed_profile[route] > 0) then
|
if (speed_profile[route] ~= nil and speed_profile[route] > 0) then
|
||||||
if durationIsValid(duration) then
|
if durationIsValid(duration) then
|
||||||
way.duration = math.max( parseDuration(duration), 1 );
|
way.duration = math.max( parseDuration(duration), 1 );
|
||||||
end
|
end
|
||||||
way.direction = Way.bidirectional
|
way.direction = Way.bidirectional
|
||||||
if speed_profile[route] ~= nil then
|
if speed_profile[route] ~= nil then
|
||||||
highway = route;
|
highway = route;
|
||||||
end
|
end
|
||||||
if tonumber(way.duration) < 0 then
|
if tonumber(way.duration) < 0 then
|
||||||
way.speed = speed_profile[highway]
|
way.speed = speed_profile[highway]
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 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 maxspeed > speed_profile[highway] then
|
||||||
|
way.speed = maxspeed
|
||||||
|
else
|
||||||
|
if 0 == maxspeed then
|
||||||
|
maxspeed = math.huge
|
||||||
|
end
|
||||||
|
way.speed = math.min(speed_profile[highway], maxspeed)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Set the avg speed on the way if it is accessible by road class
|
-- Set the avg speed on ways that are marked accessible
|
||||||
if (speed_profile[highway] ~= nil and way.speed == -1 ) then
|
if "" ~= highway and access_tag_whitelist[access] and way.speed == -1 then
|
||||||
if 0 == maxspeed then
|
if 0 == maxspeed then
|
||||||
maxspeed = math.huge
|
maxspeed = math.huge
|
||||||
end
|
end
|
||||||
way.speed = math.min(speed_profile[highway], maxspeed)
|
way.speed = math.min(speed_profile["default"], maxspeed)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set the avg speed on ways that are marked accessible
|
if durationIsValid(duration) then
|
||||||
if "" ~= highway and access_tag_whitelist[access] and way.speed == -1 then
|
way.duration = math.max( parseDuration(duration), 1 );
|
||||||
if 0 == maxspeed then
|
end
|
||||||
maxspeed = math.huge
|
|
||||||
end
|
|
||||||
way.speed = math.min(speed_profile["default"], maxspeed)
|
|
||||||
end
|
|
||||||
|
|
||||||
if durationIsValid(duration) then
|
-- Set access restriction flag if access is allowed under certain restrictions only
|
||||||
way.duration = math.max( parseDuration(duration), 1 );
|
if access ~= "" and access_tag_restricted[access] then
|
||||||
end
|
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 access restriction flag if access is allowed under certain restrictions only
|
-- Set direction according to tags on way
|
||||||
if access ~= "" and access_tag_restricted[access] then
|
if obey_oneway then
|
||||||
way.is_access_restricted = true
|
if oneway == "no" or oneway == "0" or oneway == "false" then
|
||||||
end
|
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
|
||||||
|
|
||||||
-- Set access restriction flag if service is allowed under certain restrictions only
|
-- Override general direction settings of there is a specific one for our mode of travel
|
||||||
if service ~= "" and service_tag_restricted[service] then
|
if ignore_in_grid[highway] ~= nil and ignore_in_grid[highway] then
|
||||||
way.is_access_restricted = true
|
way.ignore_in_grid = true
|
||||||
end
|
end
|
||||||
|
way.type = 1
|
||||||
-- Set direction according to tags on way
|
return 1
|
||||||
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
|
||||||
|
|
||||||
-- These are wrappers to parse vectors of nodes and ways and thus to speed up any tracing JIT
|
-- These are wrappers to parse vectors of nodes and ways and thus to speed up any tracing JIT
|
||||||
|
|
||||||
function node_vector_function(vector)
|
function node_vector_function(vector)
|
||||||
for v in vector.nodes do
|
for v in vector.nodes do
|
||||||
node_function(v)
|
node_function(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user