Skip to content

Commit

Permalink
restore cargo bike exclusion pull/7044
Browse files Browse the repository at this point in the history
  • Loading branch information
tombay committed Oct 6, 2024
1 parent 041bb2b commit 6c7fb2a
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions profiles/bicycle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function setup()
turn_bias = 1.4,
use_public_transport = true,

-- Exclude narrow ways, in particular to route with cargo bike
width = nil, -- Cargo bike could 0.5 width, in meters
exclude_cargo_bike = false,

allowed_start_modes = Set {
mode.cycling,
mode.pushing_bike
Expand Down Expand Up @@ -230,7 +234,6 @@ function setup()
uselocationtags = Set {
-- 'trunk'
}

}
end

Expand All @@ -255,6 +258,27 @@ function process_node(profile, node, result)
end
end

if profile.exclude_cargo_bike then
local cargo_bike = node:get_value_by_key("cargo_bike")
if cargo_bike and cargo_bike == "no" then
result.barrier = true
end
end

-- width
if profile.width then
-- From barrier=cycle_barrier or other barriers
local maxwidth_physical = node:get_value_by_key("maxwidth:physical")
local maxwidth_physical_meter = maxwidth_physical and Measure.parse_value_meters(maxwidth_physical) or 99
local opening = node:get_value_by_key("opening")
local opening_meter = opening and Measure.parse_value_meters(opening) or 99
local width_meter = math.min(maxwidth_physical_meter, opening_meter)

if width_meter and width_meter < profile.width then
result.barrier = true
end
end

-- check if node is a traffic light
result.traffic_lights = TrafficSignal.get_value(node)
end
Expand Down Expand Up @@ -311,6 +335,8 @@ function handle_bicycle_tags(profile,way,result,data)

bike_push_handler(profile,way,result,data)

-- width should be after bike_push
width_handler(profile,way,result,data)

-- maxspeed
limit( result, data.maxspeed, data.maxspeed_forward, data.maxspeed_backward )
Expand Down Expand Up @@ -376,10 +402,10 @@ function speed_handler(profile,way,result,data)
data.way_type_allows_pushing = true
elseif profile.bicycle_speeds[data.highway] then
-- regular ways
-- check trunk
result.forward_speed = profile.bicycle_speeds[data.highway]
result.backward_speed = profile.bicycle_speeds[data.highway]
data.way_type_allows_pushing = true
-- check trunk
elseif profile.trunk_speeds[data.highway] and profile.uselocationtags and profile.uselocationtags.trunk then
if not way:get_location_tag(data.highway) or way:get_location_tag(data.highway) ~= "no" then
result.forward_speed = profile.trunk_speeds[data.highway]
Expand Down Expand Up @@ -472,6 +498,27 @@ function cycleway_handler(profile,way,result,data)
end
end

function width_handler(profile,way,result,data)
if profile.exclude_cargo_bike then
local cargo_bike = way:get_value_by_key("cargo_bike")
if cargo_bike and cargo_bike == "no" then
result.forward_mode = mode.inaccessible
result.backward_mode = mode.inaccessible
end
end

if profile.width then
local width = way:get_value_by_key("width")
if width then
local width_meter = Measure.parse_value_meters(width)
if width_meter and width_meter < profile.width then
result.forward_mode = mode.inaccessible
result.backward_mode = mode.inaccessible
end
end
end
end

function bike_push_handler(profile,way,result,data)
-- pushing bikes - if no other mode found
if result.forward_mode == mode.inaccessible or result.backward_mode == mode.inaccessible or
Expand Down

0 comments on commit 6c7fb2a

Please sign in to comment.