Skip to content

Commit

Permalink
Add a weight for bicycle=discouraged tag in OSRM profile
Browse files Browse the repository at this point in the history
In general the OSM community do not encourage the use for this tag, but it can
be a good indication of dangerous bike routes. (We have a few street marked as such in Montreal)

This add a penalty to routing on those segments.

This was tested on De La Verandrye street, after setting the secondary default weight to 0.9
to have OSRM first route on it. After adding this code with the 0.9 weight, we see
that the road is avoided.
  • Loading branch information
greenscientist authored and kaligrafy committed Dec 17, 2024
1 parent 55783a8 commit 2c26659
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ function setup()
properties = {
u_turn_penalty = 20,
traffic_light_penalty = 15,
--weight_name = 'cyclability',
weight_name = 'routability',
-- Transition: we prefer cyclability as a baseline
weight_name = 'cyclability',
--weight_name = 'routability',
process_call_tagless_node = false,
max_speed_for_map_matching = 110/3.6, -- kmph -> m/s
use_turn_restrictions = false,
Expand Down Expand Up @@ -600,6 +601,14 @@ function safety_handler(profile,way,result,data)
backward_penalty = math.min(backward_penalty, profile.service_penalties[data.service])
end

-- Transition: Add penalty for bicycle=discouraged tag
-- See the link above about the discouraged tag
local bicycle_tag = way:get_value_by_key("bicycle")
if bicycle_tag == "discouraged" then
forward_penalty = forward_penalty * 0.5
backward_penalty = backward_penalty * 0.5
end

if result.forward_speed > 0 then
-- convert from km/h to m/s
result.forward_rate = result.forward_speed / 3.6 * forward_penalty
Expand Down

0 comments on commit 2c26659

Please sign in to comment.