Skip to content

Commit

Permalink
Support maxlength and maxweight in car profile
Browse files Browse the repository at this point in the history
  • Loading branch information
frodrigo committed Jun 6, 2018
1 parent 3da15a6 commit 4626ad4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
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 = 3.5, -- 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
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

0 comments on commit 4626ad4

Please sign in to comment.