port car profile
This commit is contained in:
parent
f9e780ed67
commit
ebcdcb5f00
179
profiles/car.lua
179
profiles/car.lua
@ -142,15 +142,14 @@ local speed_reduction = 0.8
|
|||||||
local mode_normal = 1
|
local mode_normal = 1
|
||||||
local mode_ferry = 2
|
local mode_ferry = 2
|
||||||
|
|
||||||
|
local 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 has_tag = source.tags:Holds(v)
|
local access_tag = source:get_value_by_key(v, "")
|
||||||
if has_tag then
|
if "" ~= access_tag then
|
||||||
return source.tags:Find(v)
|
return access_tag
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_exceptions(vector)
|
function get_exceptions(vector)
|
||||||
@ -191,70 +190,60 @@ end
|
|||||||
-- return penalty
|
-- return penalty
|
||||||
-- end
|
-- end
|
||||||
|
|
||||||
function node_function (node)
|
function node_function (node, result)
|
||||||
local access = find_access_tag(node, access_tags_hierachy)
|
|
||||||
|
|
||||||
--flag node if it carries a traffic light
|
|
||||||
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
|
-- parse access and barrier tags
|
||||||
if access and access ~= "" then
|
local access = find_access_tag(node, access_tags_hierachy)
|
||||||
|
if access ~= "" then
|
||||||
if access_tag_blacklist[access] then
|
if access_tag_blacklist[access] then
|
||||||
node.bollard = true
|
result.barrier = true
|
||||||
end
|
end
|
||||||
elseif node.tags:Holds("barrier") then
|
else
|
||||||
local barrier = node.tags:Find("barrier")
|
local barrier = node:get_value_by_key("barrier")
|
||||||
|
if barrier and "" ~= barrier then
|
||||||
if barrier_whitelist[barrier] then
|
if barrier_whitelist[barrier] then
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
node.bollard = true
|
result.barrier = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- check if node is a traffic light
|
||||||
|
local tag = node:get_value_by_key("highway")
|
||||||
|
if tag and "traffic_signals" == tag then
|
||||||
|
result.traffic_lights = true;
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function way_function (way)
|
function way_function (way, result)
|
||||||
|
local highway = way:get_value_by_key("highway")
|
||||||
|
local route = way:get_value_by_key("route")
|
||||||
|
|
||||||
local is_highway = way.tags:Holds("highway")
|
if not ((highway and highway ~= "") or (route and route ~= "")) then
|
||||||
local is_route = way.tags:Holds("route")
|
|
||||||
|
|
||||||
if not (is_highway or is_route) then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- we dont route over areas
|
-- we dont route over areas
|
||||||
local is_area = way.tags:Holds("area")
|
local area = way:get_value_by_key("area")
|
||||||
if ignore_areas and is_area then
|
if ignore_areas and area and "yes" == area then
|
||||||
local area = way.tags:Find("area")
|
|
||||||
if "yes" == area then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- check if oneway tag is unsupported
|
-- check if oneway tag is unsupported
|
||||||
local oneway = way.tags:Find("oneway")
|
local oneway = way:get_value_by_key("oneway")
|
||||||
if "reversible" == oneway then
|
if oneway and "reversible" == oneway then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local is_impassable = way.tags:Holds("impassable")
|
local impassable = way:get_value_by_key("impassable")
|
||||||
if is_impassable then
|
if impassable and "yes" == impassable then
|
||||||
local impassable = way.tags:Find("impassable")
|
|
||||||
if "yes" == impassable then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
local is_status = way.tags:Holds("status")
|
local status = way:get_value_by_key("status")
|
||||||
if is_status then
|
if status and "impassable" == status then
|
||||||
local status = way.tags:Find("status")
|
|
||||||
if "impassable" == status then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- Check if we are allowed to access the way
|
-- Check if we are allowed to access the way
|
||||||
local access = find_access_tag(way, access_tags_hierachy)
|
local access = find_access_tag(way, access_tags_hierachy)
|
||||||
@ -262,22 +251,18 @@ function way_function (way)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Second, parse the way according to these properties
|
|
||||||
local highway = way.tags:Find("highway")
|
|
||||||
local route = way.tags:Find("route")
|
|
||||||
|
|
||||||
-- Handling ferries and piers
|
-- Handling ferries and piers
|
||||||
local route_speed = speed_profile[route]
|
local route_speed = speed_profile[route]
|
||||||
if(route_speed and route_speed > 0) then
|
if(route_speed and route_speed > 0) then
|
||||||
highway = route;
|
highway = route;
|
||||||
local duration = way.tags:Find("duration")
|
local duration = way:get_value_by_key("duration")
|
||||||
if durationIsValid(duration) then
|
if duration and durationIsValid(duration) then
|
||||||
way.duration = max( parseDuration(duration), 1 );
|
result.duration = max( parseDuration(duration), 1 );
|
||||||
end
|
end
|
||||||
way.forward_mode = mode_ferry
|
result.forward_mode = mode_ferry
|
||||||
way.backward_mode = mode_ferry
|
result.backward_mode = mode_ferry
|
||||||
way.forward_speed = route_speed
|
result.forward_speed = route_speed
|
||||||
way.backward_speed = route_speed
|
result.backward_speed = route_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
-- leave early of this way is not accessible
|
-- leave early of this way is not accessible
|
||||||
@ -285,34 +270,34 @@ function way_function (way)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if way.forward_speed == -1 then
|
if result.forward_speed == -1 then
|
||||||
local highway_speed = speed_profile[highway]
|
local highway_speed = speed_profile[highway]
|
||||||
local max_speed = parse_maxspeed( way.tags:Find("maxspeed") )
|
local max_speed = parse_maxspeed( way:get_value_by_key("maxspeed") )
|
||||||
-- Set the avg speed on the way if it is accessible by road class
|
-- Set the avg speed on the way if it is accessible by road class
|
||||||
if highway_speed then
|
if highway_speed then
|
||||||
if max_speed > highway_speed then
|
if max_speed and max_speed > highway_speed then
|
||||||
way.forward_speed = max_speed
|
result.forward_speed = max_speed
|
||||||
way.backward_speed = max_speed
|
result.backward_speed = max_speed
|
||||||
-- max_speed = math.huge
|
-- max_speed = math.huge
|
||||||
else
|
else
|
||||||
way.forward_speed = highway_speed
|
result.forward_speed = highway_speed
|
||||||
way.backward_speed = highway_speed
|
result.backward_speed = highway_speed
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Set the avg speed on ways that are marked accessible
|
-- Set the avg speed on ways that are marked accessible
|
||||||
if access_tag_whitelist[access] then
|
if access_tag_whitelist[access] then
|
||||||
way.forward_speed = speed_profile["default"]
|
result.forward_speed = speed_profile["default"]
|
||||||
way.backward_speed = speed_profile["default"]
|
result.backward_speed = speed_profile["default"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if 0 == max_speed then
|
if 0 == max_speed then
|
||||||
max_speed = math.huge
|
max_speed = math.huge
|
||||||
end
|
end
|
||||||
way.forward_speed = min(way.forward_speed, max_speed)
|
result.forward_speed = min(result.forward_speed, max_speed)
|
||||||
way.backward_speed = min(way.backward_speed, max_speed)
|
result.backward_speed = min(result.backward_speed, max_speed)
|
||||||
end
|
end
|
||||||
|
|
||||||
if -1 == way.forward_speed and -1 == way.backward_speed then
|
if -1 == result.forward_speed and -1 == result.backward_speed then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -335,72 +320,74 @@ function way_function (way)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- parse the remaining tags
|
-- parse the remaining tags
|
||||||
local name = way.tags:Find("name")
|
local name = way:get_value_by_key("name")
|
||||||
local ref = way.tags:Find("ref")
|
local ref = way:get_value_by_key("ref")
|
||||||
local junction = way.tags:Find("junction")
|
local junction = way:get_value_by_key("junction")
|
||||||
-- local barrier = way.tags:Find("barrier")
|
-- local barrier = way:get_value_by_key("barrier", "")
|
||||||
-- local cycleway = way.tags:Find("cycleway")
|
-- local cycleway = way:get_value_by_key("cycleway", "")
|
||||||
local service = way.tags:Find("service")
|
local service = way:get_value_by_key("service")
|
||||||
|
|
||||||
-- Set the name that will be used for instructions
|
-- Set the name that will be used for instructions
|
||||||
if "" ~= ref then
|
if ref and "" ~= ref then
|
||||||
way.name = ref
|
result.name = ref
|
||||||
elseif "" ~= name then
|
elseif name and "" ~= name then
|
||||||
way.name = name
|
result.name = name
|
||||||
-- else
|
-- else
|
||||||
-- way.name = highway -- if no name exists, use way type
|
-- result.name = highway -- if no name exists, use way type
|
||||||
end
|
end
|
||||||
|
|
||||||
if "roundabout" == junction then
|
if junction and "roundabout" == junction then
|
||||||
way.roundabout = true;
|
result.roundabout = true;
|
||||||
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
|
||||||
if access ~= "" and access_tag_restricted[access] then
|
if access ~= "" and access_tag_restricted[access] then
|
||||||
way.is_access_restricted = true
|
result.is_access_restricted = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set access restriction flag if service is allowed under certain restrictions only
|
-- Set access restriction flag if service is allowed under certain restrictions only
|
||||||
if service ~= "" and service_tag_restricted[service] then
|
if service and service ~= "" and service_tag_restricted[service] then
|
||||||
way.is_access_restricted = true
|
result.is_access_restricted = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Set direction according to tags on way
|
-- Set direction according to tags on way
|
||||||
if obey_oneway then
|
if obey_oneway then
|
||||||
if oneway == "-1" then
|
if oneway == "-1" then
|
||||||
way.forward_mode = 0
|
result.forward_mode = 0
|
||||||
elseif oneway == "yes" or
|
elseif oneway == "yes" or
|
||||||
oneway == "1" or
|
oneway == "1" or
|
||||||
oneway == "true" or
|
oneway == "true" or
|
||||||
junction == "roundabout" or
|
junction == "roundabout" or
|
||||||
(highway == "motorway_link" and oneway ~="no") or
|
(highway == "motorway_link" and oneway ~="no") or
|
||||||
(highway == "motorway" and oneway ~= "no") then
|
(highway == "motorway" and oneway ~= "no") then
|
||||||
way.backward_mode = 0
|
result.backward_mode = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Override speed settings if explicit forward/backward maxspeeds are given
|
-- Override speed settings if explicit forward/backward maxspeeds are given
|
||||||
local maxspeed_forward = parse_maxspeed(way.tags:Find( "maxspeed:forward"))
|
local maxspeed_forward = parse_maxspeed(way:get_value_by_key( "maxspeed:forward"))
|
||||||
local maxspeed_backward = parse_maxspeed(way.tags:Find( "maxspeed:backward"))
|
local maxspeed_backward = parse_maxspeed(way:get_value_by_key( "maxspeed:backward"))
|
||||||
if maxspeed_forward > 0 then
|
if maxspeed_forward and maxspeed_forward > 0 then
|
||||||
if 0 ~= way.forward_mode and 0 ~= way.backward_mode then
|
if 0 ~= result.forward_mode and 0 ~= result.backward_mode then
|
||||||
way.backward_speed = way.forward_speed
|
result.backward_speed = result.forward_speed
|
||||||
end
|
end
|
||||||
way.forward_speed = maxspeed_forward
|
result.forward_speed = maxspeed_forward
|
||||||
end
|
end
|
||||||
if maxspeed_backward > 0 then
|
if maxspeed_backward and maxspeed_backward > 0 then
|
||||||
way.backward_speed = maxspeed_backward
|
result.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] then
|
if ignore_in_grid[highway] then
|
||||||
way.ignore_in_grid = true
|
result.ignore_in_grid = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- scale speeds to get better avg driving times
|
-- scale speeds to get better avg driving times
|
||||||
way.forward_speed = way.forward_speed * speed_reduction
|
if result.forward_speed > 0 then
|
||||||
if way.backward_speed > 0 then
|
result.forward_speed = result.forward_speed*speed_reduction
|
||||||
way.backward_speed = way.backward_speed*speed_reduction
|
end
|
||||||
|
if result.backward_speed > 0 then
|
||||||
|
result.backward_speed = result.backward_speed*speed_reduction
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user