Skip to content

Commit becfd8a

Browse files
authored
Add optional support of cargo bike exclusion and width to bicyle profile (#7044)
1 parent 4f1c62a commit becfd8a

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
- ADDED: Extract prerelease/build information from package semver [#6839](https://github.com/Project-OSRM/osrm-backend/pull/6839)
8080
- Profiles:
8181
- FIXED: Bicycle and foot profiles now don't route on proposed ways [#6615](https://github.com/Project-OSRM/osrm-backend/pull/6615)
82+
- ADDED: Add optional support of cargo bike exclusion and width to bicyle profile [#7044](https://github.com/Project-OSRM/osrm-backend/pull/7044)
8283
- Routing:
8384
- FIXED: Fix adding traffic signal penalties during compression [#6419](https://github.com/Project-OSRM/osrm-backend/pull/6419)
8485
- FIXED: Correctly handle compressed traffic signals. [#6724](https://github.com/Project-OSRM/osrm-backend/pull/6724)

profiles/bicycle.lua

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ function setup()
3535
turn_bias = 1.4,
3636
use_public_transport = true,
3737

38+
-- Exclude narrow ways, in particular to route with cargo bike
39+
width = nil, -- Cargo bike could 0.5 width, in meters
40+
exclude_cargo_bike = false,
41+
3842
allowed_start_modes = Set {
3943
mode.cycling,
4044
mode.pushing_bike
@@ -243,6 +247,27 @@ function process_node(profile, node, result)
243247
end
244248
end
245249

250+
if profile.exclude_cargo_bike then
251+
local cargo_bike = node:get_value_by_key("cargo_bike")
252+
if cargo_bike and cargo_bike == "no" then
253+
result.barrier = true
254+
end
255+
end
256+
257+
-- width
258+
if profile.width then
259+
-- From barrier=cycle_barrier or other barriers
260+
local maxwidth_physical = node:get_value_by_key("maxwidth:physical")
261+
local maxwidth_physical_meter = maxwidth_physical and Measure.parse_value_meters(maxwidth_physical) or 99
262+
local opening = node:get_value_by_key("opening")
263+
local opening_meter = opening and Measure.parse_value_meters(opening) or 99
264+
local width_meter = math.min(maxwidth_physical_meter, opening_meter)
265+
266+
if width_meter and width_meter < profile.width then
267+
result.barrier = true
268+
end
269+
end
270+
246271
-- check if node is a traffic light
247272
result.traffic_lights = TrafficSignal.get_value(node)
248273
end
@@ -299,6 +324,8 @@ function handle_bicycle_tags(profile,way,result,data)
299324

300325
bike_push_handler(profile,way,result,data)
301326

327+
-- width should be after bike_push
328+
width_handler(profile,way,result,data)
302329

303330
-- maxspeed
304331
limit( result, data.maxspeed, data.maxspeed_forward, data.maxspeed_backward )
@@ -453,6 +480,27 @@ function cycleway_handler(profile,way,result,data)
453480
end
454481
end
455482

483+
function width_handler(profile,way,result,data)
484+
if profile.exclude_cargo_bike then
485+
local cargo_bike = way:get_value_by_key("cargo_bike")
486+
if cargo_bike and cargo_bike == "no" then
487+
result.forward_mode = mode.inaccessible
488+
result.backward_mode = mode.inaccessible
489+
end
490+
end
491+
492+
if profile.width then
493+
local width = way:get_value_by_key("width")
494+
if width then
495+
local width_meter = Measure.parse_value_meters(width)
496+
if width_meter and width_meter < profile.width then
497+
result.forward_mode = mode.inaccessible
498+
result.backward_mode = mode.inaccessible
499+
end
500+
end
501+
end
502+
end
503+
456504
function bike_push_handler(profile,way,result,data)
457505
-- pushing bikes - if no other mode found
458506
if result.forward_mode == mode.inaccessible or result.backward_mode == mode.inaccessible or

0 commit comments

Comments
 (0)