In lua, replace access to speed by functions
This commit is contained in:
parent
f928956584
commit
e313429d11
@ -10,6 +10,7 @@ find_access_tag = require("lib/access").find_access_tag
|
|||||||
limit = require("lib/maxspeed").limit
|
limit = require("lib/maxspeed").limit
|
||||||
Utils = require("lib/utils")
|
Utils = require("lib/utils")
|
||||||
Measure = require("lib/measure")
|
Measure = require("lib/measure")
|
||||||
|
Tags = require('lib/tags')
|
||||||
|
|
||||||
function setup()
|
function setup()
|
||||||
return {
|
return {
|
||||||
@ -30,11 +31,11 @@ function setup()
|
|||||||
},
|
},
|
||||||
|
|
||||||
default_mode = mode.driving,
|
default_mode = mode.driving,
|
||||||
default_speed = 10,
|
default_speed = function(way) return 10 end,
|
||||||
oneway_handling = true,
|
oneway_handling = true,
|
||||||
side_road_multiplier = 0.8,
|
side_road_multiplier = 0.8,
|
||||||
turn_penalty = 7.5,
|
turn_penalty = 7.5,
|
||||||
speed_reduction = 0.8,
|
speed_reduction = function(way, speed) return speed * 0.8 end,
|
||||||
turn_bias = 1.075,
|
turn_bias = 1.075,
|
||||||
cardinal_directions = false,
|
cardinal_directions = false,
|
||||||
|
|
||||||
@ -136,24 +137,28 @@ function setup()
|
|||||||
'proposed'
|
'proposed'
|
||||||
},
|
},
|
||||||
|
|
||||||
speeds = Sequence {
|
speeds = function(way)
|
||||||
highway = {
|
local s = Sequence {
|
||||||
motorway = 90,
|
highway = {
|
||||||
motorway_link = 45,
|
motorway = 90,
|
||||||
trunk = 85,
|
motorway_link = 45,
|
||||||
trunk_link = 40,
|
trunk = 85,
|
||||||
primary = 65,
|
trunk_link = 40,
|
||||||
primary_link = 30,
|
primary = 65,
|
||||||
secondary = 55,
|
primary_link = 30,
|
||||||
secondary_link = 25,
|
secondary = 55,
|
||||||
tertiary = 40,
|
secondary_link = 25,
|
||||||
tertiary_link = 20,
|
tertiary = 40,
|
||||||
unclassified = 25,
|
tertiary_link = 20,
|
||||||
residential = 25,
|
unclassified = 25,
|
||||||
living_street = 10,
|
residential = 25,
|
||||||
service = 15
|
living_street = 10,
|
||||||
|
service = 15
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
return Tags.get_constant_by_key_value(way, s)
|
||||||
|
end,
|
||||||
|
|
||||||
service_penalties = {
|
service_penalties = {
|
||||||
alley = 0.5,
|
alley = 0.5,
|
||||||
|
|||||||
@ -6,6 +6,7 @@ Set = require('lib/set')
|
|||||||
Sequence = require('lib/sequence')
|
Sequence = require('lib/sequence')
|
||||||
Handlers = require("lib/way_handlers")
|
Handlers = require("lib/way_handlers")
|
||||||
find_access_tag = require("lib/access").find_access_tag
|
find_access_tag = require("lib/access").find_access_tag
|
||||||
|
Tags = require('lib/tags')
|
||||||
|
|
||||||
function setup()
|
function setup()
|
||||||
local walking_speed = 5
|
local walking_speed = 5
|
||||||
@ -21,7 +22,7 @@ function setup()
|
|||||||
},
|
},
|
||||||
|
|
||||||
default_mode = mode.walking,
|
default_mode = mode.walking,
|
||||||
default_speed = walking_speed,
|
default_speed = function(way) return walking_speed end,
|
||||||
oneway_handling = 'specific', -- respect 'oneway:foot' but not 'oneway'
|
oneway_handling = 'specific', -- respect 'oneway:foot' but not 'oneway'
|
||||||
|
|
||||||
barrier_blacklist = Set {
|
barrier_blacklist = Set {
|
||||||
@ -72,44 +73,49 @@ function setup()
|
|||||||
'impassable'
|
'impassable'
|
||||||
},
|
},
|
||||||
|
|
||||||
speeds = Sequence {
|
speeds = function(way)
|
||||||
highway = {
|
local s = Sequence {
|
||||||
primary = walking_speed,
|
highway = {
|
||||||
primary_link = walking_speed,
|
primary = walking_speed,
|
||||||
secondary = walking_speed,
|
primary_link = walking_speed,
|
||||||
secondary_link = walking_speed,
|
secondary = walking_speed,
|
||||||
tertiary = walking_speed,
|
secondary_link = walking_speed,
|
||||||
tertiary_link = walking_speed,
|
tertiary = walking_speed,
|
||||||
unclassified = walking_speed,
|
tertiary_link = walking_speed,
|
||||||
residential = walking_speed,
|
unclassified = walking_speed,
|
||||||
road = walking_speed,
|
residential = walking_speed,
|
||||||
living_street = walking_speed,
|
road = walking_speed,
|
||||||
service = walking_speed,
|
living_street = walking_speed,
|
||||||
track = walking_speed,
|
service = walking_speed,
|
||||||
path = walking_speed,
|
track = walking_speed,
|
||||||
steps = walking_speed,
|
path = walking_speed,
|
||||||
pedestrian = walking_speed,
|
steps = walking_speed,
|
||||||
footway = walking_speed,
|
pedestrian = walking_speed,
|
||||||
pier = walking_speed,
|
footway = walking_speed,
|
||||||
},
|
pier = walking_speed,
|
||||||
|
},
|
||||||
|
|
||||||
railway = {
|
railway = {
|
||||||
platform = walking_speed
|
platform = walking_speed
|
||||||
},
|
},
|
||||||
|
|
||||||
amenity = {
|
amenity = {
|
||||||
parking = walking_speed,
|
parking = walking_speed,
|
||||||
parking_entrance= walking_speed
|
parking_entrance= walking_speed
|
||||||
},
|
},
|
||||||
|
|
||||||
man_made = {
|
man_made = {
|
||||||
pier = walking_speed
|
pier = walking_speed
|
||||||
},
|
},
|
||||||
|
|
||||||
leisure = {
|
leisure = {
|
||||||
track = walking_speed
|
track = walking_speed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
print(way:id(), Tags.get_constant_by_key_value(way, s))
|
||||||
|
return Tags.get_constant_by_key_value(way, s)
|
||||||
|
end,
|
||||||
|
|
||||||
route_speeds = {
|
route_speeds = {
|
||||||
ferry = 5
|
ferry = 5
|
||||||
|
|||||||
@ -274,7 +274,7 @@ function WayHandlers.speed(profile,way,result,data)
|
|||||||
return -- abort if already set, eg. by a route
|
return -- abort if already set, eg. by a route
|
||||||
end
|
end
|
||||||
|
|
||||||
local key,value,speed = Tags.get_constant_by_key_value(way,profile.speeds)
|
local key,value,speed = profile.speeds(way)
|
||||||
|
|
||||||
if speed then
|
if speed then
|
||||||
-- set speed by way type
|
-- set speed by way type
|
||||||
@ -283,17 +283,17 @@ function WayHandlers.speed(profile,way,result,data)
|
|||||||
else
|
else
|
||||||
-- Set the avg speed on ways that are marked accessible
|
-- Set the avg speed on ways that are marked accessible
|
||||||
if profile.access_tag_whitelist[data.forward_access] then
|
if profile.access_tag_whitelist[data.forward_access] then
|
||||||
result.forward_speed = profile.default_speed
|
result.forward_speed = profile.default_speed(way)
|
||||||
elseif data.forward_access and not profile.access_tag_blacklist[data.forward_access] then
|
elseif data.forward_access and not profile.access_tag_blacklist[data.forward_access] then
|
||||||
result.forward_speed = profile.default_speed -- fallback to the avg speed if access tag is not blacklisted
|
result.forward_speed = profile.default_speed(way) -- fallback to the avg speed if access tag is not blacklisted
|
||||||
elseif not data.forward_access and data.backward_access then
|
elseif not data.forward_access and data.backward_access then
|
||||||
result.forward_mode = mode.inaccessible
|
result.forward_mode = mode.inaccessible
|
||||||
end
|
end
|
||||||
|
|
||||||
if profile.access_tag_whitelist[data.backward_access] then
|
if profile.access_tag_whitelist[data.backward_access] then
|
||||||
result.backward_speed = profile.default_speed
|
result.backward_speed = profile.default_speed(way)
|
||||||
elseif data.backward_access and not profile.access_tag_blacklist[data.backward_access] then
|
elseif data.backward_access and not profile.access_tag_blacklist[data.backward_access] then
|
||||||
result.backward_speed = profile.default_speed -- fallback to the avg speed if access tag is not blacklisted
|
result.backward_speed = profile.default_speed(way) -- fallback to the avg speed if access tag is not blacklisted
|
||||||
elseif not data.backward_access and data.forward_access then
|
elseif not data.backward_access and data.forward_access then
|
||||||
result.backward_mode = mode.inaccessible
|
result.backward_mode = mode.inaccessible
|
||||||
end
|
end
|
||||||
@ -438,11 +438,11 @@ function WayHandlers.maxspeed(profile,way,result,data)
|
|||||||
backward = WayHandlers.parse_maxspeed(backward,profile)
|
backward = WayHandlers.parse_maxspeed(backward,profile)
|
||||||
|
|
||||||
if forward and forward > 0 then
|
if forward and forward > 0 then
|
||||||
result.forward_speed = forward * profile.speed_reduction
|
result.forward_speed = profile.speed_reduction(way, forward)
|
||||||
end
|
end
|
||||||
|
|
||||||
if backward and backward > 0 then
|
if backward and backward > 0 then
|
||||||
result.backward_speed = backward * profile.speed_reduction
|
result.backward_speed = profile.speed_reduction(way, backward)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user