osrm-backend/profiles/bicycle.lua

725 lines
23 KiB
Lua
Raw Normal View History

-- Bicycle profile
2017-02-04 17:05:00 -05:00
api_version = 4
2017-05-18 08:27:28 -04:00
Set = require('lib/set')
Sequence = require('lib/sequence')
Handlers = require("lib/way_handlers")
TrafficSignal = require("lib/traffic_signal")
2017-05-18 08:27:28 -04:00
find_access_tag = require("lib/access").find_access_tag
limit = require("lib/maxspeed").limit
Measure = require("lib/measure")
2017-05-18 08:27:28 -04:00
function setup()
local default_speed = 15
local walking_speed = 4
2017-05-18 08:27:28 -04:00
return {
properties = {
u_turn_penalty = 20,
traffic_light_penalty = 2,
--weight_name = 'cyclability',
weight_name = 'duration',
process_call_tagless_node = false,
max_speed_for_map_matching = 110/3.6, -- kmph -> m/s
use_turn_restrictions = false,
continue_straight_at_waypoint = false,
mode_change_penalty = 30,
2017-05-18 08:27:28 -04:00
},
default_mode = mode.cycling,
default_speed = default_speed,
walking_speed = walking_speed,
oneway_handling = true,
turn_penalty = 6,
turn_bias = 1.4,
use_public_transport = true,
-- Exclude narrow ways, in particular to route with cargo bike
width = nil, -- Cargo bike could 0.5 width, in meters
exclude_cargo_bike = false,
2017-05-18 08:27:28 -04:00
allowed_start_modes = Set {
mode.cycling,
mode.pushing_bike
},
barrier_blacklist = Set {
'yes',
'wall',
'fence'
2017-05-18 08:27:28 -04:00
},
access_tag_whitelist = Set {
2017-07-19 09:32:42 -04:00
'yes',
'permissive',
'designated'
2017-05-18 08:27:28 -04:00
},
access_tag_blacklist = Set {
2017-07-19 09:32:42 -04:00
'no',
'private',
'agricultural',
'forestry',
'delivery',
-- When a way is tagged with `use_sidepath` a parallel way suitable for
-- cyclists is mapped and must be used instead (by law). This tag is
-- used on ways that normally may be used by cyclists, but not when
-- a signposted parallel cycleway is available. For purposes of routing
-- cyclists, this value should be treated as 'no access for bicycles'.
'use_sidepath'
2017-05-18 08:27:28 -04:00
},
restricted_access_tag_list = Set { },
restricted_highway_whitelist = Set { },
-- tags disallow access to in combination with highway=service
service_access_tag_blacklist = Set { },
construction_whitelist = Set {
'no',
'widening',
'minor',
},
2017-05-18 08:27:28 -04:00
access_tags_hierarchy = Sequence {
2017-07-19 09:32:42 -04:00
'bicycle',
'vehicle',
'access'
2017-05-18 08:27:28 -04:00
},
restrictions = Set {
2017-07-19 09:32:42 -04:00
'bicycle'
2017-05-18 08:27:28 -04:00
},
cycleway_tags = Set {
2017-07-19 09:32:42 -04:00
'track',
'lane',
'share_busway',
'sharrow',
'shared',
2017-05-18 08:27:28 -04:00
'shared_lane'
},
opposite_cycleway_tags = Set {
'opposite',
'opposite_lane',
'opposite_track',
},
2017-05-18 08:27:28 -04:00
-- reduce the driving speed by 30% for unsafe roads
-- only used for cyclability metric
unsafe_highway_list = {
primary = 0.5,
secondary = 0.65,
2017-05-18 08:27:28 -04:00
tertiary = 0.8,
primary_link = 0.5,
secondary_link = 0.65,
2017-05-18 08:27:28 -04:00
tertiary_link = 0.8,
},
service_penalties = {
alley = 0.5,
},
bicycle_speeds = {
cycleway = default_speed,
primary = default_speed,
primary_link = default_speed,
secondary = default_speed,
secondary_link = default_speed,
tertiary = default_speed,
tertiary_link = default_speed,
residential = default_speed,
unclassified = default_speed,
living_street = default_speed,
road = default_speed,
service = default_speed,
track = 12,
2022-09-23 11:54:55 -04:00
path = 13
2017-05-18 08:27:28 -04:00
},
pedestrian_speeds = {
footway = walking_speed,
pedestrian = walking_speed,
steps = 2
},
railway_speeds = {
train = 10,
railway = 10,
subway = 10,
light_rail = 10,
monorail = 10,
tram = 10
},
platform_speeds = {
platform = walking_speed
},
amenity_speeds = {
parking = 10,
parking_entrance = 10
},
man_made_speeds = {
pier = walking_speed
},
route_speeds = {
ferry = 5
},
bridge_speeds = {
movable = 5
},
surface_speeds = {
asphalt = default_speed,
2022-09-23 11:54:55 -04:00
chipseal = default_speed,
concrete = default_speed,
concrete_lanes = default_speed,
wood = 10,
metal = 10,
2017-05-18 08:27:28 -04:00
["cobblestone:flattened"] = 10,
paving_stones = 10,
compacted = 10,
2022-09-23 11:54:55 -04:00
cobblestone = 7,
2017-05-18 08:27:28 -04:00
unpaved = 6,
2022-09-23 11:54:55 -04:00
fine_gravel = 10,
2017-05-18 08:27:28 -04:00
gravel = 6,
pebblestone = 6,
grass_paver = 6,
2022-09-23 11:54:55 -04:00
ground = 10,
dirt = 8,
2017-05-18 08:27:28 -04:00
earth = 6,
grass = 6,
mud = 3,
sand = 3,
woodchips = 3,
2022-09-23 11:54:55 -04:00
sett = 9
2017-05-18 08:27:28 -04:00
},
classes = Sequence {
'ferry', 'tunnel'
},
-- Which classes should be excludable
-- This increases memory usage so its disabled by default.
excludable = Sequence {
-- Set {'ferry'}
},
2017-05-18 08:27:28 -04:00
tracktype_speeds = {
},
smoothness_speeds = {
},
avoid = Set {
'impassable',
2023-08-20 05:17:30 -04:00
'construction',
'proposed'
2017-05-18 08:27:28 -04:00
}
}
end
2017-07-19 09:32:42 -04:00
function process_node(profile, node, result)
2015-05-15 08:45:50 -04:00
-- parse access and barrier tags
local highway = node:get_value_by_key("highway")
local is_crossing = highway and highway == "crossing"
2017-02-04 17:05:00 -05:00
local access = find_access_tag(node, profile.access_tags_hierarchy)
2015-05-15 11:01:21 -04:00
if access and access ~= "" then
-- access restrictions on crossing nodes are not relevant for
-- the traffic on the road
2017-02-04 17:05:00 -05:00
if profile.access_tag_blacklist[access] and not is_crossing then
2015-05-15 08:45:50 -04:00
result.barrier = true
end
else
local barrier = node:get_value_by_key("barrier")
if barrier and "" ~= barrier then
if profile.barrier_blacklist[barrier] then
2015-05-15 08:45:50 -04:00
result.barrier = true
end
end
end
2014-03-05 13:16:17 -05:00
if profile.exclude_cargo_bike then
local cargo_bike = node:get_value_by_key("cargo_bike")
if cargo_bike and cargo_bike == "no" then
result.barrier = true
end
end
-- width
if profile.width then
-- From barrier=cycle_barrier or other barriers
local maxwidth_physical = node:get_value_by_key("maxwidth:physical")
local maxwidth_physical_meter = maxwidth_physical and Measure.parse_value_meters(maxwidth_physical) or 99
local opening = node:get_value_by_key("opening")
local opening_meter = opening and Measure.parse_value_meters(opening) or 99
local width_meter = math.min(maxwidth_physical_meter, opening_meter)
if width_meter and width_meter < profile.width then
result.barrier = true
end
end
2015-05-15 08:45:50 -04:00
-- check if node is a traffic light
result.traffic_lights = TrafficSignal.get_value(node)
2014-03-05 13:16:17 -05:00
end
2017-05-18 08:27:28 -04:00
function handle_bicycle_tags(profile,way,result,data)
-- initial routability check, filters out buildings, boundaries, etc
2018-04-12 07:15:07 -04:00
data.route = way:get_value_by_key("route")
data.man_made = way:get_value_by_key("man_made")
data.railway = way:get_value_by_key("railway")
data.amenity = way:get_value_by_key("amenity")
data.public_transport = way:get_value_by_key("public_transport")
data.bridge = way:get_value_by_key("bridge")
2017-02-05 14:44:04 -05:00
if (not data.highway or data.highway == '') and
2018-04-12 07:15:07 -04:00
(not data.route or data.route == '') and
(not profile.use_public_transport or not data.railway or data.railway=='') and
(not data.amenity or data.amenity=='') and
(not data.man_made or data.man_made=='') and
(not data.public_transport or data.public_transport=='') and
(not data.bridge or data.bridge=='')
2014-03-27 16:19:26 -04:00
then
2017-05-18 08:27:28 -04:00
return false
2014-03-27 16:19:26 -04:00
end
-- access
2018-04-12 07:15:07 -04:00
data.access = find_access_tag(way, profile.access_tags_hierarchy)
if data.access and profile.access_tag_blacklist[data.access] then
2017-05-18 08:27:28 -04:00
return false
2014-03-27 16:19:26 -04:00
end
-- other tags
2018-04-12 07:15:07 -04:00
data.junction = way:get_value_by_key("junction")
data.maxspeed = Measure.get_max_speed(way:get_value_by_key ("maxspeed")) or 0
data.maxspeed_forward = Measure.get_max_speed(way:get_value_by_key("maxspeed:forward")) or 0
data.maxspeed_backward = Measure.get_max_speed(way:get_value_by_key("maxspeed:backward")) or 0
2018-04-12 07:15:07 -04:00
data.barrier = way:get_value_by_key("barrier")
data.oneway = way:get_value_by_key("oneway")
data.oneway_bicycle = way:get_value_by_key("oneway:bicycle")
data.cycleway = way:get_value_by_key("cycleway")
data.cycleway_left = way:get_value_by_key("cycleway:left")
data.cycleway_right = way:get_value_by_key("cycleway:right")
data.duration = way:get_value_by_key("duration")
data.service = way:get_value_by_key("service")
data.foot = way:get_value_by_key("foot")
data.foot_forward = way:get_value_by_key("foot:forward")
data.foot_backward = way:get_value_by_key("foot:backward")
data.bicycle = way:get_value_by_key("bicycle")
speed_handler(profile,way,result,data)
oneway_handler(profile,way,result,data)
cycleway_handler(profile,way,result,data)
bike_push_handler(profile,way,result,data)
-- width should be after bike_push
width_handler(profile,way,result,data)
2018-04-12 07:15:07 -04:00
-- maxspeed
limit( result, data.maxspeed, data.maxspeed_forward, data.maxspeed_backward )
-- not routable if no speed assigned
-- this avoid assertions in debug builds
if result.forward_speed <= 0 and result.duration <= 0 then
result.forward_mode = mode.inaccessible
end
if result.backward_speed <= 0 and result.duration <= 0 then
result.backward_mode = mode.inaccessible
end
safety_handler(profile,way,result,data)
end
function speed_handler(profile,way,result,data)
data.way_type_allows_pushing = false
2014-03-27 16:19:26 -04:00
-- speed
2018-04-12 07:15:07 -04:00
local bridge_speed = profile.bridge_speeds[data.bridge]
if (bridge_speed and bridge_speed > 0) then
2018-04-12 07:15:07 -04:00
data.highway = data.bridge
if data.duration and durationIsValid(data.duration) then
result.duration = math.max( parseDuration(data.duration), 1 )
end
result.forward_speed = bridge_speed
result.backward_speed = bridge_speed
2018-04-12 07:15:07 -04:00
data.way_type_allows_pushing = true
elseif profile.route_speeds[data.route] then
2014-03-27 16:19:26 -04:00
-- ferries (doesn't cover routes tagged using relations)
result.forward_mode = mode.ferry
result.backward_mode = mode.ferry
2018-04-12 07:15:07 -04:00
if data.duration and durationIsValid(data.duration) then
result.duration = math.max( 1, parseDuration(data.duration) )
2014-03-27 16:19:26 -04:00
else
2018-04-12 07:15:07 -04:00
result.forward_speed = profile.route_speeds[data.route]
result.backward_speed = profile.route_speeds[data.route]
2014-03-27 16:19:26 -04:00
end
-- railway platforms (old tagging scheme)
2018-04-12 07:15:07 -04:00
elseif data.railway and profile.platform_speeds[data.railway] then
result.forward_speed = profile.platform_speeds[data.railway]
result.backward_speed = profile.platform_speeds[data.railway]
data.way_type_allows_pushing = true
-- public_transport platforms (new tagging platform)
2018-04-12 07:15:07 -04:00
elseif data.public_transport and profile.platform_speeds[data.public_transport] then
result.forward_speed = profile.platform_speeds[data.public_transport]
result.backward_speed = profile.platform_speeds[data.public_transport]
data.way_type_allows_pushing = true
-- railways
2018-04-12 07:15:07 -04:00
elseif profile.use_public_transport and data.railway and profile.railway_speeds[data.railway] and profile.access_tag_whitelist[data.access] then
result.forward_mode = mode.train
result.backward_mode = mode.train
2018-04-12 07:15:07 -04:00
result.forward_speed = profile.railway_speeds[data.railway]
result.backward_speed = profile.railway_speeds[data.railway]
elseif data.amenity and profile.amenity_speeds[data.amenity] then
2014-03-27 16:19:26 -04:00
-- parking areas
2018-04-12 07:15:07 -04:00
result.forward_speed = profile.amenity_speeds[data.amenity]
result.backward_speed = profile.amenity_speeds[data.amenity]
data.way_type_allows_pushing = true
2017-02-05 14:44:04 -05:00
elseif profile.bicycle_speeds[data.highway] then
2014-03-27 16:19:26 -04:00
-- regular ways
2017-02-05 14:44:04 -05:00
result.forward_speed = profile.bicycle_speeds[data.highway]
result.backward_speed = profile.bicycle_speeds[data.highway]
2018-04-12 07:15:07 -04:00
data.way_type_allows_pushing = true
elseif data.access and profile.access_tag_whitelist[data.access] then
2014-03-27 16:19:26 -04:00
-- unknown way, but valid access tag
2017-05-18 08:27:28 -04:00
result.forward_speed = profile.default_speed
result.backward_speed = profile.default_speed
2018-04-12 07:15:07 -04:00
data.way_type_allows_pushing = true
2014-03-27 16:19:26 -04:00
end
2018-04-12 07:15:07 -04:00
end
2014-03-27 16:19:26 -04:00
2018-04-12 07:15:07 -04:00
function oneway_handler(profile,way,result,data)
-- oneway
2018-04-12 07:15:07 -04:00
data.implied_oneway = data.junction == "roundabout" or data.junction == "circular" or data.highway == "motorway"
data.reverse = false
2014-03-27 16:19:26 -04:00
2018-04-12 07:15:07 -04:00
if data.oneway_bicycle == "yes" or data.oneway_bicycle == "1" or data.oneway_bicycle == "true" then
result.backward_mode = mode.inaccessible
2018-04-12 07:15:07 -04:00
elseif data.oneway_bicycle == "no" or data.oneway_bicycle == "0" or data.oneway_bicycle == "false" then
-- prevent other cases
2018-04-12 07:15:07 -04:00
elseif data.oneway_bicycle == "-1" then
result.forward_mode = mode.inaccessible
2018-04-12 07:15:07 -04:00
data.reverse = true
elseif data.oneway == "yes" or data.oneway == "1" or data.oneway == "true" then
result.backward_mode = mode.inaccessible
2018-04-12 07:15:07 -04:00
elseif data.oneway == "no" or data.oneway == "0" or data.oneway == "false" then
-- prevent other cases
2018-04-12 07:15:07 -04:00
elseif data.oneway == "-1" then
result.forward_mode = mode.inaccessible
2018-04-12 07:15:07 -04:00
data.reverse = true
elseif data.implied_oneway then
result.backward_mode = mode.inaccessible
2014-03-27 16:19:26 -04:00
end
2018-04-12 07:15:07 -04:00
end
2014-08-27 12:38:30 -04:00
2018-04-12 07:15:07 -04:00
function cycleway_handler(profile,way,result,data)
-- cycleway
2018-04-12 07:15:07 -04:00
data.has_cycleway_forward = false
data.has_cycleway_backward = false
data.is_twoway = result.forward_mode ~= mode.inaccessible and result.backward_mode ~= mode.inaccessible and not data.implied_oneway
-- cycleways on normal roads
2018-04-12 07:15:07 -04:00
if data.is_twoway then
if data.cycleway and profile.cycleway_tags[data.cycleway] then
data.has_cycleway_backward = true
data.has_cycleway_forward = true
end
2018-04-12 07:15:07 -04:00
if (data.cycleway_right and profile.cycleway_tags[data.cycleway_right]) or (data.cycleway_left and profile.opposite_cycleway_tags[data.cycleway_left]) then
data.has_cycleway_forward = true
end
2018-04-12 07:15:07 -04:00
if (data.cycleway_left and profile.cycleway_tags[data.cycleway_left]) or (data.cycleway_right and profile.opposite_cycleway_tags[data.cycleway_right]) then
data.has_cycleway_backward = true
end
else
2018-04-12 07:15:07 -04:00
local has_twoway_cycleway = (data.cycleway and profile.opposite_cycleway_tags[data.cycleway]) or (data.cycleway_right and profile.opposite_cycleway_tags[data.cycleway_right]) or (data.cycleway_left and profile.opposite_cycleway_tags[data.cycleway_left])
local has_opposite_cycleway = (data.cycleway_left and profile.opposite_cycleway_tags[data.cycleway_left]) or (data.cycleway_right and profile.opposite_cycleway_tags[data.cycleway_right])
local has_oneway_cycleway = (data.cycleway and profile.cycleway_tags[data.cycleway]) or (data.cycleway_right and profile.cycleway_tags[data.cycleway_right]) or (data.cycleway_left and profile.cycleway_tags[data.cycleway_left])
-- set cycleway even though it is an one-way if opposite is tagged
if has_twoway_cycleway then
2018-04-12 07:15:07 -04:00
data.has_cycleway_backward = true
data.has_cycleway_forward = true
elseif has_opposite_cycleway then
2018-04-12 07:15:07 -04:00
if not data.reverse then
data.has_cycleway_backward = true
else
2018-04-12 07:15:07 -04:00
data.has_cycleway_forward = true
end
elseif has_oneway_cycleway then
2018-04-12 07:15:07 -04:00
if not data.reverse then
data.has_cycleway_forward = true
else
2018-04-12 07:15:07 -04:00
data.has_cycleway_backward = true
end
end
2017-03-27 08:31:08 -04:00
end
2018-04-12 07:15:07 -04:00
if data.has_cycleway_backward then
result.backward_mode = mode.cycling
2017-02-04 17:05:00 -05:00
result.backward_speed = profile.bicycle_speeds["cycleway"]
2014-03-27 16:19:26 -04:00
end
2018-04-12 07:15:07 -04:00
if data.has_cycleway_forward then
result.forward_mode = mode.cycling
result.forward_speed = profile.bicycle_speeds["cycleway"]
end
2018-04-12 07:15:07 -04:00
end
function width_handler(profile,way,result,data)
if profile.exclude_cargo_bike then
local cargo_bike = way:get_value_by_key("cargo_bike")
if cargo_bike and cargo_bike == "no" then
result.forward_mode = mode.inaccessible
result.backward_mode = mode.inaccessible
end
end
if profile.width then
local width = way:get_value_by_key("width")
if width then
local width_meter = Measure.parse_value_meters(width)
if width_meter and width_meter < profile.width then
result.forward_mode = mode.inaccessible
result.backward_mode = mode.inaccessible
end
end
end
end
2018-04-12 07:15:07 -04:00
function bike_push_handler(profile,way,result,data)
-- pushing bikes - if no other mode found
if result.forward_mode == mode.inaccessible or result.backward_mode == mode.inaccessible or
result.forward_speed == -1 or result.backward_speed == -1 then
2018-04-12 07:15:07 -04:00
if data.foot ~= 'no' then
local push_forward_speed = nil
local push_backward_speed = nil
if profile.pedestrian_speeds[data.highway] then
push_forward_speed = profile.pedestrian_speeds[data.highway]
push_backward_speed = profile.pedestrian_speeds[data.highway]
2018-04-12 07:15:07 -04:00
elseif data.man_made and profile.man_made_speeds[data.man_made] then
push_forward_speed = profile.man_made_speeds[data.man_made]
push_backward_speed = profile.man_made_speeds[data.man_made]
else
2018-04-12 07:15:07 -04:00
if data.foot == 'yes' then
2017-05-18 08:27:28 -04:00
push_forward_speed = profile.walking_speed
2018-04-12 07:15:07 -04:00
if not data.implied_oneway then
2017-05-18 08:27:28 -04:00
push_backward_speed = profile.walking_speed
end
2018-04-12 07:15:07 -04:00
elseif data.foot_forward == 'yes' then
2017-05-18 08:27:28 -04:00
push_forward_speed = profile.walking_speed
2018-04-12 07:15:07 -04:00
elseif data.foot_backward == 'yes' then
2017-05-18 08:27:28 -04:00
push_backward_speed = profile.walking_speed
2018-04-12 07:15:07 -04:00
elseif data.way_type_allows_pushing then
2017-05-18 08:27:28 -04:00
push_forward_speed = profile.walking_speed
2018-04-12 07:15:07 -04:00
if not data.implied_oneway then
2017-05-18 08:27:28 -04:00
push_backward_speed = profile.walking_speed
end
end
end
if push_forward_speed and (result.forward_mode == mode.inaccessible or result.forward_speed == -1) then
result.forward_mode = mode.pushing_bike
result.forward_speed = push_forward_speed
end
if push_backward_speed and (result.backward_mode == mode.inaccessible or result.backward_speed == -1)then
result.backward_mode = mode.pushing_bike
result.backward_speed = push_backward_speed
end
end
end
2014-08-12 08:18:02 -04:00
-- dismount
2018-04-12 07:15:07 -04:00
if data.bicycle == "dismount" then
result.forward_mode = mode.pushing_bike
result.backward_mode = mode.pushing_bike
2017-05-18 08:27:28 -04:00
result.forward_speed = profile.walking_speed
result.backward_speed = profile.walking_speed
2014-08-12 08:18:02 -04:00
end
2018-04-12 07:15:07 -04:00
end
2014-08-12 08:18:02 -04:00
2018-04-12 07:15:07 -04:00
function safety_handler(profile,way,result,data)
-- convert duration into cyclability
2017-05-18 08:27:28 -04:00
if profile.properties.weight_name == 'cyclability' then
2018-04-12 07:15:07 -04:00
local safety_penalty = profile.unsafe_highway_list[data.highway] or 1.
local is_unsafe = safety_penalty < 1
2018-04-12 07:15:07 -04:00
-- primaries that are one ways are probably huge primaries where the lanes need to be separated
if is_unsafe and data.highway == 'primary' and not data.is_twoway then
safety_penalty = safety_penalty * 0.5
end
if is_unsafe and data.highway == 'secondary' and not data.is_twoway then
safety_penalty = safety_penalty * 0.6
end
2018-04-12 07:15:07 -04:00
local forward_is_unsafe = is_unsafe and not data.has_cycleway_forward
local backward_is_unsafe = is_unsafe and not data.has_cycleway_backward
local is_undesireable = data.highway == "service" and profile.service_penalties[data.service]
local forward_penalty = 1.
local backward_penalty = 1.
if forward_is_unsafe then
forward_penalty = math.min(forward_penalty, safety_penalty)
end
if backward_is_unsafe then
backward_penalty = math.min(backward_penalty, safety_penalty)
end
2017-06-30 07:23:05 -04:00
2018-04-12 07:15:07 -04:00
if is_undesireable then
forward_penalty = math.min(forward_penalty, profile.service_penalties[data.service])
backward_penalty = math.min(backward_penalty, profile.service_penalties[data.service])
end
2017-02-04 17:50:00 -05:00
2018-04-12 07:15:07 -04:00
if result.forward_speed > 0 then
-- convert from km/h to m/s
result.forward_rate = result.forward_speed / 3.6 * forward_penalty
end
if result.backward_speed > 0 then
-- convert from km/h to m/s
result.backward_rate = result.backward_speed / 3.6 * backward_penalty
end
if result.duration > 0 then
result.weight = result.duration / forward_penalty
end
end
2017-05-18 08:27:28 -04:00
end
2018-04-12 07:15:07 -04:00
2017-07-19 09:32:42 -04:00
function process_way(profile, way, result)
2017-05-18 08:27:28 -04:00
-- the initial filtering of ways based on presence of tags
-- affects processing times significantly, because all ways
-- have to be checked.
-- to increase performance, prefetching and initial tag check
-- is done directly instead of via a handler.
-- in general we should try to abort as soon as
-- possible if the way is not routable, to avoid doing
-- unnecessary work. this implies we should check things that
-- commonly forbids access early, and handle edge cases later.
-- data table for storing intermediate values during processing
local data = {
-- prefetch tags
highway = way:get_value_by_key('highway'),
2018-04-12 07:15:07 -04:00
route = nil,
man_made = nil,
railway = nil,
amenity = nil,
public_transport = nil,
bridge = nil,
access = nil,
junction = nil,
maxspeed = nil,
maxspeed_forward = nil,
maxspeed_backward = nil,
barrier = nil,
oneway = nil,
oneway_bicycle = nil,
cycleway = nil,
cycleway_left = nil,
cycleway_right = nil,
duration = nil,
service = nil,
foot = nil,
foot_forward = nil,
foot_backward = nil,
bicycle = nil,
way_type_allows_pushing = false,
has_cycleway_forward = false,
has_cycleway_backward = false,
is_twoway = true,
reverse = false,
implied_oneway = false
2017-05-18 08:27:28 -04:00
}
2017-02-04 17:50:00 -05:00
local handlers = Sequence {
2017-05-18 08:27:28 -04:00
-- set the default mode for this profile. if can be changed later
-- in case it turns we're e.g. on a ferry
WayHandlers.default_mode,
-- check various tags that could indicate that the way is not
-- routable. this includes things like status=impassable,
-- toll=yes and oneway=reversible
WayHandlers.blocked_ways,
-- our main handler
handle_bicycle_tags,
2017-02-04 17:50:00 -05:00
-- compute speed taking into account way type, maxspeed tags, etc.
2017-05-18 08:27:28 -04:00
WayHandlers.surface,
2017-02-04 17:50:00 -05:00
-- handle turn lanes and road classification, used for guidance
2017-05-18 08:27:28 -04:00
WayHandlers.classification,
-- handle allowed start/end modes
2017-05-18 08:27:28 -04:00
WayHandlers.startpoint,
-- handle roundabouts
WayHandlers.roundabouts,
2017-02-04 17:50:00 -05:00
-- set name, ref and pronunciation
WayHandlers.names,
-- set classes
WayHandlers.classes,
-- set weight properties of the way
WayHandlers.weights
2017-02-04 17:50:00 -05:00
}
WayHandlers.run(profile, way, result, data, handlers)
end
2013-02-23 02:33:33 -05:00
2017-05-18 08:27:28 -04:00
function process_turn(profile, turn)
2014-03-27 16:19:26 -04:00
-- compute turn penalty as angle^2, with a left/right bias
local normalized_angle = turn.angle / 90.0
if normalized_angle >= 0.0 then
2017-02-04 17:05:00 -05:00
turn.duration = normalized_angle * normalized_angle * profile.turn_penalty / profile.turn_bias
2014-03-27 16:19:26 -04:00
else
2017-02-04 17:05:00 -05:00
turn.duration = normalized_angle * normalized_angle * profile.turn_penalty * profile.turn_bias
end
if turn.is_u_turn then
2017-05-18 08:27:28 -04:00
turn.duration = turn.duration + profile.properties.u_turn_penalty
end
if turn.has_traffic_light then
2017-05-18 08:27:28 -04:00
turn.duration = turn.duration + profile.properties.traffic_light_penalty
2014-03-27 16:19:26 -04:00
end
2017-05-18 08:27:28 -04:00
if profile.properties.weight_name == 'cyclability' then
turn.weight = turn.duration
end
if turn.source_mode == mode.cycling and turn.target_mode ~= mode.cycling then
turn.weight = turn.weight + profile.properties.mode_change_penalty
end
2013-02-23 02:33:33 -05:00
end
2017-05-18 08:27:28 -04:00
return {
setup = setup,
process_way = process_way,
process_node = process_node,
process_turn = process_turn
}