osrm-backend/profiles/foot.lua

265 lines
7.0 KiB
Lua
Raw Normal View History

-- Foot profile
api_version = 1
local find_access_tag = require("lib/access").find_access_tag
local Set = require('lib/set')
local Sequence = require('lib/sequence')
local Handlers = require("lib/handlers")
local next = next -- bind to local for speed
2015-05-29 14:45:34 -04:00
properties.max_speed_for_map_matching = 40/3.6 -- kmph -> m/s
2016-04-12 12:47:00 -04:00
properties.use_turn_restrictions = false
properties.continue_straight_at_waypoint = false
properties.weight_name = 'duration'
--properties.weight_name = 'routability'
-- Set to true if you need to call the node_function for every node.
-- Generally can be left as false to avoid unnecessary Lua calls
-- (which slow down pre-processing).
properties.call_tagless_node_function = false
local walking_speed = 5
local profile = {
default_mode = mode.walking,
default_speed = walking_speed,
oneway_handling = 'specific', -- respect 'oneway:foot' but not 'oneway'
traffic_light_penalty = 2,
u_turn_penalty = 2,
2017-02-01 16:08:14 -05:00
barrier_whitelist = Set {
'cycle_barrier',
'bollard',
'entrance',
'cattle_grid',
'border_control',
'toll_booth',
'sally_port',
'gate',
'no',
'kerb',
'block'
},
2017-02-01 16:08:14 -05:00
access_tag_whitelist = Set {
2017-02-01 16:08:14 -05:00
'yes',
'foot',
'permissive',
'designated'
},
2017-02-01 16:08:14 -05:00
access_tag_blacklist = Set {
2017-02-01 16:08:14 -05:00
'no',
'agricultural',
'forestry',
'private',
'delivery',
},
restricted_access_tag_list = Set { },
restricted_highway_whitelist = Set { },
access_tags_hierarchy = Sequence {
'foot',
'access'
},
restrictions = Sequence {
'foot'
},
-- list of suffixes to suppress in name change instructions
suffix_list = Set {
'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'North', 'South', 'West', 'East'
},
2017-02-01 16:08:14 -05:00
avoid = Set {
'impassable'
},
2017-02-01 16:08:14 -05:00
speeds = Sequence {
highway = {
primary = walking_speed,
primary_link = walking_speed,
secondary = walking_speed,
secondary_link = walking_speed,
tertiary = walking_speed,
tertiary_link = walking_speed,
unclassified = walking_speed,
residential = walking_speed,
road = walking_speed,
living_street = walking_speed,
service = walking_speed,
track = walking_speed,
path = walking_speed,
steps = walking_speed,
pedestrian = walking_speed,
footway = walking_speed,
pier = walking_speed,
},
railway = {
platform = walking_speed
},
amenity = {
parking = walking_speed,
parking_entrance= walking_speed
},
man_made = {
pier = walking_speed
},
2017-02-01 16:08:14 -05:00
leisure = {
track = walking_speed
}
},
2017-02-01 16:08:14 -05:00
route_speeds = {
ferry = 5
},
2017-02-01 16:08:14 -05:00
bridge_speeds = {
},
surface_speeds = {
fine_gravel = walking_speed*0.75,
gravel = walking_speed*0.75,
pebblestone = walking_speed*0.75,
mud = walking_speed*0.5,
sand = walking_speed*0.5
2017-02-01 16:08:14 -05:00
},
tracktype_speeds = {
},
smoothness_speeds = {
}
}
2013-12-06 06:06:51 -05:00
function node_function (node, result)
2015-05-29 14:48:04 -04:00
-- parse access and barrier tags
local access = find_access_tag(node, profile.access_tags_hierarchy)
if access then
if profile.access_tag_blacklist[access] then
2015-05-29 14:48:04 -04:00
result.barrier = true
end
else
local barrier = node:get_value_by_key("barrier")
if barrier then
-- make an exception for rising bollard barriers
local bollard = node:get_value_by_key("bollard")
local rising_bollard = bollard and "rising" == bollard
if not profile.barrier_whitelist[barrier] and not rising_bollard then
result.barrier = true
end
end
2015-05-29 14:48:04 -04:00
end
2013-12-06 06:06:51 -05:00
-- check if node is a traffic light
local tag = node:get_value_by_key("highway")
if "traffic_signals" == tag then
result.traffic_lights = true
end
2015-05-29 14:48:04 -04:00
end
-- main entry point for processsing a way
function way_function(way, result)
-- the intial filtering of ways based on presence of tags
-- affects processing times significantly, because all ways
-- have to be checked.
-- to increase performance, prefetching and intial tag check
-- is done in 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'),
2017-02-21 16:09:33 -05:00
bridge = way:get_value_by_key('bridge'),
route = way:get_value_by_key('route'),
leisure = way:get_value_by_key('leisure'),
man_made = way:get_value_by_key('man_made'),
railway = way:get_value_by_key('railway'),
platform = way:get_value_by_key('platform'),
amenity = way:get_value_by_key('amenity'),
public_transport = way:get_value_by_key('public_transport')
}
-- perform an quick initial check and abort if the way is
-- obviously not routable. here we require at least one
-- of the prefetched tags to be present, ie. the data table
-- cannot be empty
if next(data) == nil then -- is the data table empty?
return
end
local handlers = Sequence {
-- set the default mode for this profile. if can be changed later
-- in case it turns we're e.g. on a ferry
'handle_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
'handle_blocked_ways',
-- determine access status by checking our hierarchy of
-- access tags, e.g: motorcar, motor_vehicle, vehicle
'handle_access',
-- check whether forward/backward directons are routable
'handle_oneway',
-- check whether forward/backward directons are routable
'handle_destinations',
-- check whether we're using a special transport mode
'handle_ferries',
'handle_movables',
-- compute speed taking into account way type, maxspeed tags, etc.
'handle_speed',
'handle_surface',
-- handle turn lanes and road classification, used for guidance
'handle_classification',
-- handle various other flags
'handle_roundabouts',
'handle_startpoint',
-- set name, ref and pronunciation
'handle_names'
}
2017-02-01 16:08:14 -05:00
Handlers.run(handlers,way,result,data,profile)
end
function turn_function (turn)
turn.duration = 0.
if turn.direction_modifier == direction_modifier.u_turn then
turn.duration = turn.duration + profile.u_turn_penalty
end
if turn.has_traffic_light then
turn.duration = profile.traffic_light_penalty
end
if properties.weight_name == 'routability' then
-- penalize turns from non-local access only segments onto local access only tags
if not turn.source_restricted and turn.target_restricted then
turn.weight = turn.weight + 3000
end
end
end