scale maxspeeds to 2/3 to be more realistic and in sync with the default profile
This commit is contained in:
parent
aedf9d3a91
commit
9e64ccdbf2
194
profiles/car.lua
194
profiles/car.lua
@ -32,23 +32,27 @@ speed_profile = {
|
||||
["default"] = 10
|
||||
}
|
||||
|
||||
take_minimum_of_speeds = false
|
||||
obey_oneway = true
|
||||
obey_bollards = true
|
||||
use_turn_restrictions = true
|
||||
ignore_areas = true -- future feature
|
||||
traffic_signal_penalty = 2
|
||||
u_turn_penalty = 20
|
||||
local take_minimum_of_speeds = false
|
||||
local obey_oneway = true
|
||||
local obey_bollards = true
|
||||
local use_turn_restrictions = true
|
||||
local ignore_areas = true -- future feature
|
||||
local traffic_signal_penalty = 2
|
||||
local u_turn_penalty = 20
|
||||
|
||||
local abs = math.abs
|
||||
local min = math.min
|
||||
local max = math.max
|
||||
|
||||
-- End of globals
|
||||
function find_access_tag(source,access_tags_hierachy)
|
||||
for i,v in ipairs(access_tags_hierachy) do
|
||||
local tag = source.tags:Find(v)
|
||||
if tag ~= '' then
|
||||
return tag
|
||||
end
|
||||
local function find_access_tag(source,access_tags_hierachy)
|
||||
for i,v in ipairs(access_tags_hierachy) do
|
||||
local has_tag = source.tags:Holds(v)
|
||||
if has_tag then
|
||||
return source.tags:Find(v)
|
||||
end
|
||||
return nil
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function get_exceptions(vector)
|
||||
@ -58,36 +62,36 @@ function get_exceptions(vector)
|
||||
end
|
||||
|
||||
local function parse_maxspeed(source)
|
||||
if source == nil then
|
||||
if not source then
|
||||
return 0
|
||||
end
|
||||
local n = tonumber(source:match("%d*"))
|
||||
if n == nil then
|
||||
if not n 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)
|
||||
return abs(n*0.66)
|
||||
end
|
||||
|
||||
function node_function (node)
|
||||
local barrier = node.tags:Find("barrier")
|
||||
local access = find_access_tag(node, access_tags_hierachy)
|
||||
local traffic_signal = node.tags:Find("highway")
|
||||
|
||||
--flag node if it carries a traffic light
|
||||
|
||||
if traffic_signal == "traffic_signals" then
|
||||
node.traffic_light = true;
|
||||
if node.tags:Holds("highway") then
|
||||
if node.tags:Find("highway") == "traffic_signals" then
|
||||
node.traffic_light = true;
|
||||
end
|
||||
end
|
||||
|
||||
-- parse access and barrier tags
|
||||
if access and access ~= "" then
|
||||
if access and access ~= "" then
|
||||
if access_tag_blacklist[access] then
|
||||
node.bollard = true
|
||||
end
|
||||
elseif barrier and barrier ~= "" then
|
||||
elseif node.tags:Holds("barrier") then
|
||||
local barrier = node.tags:Find("barrier")
|
||||
if barrier_whitelist[barrier] then
|
||||
return
|
||||
else
|
||||
@ -96,12 +100,14 @@ function node_function (node)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function way_function (way)
|
||||
-- we dont route over areas
|
||||
local area = way.tags:Find("area")
|
||||
if ignore_areas and ("yes" == area) then
|
||||
return
|
||||
local is_area = way.tags:Holds("area")
|
||||
if ignore_areas and is_area then
|
||||
local area = way.tags:Find("area")
|
||||
if "yes" == area then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- check if oneway tag is unsupported
|
||||
@ -110,14 +116,20 @@ function way_function (way)
|
||||
return
|
||||
end
|
||||
|
||||
local impassable = way.tags:Find("impassable")
|
||||
if "yes" == impassable then
|
||||
return
|
||||
local is_impassable = way.tags:Holds("impassable")
|
||||
if is_impassable then
|
||||
local impassable = way.tags:Find("impassable")
|
||||
if "yes" == impassable then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local status = way.tags:Find("status")
|
||||
if "impassable" == status then
|
||||
return
|
||||
local is_status = way.tags:Holds("status")
|
||||
if is_status then
|
||||
local status = way.tags:Find("status")
|
||||
if "impassable" == status then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Check if we are allowed to access the way
|
||||
@ -128,63 +140,71 @@ function way_function (way)
|
||||
|
||||
-- Second, parse the way according to these properties
|
||||
local highway = way.tags:Find("highway")
|
||||
local route = way.tags:Find("route")
|
||||
|
||||
-- Handling ferries and piers
|
||||
local route_speed = speed_profile[route]
|
||||
if(route_speed and route_speed > 0) then
|
||||
highway = route;
|
||||
local duration = way.tags:Find("duration")
|
||||
if durationIsValid(duration) then
|
||||
way.duration = max( parseDuration(duration), 1 );
|
||||
end
|
||||
way.direction = Way.bidirectional
|
||||
way.speed = route_speed
|
||||
end
|
||||
|
||||
-- leave early of this way is not accessible
|
||||
if "" == highway then
|
||||
return
|
||||
end
|
||||
|
||||
if way.speed == -1 then
|
||||
local highway_speed = speed_profile[highway]
|
||||
local max_speed = parse_maxspeed( way.tags:Find("maxspeed") )
|
||||
-- Set the avg speed on the way if it is accessible by road class
|
||||
if highway_speed then
|
||||
if max_speed > highway_speed then
|
||||
way.speed = max_speed
|
||||
-- max_speed = math.huge
|
||||
else
|
||||
way.speed = highway_speed
|
||||
end
|
||||
else
|
||||
-- Set the avg speed on ways that are marked accessible
|
||||
if access_tag_whitelist[access] then
|
||||
way.speed = speed_profile["default"]
|
||||
end
|
||||
end
|
||||
if 0 == max_speed then
|
||||
max_speed = math.huge
|
||||
end
|
||||
way.speed = min(way.speed, max_speed)
|
||||
end
|
||||
|
||||
if -1 == way.speed then
|
||||
return
|
||||
end
|
||||
|
||||
-- parse the remaining tags
|
||||
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 = parse_maxspeed(way.tags:Find ( "maxspeed") )
|
||||
local maxspeed_forward = parse_maxspeed(way.tags:Find( "maxspeed:forward"))
|
||||
local maxspeed_backward = parse_maxspeed(way.tags:Find( "maxspeed:backward"))
|
||||
local barrier = way.tags:Find("barrier")
|
||||
local cycleway = way.tags:Find("cycleway")
|
||||
local duration = way.tags:Find("duration")
|
||||
-- local barrier = way.tags:Find("barrier")
|
||||
-- local cycleway = way.tags:Find("cycleway")
|
||||
local service = way.tags:Find("service")
|
||||
|
||||
-- Set the name that will be used for instructions
|
||||
if "" ~= ref then
|
||||
way.name = ref
|
||||
elseif "" ~= name then
|
||||
way.name = name
|
||||
-- else
|
||||
-- way.name = highway -- if no name exists, use way type
|
||||
end
|
||||
|
||||
if "roundabout" == junction then
|
||||
way.roundabout = true;
|
||||
end
|
||||
|
||||
-- Handling ferries and piers
|
||||
if (speed_profile[route] ~= nil and speed_profile[route] > 0) then
|
||||
if durationIsValid(duration) then
|
||||
way.duration = math.max( parseDuration(duration), 1 );
|
||||
end
|
||||
way.direction = Way.bidirectional
|
||||
if speed_profile[route] ~= nil then
|
||||
highway = route;
|
||||
end
|
||||
if tonumber(way.duration) < 0 then
|
||||
way.speed = speed_profile[highway]
|
||||
end
|
||||
if "" ~= ref then
|
||||
way.name = ref
|
||||
elseif "" ~= name then
|
||||
way.name = name
|
||||
-- else
|
||||
-- way.name = highway -- if no name exists, use way type
|
||||
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
|
||||
|
||||
-- Set the avg speed on ways that are marked accessible
|
||||
if "" ~= highway and access_tag_whitelist[access] and way.speed == -1 then
|
||||
if 0 == maxspeed then
|
||||
maxspeed = math.huge
|
||||
end
|
||||
way.speed = math.min(speed_profile["default"], maxspeed)
|
||||
if "roundabout" == junction then
|
||||
way.roundabout = true;
|
||||
end
|
||||
|
||||
-- Set access restriction flag if access is allowed under certain restrictions only
|
||||
@ -214,18 +234,20 @@ function way_function (way)
|
||||
end
|
||||
|
||||
-- Override speed settings if explicit forward/backward maxspeeds are given
|
||||
if way.speed > 0 and maxspeed_forward ~= nil and maxspeed_forward > 0 then
|
||||
local maxspeed_forward = parse_maxspeed(way.tags:Find( "maxspeed:forward"))
|
||||
local maxspeed_backward = parse_maxspeed(way.tags:Find( "maxspeed:backward"))
|
||||
if maxspeed_forward > 0 then
|
||||
if Way.bidirectional == way.direction then
|
||||
way.backward_speed = way.speed
|
||||
end
|
||||
way.speed = maxspeed_forward
|
||||
end
|
||||
if maxspeed_backward ~= nil and maxspeed_backward > 0 then
|
||||
if maxspeed_backward > 0 then
|
||||
way.backward_speed = maxspeed_backward
|
||||
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
|
||||
if ignore_in_grid[highway] then
|
||||
way.ignore_in_grid = true
|
||||
end
|
||||
way.type = 1
|
||||
|
Loading…
Reference in New Issue
Block a user