Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support maxlength and maxweight in car profile #5101

Merged
merged 3 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions features/car/physical_limitation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,22 @@ Feature: Car - Handle physical limitation
| primary | | none | x |
| primary | | no-sign | x |
| primary | | unsigned | x |

Scenario: Car - Limited by length
Then routability should be
| highway | maxlength | bothw |
| primary | | x |
| primary | 1 | |
| primary | 5 | x |
| primary | unsigned | x |

Scenario: Car - Limited by weight
Then routability should be
| highway | maxweight | bothw |
| primary | | x |
| primary | 1 | |
| primary | 3.5 | x |
| primary | 35000 kg | x |
| primary | 8.9t | x |
| primary | 0.1 lbs | |
| primary | unsigned | x |
6 changes: 6 additions & 0 deletions profiles/car.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ function setup()
vehicle_height = 2.5, -- in meters, 2.5m is the height of van
vehicle_width = 1.9, -- in meters, ways with narrow tag are considered narrower than 2.2m

-- Size of the vehicle, to be limited mostly by legal restriction of the way
vehicle_length = 4.8, -- in meters, 4.8m is the length of large or familly car
vehicle_weight = 3500, -- in kilograms

-- a list of suffixes to suppress in name change instructions. The suffixes also include common substrings of each other
suffix_list = {
'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'North', 'South', 'West', 'East', 'Nor', 'Sou', 'We', 'Ea'
Expand Down Expand Up @@ -387,6 +391,8 @@ function process_way(profile, way, result, relations)
WayHandlers.avoid_ways,
WayHandlers.handle_height,
WayHandlers.handle_width,
WayHandlers.handle_length,
WayHandlers.handle_weight,

-- determine access status by checking our hierarchy of
-- access tags, e.g: motorcar, motor_vehicle, vehicle
Expand Down
46 changes: 20 additions & 26 deletions profiles/lib/measure.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Measure = {}
-- measurements conversion constants
local inch_to_meters = 0.0254
local feet_to_inches = 12
local pound_to_kilograms = 0.45359237

--- Parse string as a height in meters.
--- according to http://wiki.openstreetmap.org/wiki/Key:maxheight
Expand All @@ -25,33 +26,19 @@ function Measure.parse_value_meters(value)
end
end

--- according to http://wiki.openstreetmap.org/wiki/Map_Features/Units#Explicit_specifications
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you say more about why you removed the patterns in favor of the hard coded version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's about implementing a more fail safe version and only extract partial value from the tag.

local tonns_parse_patterns = Sequence {
"%d+",
"%d+.%d+",
"%d+.%d+ ?t"
}

local kg_parse_patterns = Sequence {
"%d+ ?kg"
}

--- Parse weight value in kilograms
--- Parse weight value in kilograms.
--- according to https://wiki.openstreetmap.org/wiki/Key:maxweight
function Measure.parse_value_kilograms(value)
-- try to parse kilograms
for i, templ in ipairs(kg_parse_patterns) do
m = string.match(value, templ)
if m then
return tonumber(m)
end
end

-- try to parse tonns
for i, templ in ipairs(tonns_parse_patterns) do
m = string.match(value, templ)
if m then
return tonumber(m) * 1000
local n = tonumber(value:gsub(",", "."):match("%d+%.?%d*"))
if n then
if string.match(value, "lbs") then
n = n * pound_to_kilograms
elseif string.match(value, "kg") then
-- n = n
else -- Default, metric tons
n = n * 1000
end
return n
end
end

Expand Down Expand Up @@ -83,7 +70,14 @@ function Measure.get_max_width(raw_value)
end
end

--- Get maxweight of specified way in kilogramms
--- Get maxlength of specified way in meters.
function Measure.get_max_length(raw_value)
if raw_value then
return Measure.parse_value_meters(raw_value)
end
end

--- Get maxweight of specified way in kilogramms.
function Measure.get_max_weight(raw_value)
if raw_value then
return Measure.parse_value_kilograms(raw_value)
Expand Down
32 changes: 32 additions & 0 deletions profiles/lib/way_handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,38 @@ function WayHandlers.handle_width(profile,way,result,data)
end
end

-- handle maxweight tags
function WayHandlers.handle_weight(profile,way,result,data)
local keys = Sequence { 'maxweight' }
local forward, backward = Tags.get_forward_backward_by_set(way,data,keys)
forward = Measure.get_max_weight(forward)
backward = Measure.get_max_weight(backward)

if forward and forward < profile.vehicle_weight then
result.forward_mode = mode.inaccessible
end

if backward and backward < profile.vehicle_weight then
result.backward_mode = mode.inaccessible
end
end

-- handle maxlength tags
function WayHandlers.handle_length(profile,way,result,data)
local keys = Sequence { 'maxlength' }
local forward, backward = Tags.get_forward_backward_by_set(way,data,keys)
forward = Measure.get_max_length(forward)
backward = Measure.get_max_length(backward)

if forward and forward < profile.vehicle_length then
result.forward_mode = mode.inaccessible
end

if backward and backward < profile.vehicle_length then
result.backward_mode = mode.inaccessible
end
end

-- handle oneways tags
function WayHandlers.oneway(profile,way,result,data)
if not profile.oneway_handling then
Expand Down