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
|
["default"] = 10
|
||||||
}
|
}
|
||||||
|
|
||||||
take_minimum_of_speeds = false
|
local take_minimum_of_speeds = false
|
||||||
obey_oneway = true
|
local obey_oneway = true
|
||||||
obey_bollards = true
|
local obey_bollards = true
|
||||||
use_turn_restrictions = true
|
local use_turn_restrictions = true
|
||||||
ignore_areas = true -- future feature
|
local ignore_areas = true -- future feature
|
||||||
traffic_signal_penalty = 2
|
local traffic_signal_penalty = 2
|
||||||
u_turn_penalty = 20
|
local u_turn_penalty = 20
|
||||||
|
|
||||||
|
local abs = math.abs
|
||||||
|
local min = math.min
|
||||||
|
local max = math.max
|
||||||
|
|
||||||
-- End of globals
|
-- End of globals
|
||||||
function find_access_tag(source,access_tags_hierachy)
|
local function find_access_tag(source,access_tags_hierachy)
|
||||||
for i,v in ipairs(access_tags_hierachy) do
|
for i,v in ipairs(access_tags_hierachy) do
|
||||||
local tag = source.tags:Find(v)
|
local has_tag = source.tags:Holds(v)
|
||||||
if tag ~= '' then
|
if has_tag then
|
||||||
return tag
|
return source.tags:Find(v)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return nil
|
end
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_exceptions(vector)
|
function get_exceptions(vector)
|
||||||
@ -58,36 +62,36 @@ function get_exceptions(vector)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function parse_maxspeed(source)
|
local function parse_maxspeed(source)
|
||||||
if source == nil then
|
if not source then
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
local n = tonumber(source:match("%d*"))
|
local n = tonumber(source:match("%d*"))
|
||||||
if n == nil then
|
if not n then
|
||||||
n = 0
|
n = 0
|
||||||
end
|
end
|
||||||
if string.match(source, "mph") or string.match(source, "mp/h") then
|
if string.match(source, "mph") or string.match(source, "mp/h") then
|
||||||
n = (n*1609)/1000;
|
n = (n*1609)/1000;
|
||||||
end
|
end
|
||||||
return math.abs(n)
|
return abs(n*0.66)
|
||||||
end
|
end
|
||||||
|
|
||||||
function node_function (node)
|
function node_function (node)
|
||||||
local barrier = node.tags:Find("barrier")
|
|
||||||
local access = find_access_tag(node, access_tags_hierachy)
|
local access = find_access_tag(node, access_tags_hierachy)
|
||||||
local traffic_signal = node.tags:Find("highway")
|
|
||||||
|
|
||||||
--flag node if it carries a traffic light
|
--flag node if it carries a traffic light
|
||||||
|
if node.tags:Holds("highway") then
|
||||||
if traffic_signal == "traffic_signals" then
|
if node.tags:Find("highway") == "traffic_signals" then
|
||||||
node.traffic_light = true;
|
node.traffic_light = true;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- parse access and barrier tags
|
-- parse access and barrier tags
|
||||||
if access and access ~= "" then
|
if access and access ~= "" then
|
||||||
if access_tag_blacklist[access] then
|
if access_tag_blacklist[access] then
|
||||||
node.bollard = true
|
node.bollard = true
|
||||||
end
|
end
|
||||||
elseif barrier and barrier ~= "" then
|
elseif node.tags:Holds("barrier") then
|
||||||
|
local barrier = node.tags:Find("barrier")
|
||||||
if barrier_whitelist[barrier] then
|
if barrier_whitelist[barrier] then
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
@ -96,12 +100,14 @@ function node_function (node)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function way_function (way)
|
function way_function (way)
|
||||||
-- we dont route over areas
|
-- we dont route over areas
|
||||||
local area = way.tags:Find("area")
|
local is_area = way.tags:Holds("area")
|
||||||
if ignore_areas and ("yes" == area) then
|
if ignore_areas and is_area then
|
||||||
return
|
local area = way.tags:Find("area")
|
||||||
|
if "yes" == area then
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check if oneway tag is unsupported
|
-- check if oneway tag is unsupported
|
||||||
@ -110,14 +116,20 @@ function way_function (way)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local impassable = way.tags:Find("impassable")
|
local is_impassable = way.tags:Holds("impassable")
|
||||||
if "yes" == impassable then
|
if is_impassable then
|
||||||
return
|
local impassable = way.tags:Find("impassable")
|
||||||
|
if "yes" == impassable then
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local status = way.tags:Find("status")
|
local is_status = way.tags:Holds("status")
|
||||||
if "impassable" == status then
|
if is_status then
|
||||||
return
|
local status = way.tags:Find("status")
|
||||||
|
if "impassable" == status then
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if we are allowed to access the way
|
-- 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
|
-- Second, parse the way according to these properties
|
||||||
local highway = way.tags:Find("highway")
|
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 name = way.tags:Find("name")
|
||||||
local ref = way.tags:Find("ref")
|
local ref = way.tags:Find("ref")
|
||||||
local junction = way.tags:Find("junction")
|
local junction = way.tags:Find("junction")
|
||||||
local route = way.tags:Find("route")
|
-- local barrier = way.tags:Find("barrier")
|
||||||
local maxspeed = parse_maxspeed(way.tags:Find ( "maxspeed") )
|
-- local cycleway = way.tags:Find("cycleway")
|
||||||
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 service = way.tags:Find("service")
|
local service = way.tags:Find("service")
|
||||||
|
|
||||||
-- 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
|
-- else
|
||||||
-- way.name = highway -- if no name exists, use way type
|
-- 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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set the avg speed on the way if it is accessible by road class
|
if "roundabout" == junction then
|
||||||
if (speed_profile[highway] ~= nil and way.speed == -1 ) then
|
way.roundabout = true;
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set access restriction flag if access is allowed under certain restrictions only
|
-- Set access restriction flag if access is allowed under certain restrictions only
|
||||||
@ -214,18 +234,20 @@ function way_function (way)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Override speed settings if explicit forward/backward maxspeeds are given
|
-- 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
|
if Way.bidirectional == way.direction then
|
||||||
way.backward_speed = way.speed
|
way.backward_speed = way.speed
|
||||||
end
|
end
|
||||||
way.speed = maxspeed_forward
|
way.speed = maxspeed_forward
|
||||||
end
|
end
|
||||||
if maxspeed_backward ~= nil and maxspeed_backward > 0 then
|
if maxspeed_backward > 0 then
|
||||||
way.backward_speed = maxspeed_backward
|
way.backward_speed = maxspeed_backward
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Override general direction settings of there is a specific one for our mode of travel
|
-- 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
|
way.ignore_in_grid = true
|
||||||
end
|
end
|
||||||
way.type = 1
|
way.type = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user