Lua maxspeed parsing refactoring (#5144)
* Lua maxspeed parsing refactoring
This commit is contained in:
parent
77b4fbb69c
commit
714719c377
@ -14,6 +14,7 @@
|
||||
- CHANGED: matching will now consider edges marked with is_startpoint=false, allowing matching over ferries and other previously non-matchable edge types. [#5297](https://github.com/Project-OSRM/osrm-backend/pull/5297)
|
||||
- Profile:
|
||||
- ADDED: Parse `source:maxspeed` and `maxspeed:type` tags to apply maxspeeds and add belgian flanders rural speed limit. [#5217](https://github.com/Project-OSRM/osrm-backend/pull/5217)
|
||||
- CHANGED: Refactor maxspeed parsing to use common library. [#5144](https://github.com/Project-OSRM/osrm-backend/pull/5144)
|
||||
|
||||
# 5.20.0
|
||||
- Changes from 5.19.0:
|
||||
|
@ -7,6 +7,7 @@ Sequence = require('lib/sequence')
|
||||
Handlers = require("lib/way_handlers")
|
||||
find_access_tag = require("lib/access").find_access_tag
|
||||
limit = require("lib/maxspeed").limit
|
||||
Measure = require("lib/measure")
|
||||
|
||||
function setup()
|
||||
local default_speed = 15
|
||||
@ -206,20 +207,6 @@ function setup()
|
||||
}
|
||||
end
|
||||
|
||||
local function parse_maxspeed(source)
|
||||
if not source then
|
||||
return 0
|
||||
end
|
||||
local n = tonumber(source:match("%d*"))
|
||||
if not n then
|
||||
n = 0
|
||||
end
|
||||
if string.match(source, "mph") or string.match(source, "mp/h") then
|
||||
n = (n*1609)/1000
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
function process_node(profile, node, result)
|
||||
-- parse access and barrier tags
|
||||
local highway = node:get_value_by_key("highway")
|
||||
@ -276,9 +263,9 @@ function handle_bicycle_tags(profile,way,result,data)
|
||||
|
||||
-- other tags
|
||||
data.junction = way:get_value_by_key("junction")
|
||||
data.maxspeed = parse_maxspeed(way:get_value_by_key ( "maxspeed") )
|
||||
data.maxspeed_forward = parse_maxspeed(way:get_value_by_key( "maxspeed:forward"))
|
||||
data.maxspeed_backward = parse_maxspeed(way:get_value_by_key( "maxspeed:backward"))
|
||||
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
|
||||
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")
|
||||
|
@ -6,6 +6,18 @@ Measure = {}
|
||||
local inch_to_meters = 0.0254
|
||||
local feet_to_inches = 12
|
||||
local pound_to_kilograms = 0.45359237
|
||||
local miles_to_kilometers = 1.609
|
||||
|
||||
-- Parse speed value as kilometers by hours.
|
||||
function Measure.parse_value_speed(source)
|
||||
local n = tonumber(source:match("%d*"))
|
||||
if n then
|
||||
if string.match(source, "mph") or string.match(source, "mp/h") then
|
||||
n = n * miles_to_kilometers
|
||||
end
|
||||
return n
|
||||
end
|
||||
end
|
||||
|
||||
--- Parse string as a height in meters.
|
||||
--- according to http://wiki.openstreetmap.org/wiki/Key:maxheight
|
||||
@ -42,6 +54,13 @@ function Measure.parse_value_kilograms(value)
|
||||
end
|
||||
end
|
||||
|
||||
--- Get maxspeed of specified way in kilometers by hours.
|
||||
function Measure.get_max_speed(raw_value)
|
||||
if raw_value then
|
||||
return Measure.parse_value_speed(raw_value)
|
||||
end
|
||||
end
|
||||
|
||||
-- default maxheight value defined in https://wiki.openstreetmap.org/wiki/Key:maxheight#Non-numerical_values
|
||||
local default_maxheight = 4.5
|
||||
-- Available Non numerical values equal to 4.5; below_default and no_indications are not considered
|
||||
|
@ -450,12 +450,9 @@ function WayHandlers.parse_maxspeed(source,profile)
|
||||
if not source then
|
||||
return 0
|
||||
end
|
||||
local n = tonumber(source:match("%d*"))
|
||||
if n then
|
||||
if string.match(source, "mph") or string.match(source, "mp/h") then
|
||||
n = (n*1609)/1000
|
||||
end
|
||||
else
|
||||
|
||||
local n = Measure.get_max_speed(source)
|
||||
if not n then
|
||||
-- parse maxspeed like FR:urban
|
||||
source = string.lower(source)
|
||||
n = profile.maxspeed_table[source]
|
||||
|
Loading…
Reference in New Issue
Block a user