first round of handlers
This commit is contained in:
parent
3abab16bf3
commit
d81ef3f4db
@ -4,8 +4,9 @@ api_version = 1
|
|||||||
local find_access_tag = require("lib/access").find_access_tag
|
local find_access_tag = require("lib/access").find_access_tag
|
||||||
local Set = require('lib/set')
|
local Set = require('lib/set')
|
||||||
local Sequence = require('lib/sequence')
|
local Sequence = require('lib/sequence')
|
||||||
|
local Handlers = require("lib/handlers")
|
||||||
|
local next = next -- bind to local for speed
|
||||||
local limit = require("lib/maxspeed").limit
|
local limit = require("lib/maxspeed").limit
|
||||||
local set_classification = require("lib/guidance").set_classification
|
|
||||||
|
|
||||||
-- these need to be global because they are accesed externaly
|
-- these need to be global because they are accesed externaly
|
||||||
properties.max_speed_for_map_matching = 110/3.6 -- kmph -> m/s
|
properties.max_speed_for_map_matching = 110/3.6 -- kmph -> m/s
|
||||||
@ -19,20 +20,24 @@ local default_speed = 15
|
|||||||
local walking_speed = 6
|
local walking_speed = 6
|
||||||
|
|
||||||
local profile = {
|
local profile = {
|
||||||
default_mode = mode.cycling,
|
default_mode = mode.cycling,
|
||||||
default_speed = 15,
|
default_speed = 15,
|
||||||
oneway_handling = true,
|
oneway_handling = true,
|
||||||
|
|
||||||
traffic_light_penalty = 2,
|
traffic_light_penalty = 2,
|
||||||
u_turn_penalty = 20,
|
u_turn_penalty = 20,
|
||||||
turn_penalty = 6,
|
turn_penalty = 6,
|
||||||
turn_bias = 1.4,
|
turn_bias = 1.4,
|
||||||
|
|
||||||
-- reduce the driving speed by 30% for unsafe roads
|
-- reduce the driving speed by 30% for unsafe roads
|
||||||
-- local safety_penalty = 0.7,
|
-- local safety_penalty = 0.7,
|
||||||
safety_penalty = 1.0,
|
safety_penalty = 1.0,
|
||||||
use_public_transport = true,
|
use_public_transport = true,
|
||||||
|
|
||||||
|
allowed_start_modes = Set {
|
||||||
|
mode.cycling,
|
||||||
|
mode.pushing_bike
|
||||||
|
},
|
||||||
|
|
||||||
barrier_whitelist = Set {
|
barrier_whitelist = Set {
|
||||||
'cycle_barrier',
|
'cycle_barrier',
|
||||||
'bollard',
|
'bollard',
|
||||||
@ -45,7 +50,7 @@ local profile = {
|
|||||||
'no',
|
'no',
|
||||||
'block'
|
'block'
|
||||||
},
|
},
|
||||||
|
|
||||||
access_tag_whitelist = Set {
|
access_tag_whitelist = Set {
|
||||||
'yes',
|
'yes',
|
||||||
'permissive',
|
'permissive',
|
||||||
@ -59,17 +64,17 @@ local profile = {
|
|||||||
'forestry',
|
'forestry',
|
||||||
'delivery'
|
'delivery'
|
||||||
},
|
},
|
||||||
|
|
||||||
access_tags_hierarchy = Sequence {
|
access_tags_hierarchy = Sequence {
|
||||||
'bicycle',
|
'bicycle',
|
||||||
'vehicle',
|
'vehicle',
|
||||||
'access'
|
'access'
|
||||||
},
|
},
|
||||||
|
|
||||||
restrictions = Set {
|
restrictions = Set {
|
||||||
'bicycle'
|
'bicycle'
|
||||||
},
|
},
|
||||||
|
|
||||||
cycleway_tags = Set {
|
cycleway_tags = Set {
|
||||||
'track',
|
'track',
|
||||||
'lane',
|
'lane',
|
||||||
@ -80,7 +85,7 @@ local profile = {
|
|||||||
'sharrow',
|
'sharrow',
|
||||||
'shared'
|
'shared'
|
||||||
},
|
},
|
||||||
|
|
||||||
unsafe_highway_list = Set {
|
unsafe_highway_list = Set {
|
||||||
'primary',
|
'primary',
|
||||||
'secondary',
|
'secondary',
|
||||||
@ -89,7 +94,7 @@ local profile = {
|
|||||||
'secondary_link',
|
'secondary_link',
|
||||||
'tertiary_link'
|
'tertiary_link'
|
||||||
},
|
},
|
||||||
|
|
||||||
bicycle_speeds = {
|
bicycle_speeds = {
|
||||||
cycleway = default_speed,
|
cycleway = default_speed,
|
||||||
primary = default_speed,
|
primary = default_speed,
|
||||||
@ -105,10 +110,8 @@ local profile = {
|
|||||||
service = default_speed,
|
service = default_speed,
|
||||||
track = 12,
|
track = 12,
|
||||||
path = 12
|
path = 12
|
||||||
--footway = 12,
|
|
||||||
--pedestrian = 12,
|
|
||||||
},
|
},
|
||||||
|
|
||||||
pedestrian_speeds = {
|
pedestrian_speeds = {
|
||||||
footway = walking_speed,
|
footway = walking_speed,
|
||||||
pedestrian = walking_speed,
|
pedestrian = walking_speed,
|
||||||
@ -162,6 +165,11 @@ local profile = {
|
|||||||
mud = 3,
|
mud = 3,
|
||||||
sand = 3,
|
sand = 3,
|
||||||
sett = 10
|
sett = 10
|
||||||
|
},
|
||||||
|
|
||||||
|
avoid = Set {
|
||||||
|
'impassable',
|
||||||
|
'construction'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,6 +223,40 @@ function node_function (node, result)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function way_function (way, result)
|
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'),
|
||||||
|
}
|
||||||
|
|
||||||
|
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',
|
||||||
|
}
|
||||||
|
|
||||||
|
if Handlers.run(handlers,way,result,data,profile) == false then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- initial routability check, filters out buildings, boundaries, etc
|
-- initial routability check, filters out buildings, boundaries, etc
|
||||||
local highway = way:get_value_by_key("highway")
|
local highway = way:get_value_by_key("highway")
|
||||||
local route = way:get_value_by_key("route")
|
local route = way:get_value_by_key("route")
|
||||||
@ -234,23 +276,13 @@ function way_function (way, result)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- don't route on ways or railways that are still under construction
|
|
||||||
if highway=='construction' or railway=='construction' then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- access
|
-- access
|
||||||
local access = find_access_tag(way, profile.access_tags_hierarchy)
|
local access = find_access_tag(way, profile.access_tags_hierarchy)
|
||||||
if access and profile.access_tag_blacklist[access] then
|
if access and profile.access_tag_blacklist[access] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
result.forward_mode = mode.cycling
|
|
||||||
result.backward_mode = mode.cycling
|
|
||||||
|
|
||||||
-- other tags
|
-- other tags
|
||||||
local name = way:get_value_by_key("name")
|
|
||||||
local ref = way:get_value_by_key("ref")
|
|
||||||
local junction = way:get_value_by_key("junction")
|
local junction = way:get_value_by_key("junction")
|
||||||
local maxspeed = parse_maxspeed(way:get_value_by_key ( "maxspeed") )
|
local maxspeed = parse_maxspeed(way:get_value_by_key ( "maxspeed") )
|
||||||
local maxspeed_forward = parse_maxspeed(way:get_value_by_key( "maxspeed:forward"))
|
local maxspeed_forward = parse_maxspeed(way:get_value_by_key( "maxspeed:forward"))
|
||||||
@ -263,29 +295,11 @@ function way_function (way, result)
|
|||||||
local cycleway_right = way:get_value_by_key("cycleway:right")
|
local cycleway_right = way:get_value_by_key("cycleway:right")
|
||||||
local duration = way:get_value_by_key("duration")
|
local duration = way:get_value_by_key("duration")
|
||||||
local service = way:get_value_by_key("service")
|
local service = way:get_value_by_key("service")
|
||||||
local area = way:get_value_by_key("area")
|
|
||||||
local foot = way:get_value_by_key("foot")
|
local foot = way:get_value_by_key("foot")
|
||||||
local foot_forward = way:get_value_by_key("foot:forward")
|
local foot_forward = way:get_value_by_key("foot:forward")
|
||||||
local foot_backward = way:get_value_by_key("foot:backward")
|
local foot_backward = way:get_value_by_key("foot:backward")
|
||||||
local bicycle = way:get_value_by_key("bicycle")
|
local bicycle = way:get_value_by_key("bicycle")
|
||||||
|
|
||||||
-- name
|
|
||||||
if name and "" ~= name then
|
|
||||||
result.name = name
|
|
||||||
end
|
|
||||||
|
|
||||||
-- ref
|
|
||||||
if ref and "" ~= ref then
|
|
||||||
result.ref = ref
|
|
||||||
end
|
|
||||||
|
|
||||||
-- roundabout handling
|
|
||||||
if junction and ("roundabout" == junction) then
|
|
||||||
result.roundabout = true
|
|
||||||
end
|
|
||||||
if junction and ("circular" == junction) then
|
|
||||||
result.circular = true;
|
|
||||||
end
|
|
||||||
|
|
||||||
-- speed
|
-- speed
|
||||||
local bridge_speed = profile.bridge_speeds[bridge]
|
local bridge_speed = profile.bridge_speeds[bridge]
|
||||||
@ -441,16 +455,6 @@ function way_function (way, result)
|
|||||||
result.backward_speed = walking_speed
|
result.backward_speed = walking_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
-- reduce speed on bad surfaces
|
|
||||||
local surface = way:get_value_by_key("surface")
|
|
||||||
|
|
||||||
if surface and profile.surface_speeds[surface] then
|
|
||||||
result.forward_speed = math.min(profile.surface_speeds[surface], result.forward_speed)
|
|
||||||
result.backward_speed = math.min(profile.surface_speeds[surface], result.backward_speed)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- set the road classification based on guidance globals configuration
|
|
||||||
set_classification(highway,result,way)
|
|
||||||
|
|
||||||
-- maxspeed
|
-- maxspeed
|
||||||
limit( result, maxspeed, maxspeed_forward, maxspeed_backward )
|
limit( result, maxspeed, maxspeed_forward, maxspeed_backward )
|
||||||
@ -477,6 +481,26 @@ function way_function (way, result)
|
|||||||
result.weight = result.weight * (1+profile.safety_penalty)
|
result.weight = result.weight * (1+profile.safety_penalty)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local handlers = Sequence {
|
||||||
|
-- compute speed taking into account way type, maxspeed tags, etc.
|
||||||
|
'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'
|
||||||
|
}
|
||||||
|
|
||||||
|
Handlers.run(handlers,way,result,data,profile)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function turn_function(turn)
|
function turn_function(turn)
|
||||||
|
@ -65,9 +65,15 @@ end
|
|||||||
|
|
||||||
-- determine if this way can be used as a start/end point for routing
|
-- determine if this way can be used as a start/end point for routing
|
||||||
function Handlers.handle_startpoint(way,result,data,profile)
|
function Handlers.handle_startpoint(way,result,data,profile)
|
||||||
-- only allow this road as start point if it not a ferry
|
-- if profile specifies set of allowed start modes, then check for that
|
||||||
result.is_startpoint = result.forward_mode == profile.default_mode or
|
-- otherwise require default mode
|
||||||
result.backward_mode == profile.default_mode
|
if profile.allowed_start_modes then
|
||||||
|
result.is_startpoint = profile.allowed_start_modes[result.forward_mode] == true or
|
||||||
|
profile.allowed_start_modes[result.backward_mode] == true
|
||||||
|
else
|
||||||
|
result.is_startpoint = result.forward_mode == profile.default_mode or
|
||||||
|
result.backward_mode == profile.default_mode
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- handle turn lanes
|
-- handle turn lanes
|
||||||
@ -431,6 +437,12 @@ function Handlers.handle_blocked_ways(way,result,data,profile)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- construction
|
||||||
|
-- TODO if highway is valid then we shouldn't check railway, and vica versa
|
||||||
|
if profile.avoid.construction and (data.highway == 'construction' or way:get_value_by_key('railway') == 'construction') then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
-- Reversible oneways change direction with low frequency (think twice a day):
|
-- Reversible oneways change direction with low frequency (think twice a day):
|
||||||
-- do not route over these at all at the moment because of time dependence.
|
-- do not route over these at all at the moment because of time dependence.
|
||||||
-- Note: alternating (high frequency) oneways are handled below with penalty.
|
-- Note: alternating (high frequency) oneways are handled below with penalty.
|
||||||
|
Loading…
Reference in New Issue
Block a user