prefer ways that a part of route=bicycle relation

This commit is contained in:
Michal Palenik 2018-05-31 21:54:53 +02:00
parent 454ffc2686
commit 0832afe929

View File

@ -5,6 +5,7 @@ api_version = 4
Set = require('lib/set') Set = require('lib/set')
Sequence = require('lib/sequence') Sequence = require('lib/sequence')
Handlers = require("lib/way_handlers") Handlers = require("lib/way_handlers")
Relations = require("lib/relations")
find_access_tag = require("lib/access").find_access_tag find_access_tag = require("lib/access").find_access_tag
limit = require("lib/maxspeed").limit limit = require("lib/maxspeed").limit
@ -32,6 +33,7 @@ function setup()
turn_penalty = 6, turn_penalty = 6,
turn_bias = 1.4, turn_bias = 1.4,
use_public_transport = true, use_public_transport = true,
route_preference = 1.1,
allowed_start_modes = Set { allowed_start_modes = Set {
mode.cycling, mode.cycling,
@ -212,7 +214,9 @@ function setup()
avoid = Set { avoid = Set {
'impassable', 'impassable',
'construction' 'construction'
} },
relation_types = Sequence { 'route' },
} }
end end
@ -464,6 +468,16 @@ function cycleway_handler(profile,way,result,data)
end end
end end
function bicycle_relation_handler(profile,way,result,data,relations)
-- prefer ways on route=bicycle by factor of profile.route_preference
if result.forward_rate and Relations.filter_relations(relations, way, "route", "bicycle", "route", "forward") == "bicycle" then
result.forward_rate = result.forward_rate * profile.route_preference
end
if result.backward_rate and Relations.filter_relations(relations, way, "route", "bicycle", "route", "backward") == "bicycle" then
result.backward_rate = result.backward_rate * profile.route_preference
end
end
function bike_push_handler(profile,way,result,data) function bike_push_handler(profile,way,result,data)
-- pushing bikes - if no other mode found -- pushing bikes - if no other mode found
if result.forward_mode == mode.inaccessible or result.backward_mode == mode.inaccessible or if result.forward_mode == mode.inaccessible or result.backward_mode == mode.inaccessible or
@ -580,7 +594,7 @@ end
function process_way(profile, way, result) function process_way(profile, way, result, relations)
-- the initial filtering of ways based on presence of tags -- the initial filtering of ways based on presence of tags
-- affects processing times significantly, because all ways -- affects processing times significantly, because all ways
-- have to be checked. -- have to be checked.
@ -648,6 +662,9 @@ function process_way(profile, way, result)
-- compute speed taking into account way type, maxspeed tags, etc. -- compute speed taking into account way type, maxspeed tags, etc.
WayHandlers.surface, WayHandlers.surface,
-- handle preference of bicyle route relations
bicycle_relation_handler,
-- handle turn lanes and road classification, used for guidance -- handle turn lanes and road classification, used for guidance
WayHandlers.classification, WayHandlers.classification,
@ -667,7 +684,7 @@ function process_way(profile, way, result)
WayHandlers.weights WayHandlers.weights
} }
WayHandlers.run(profile, way, result, data, handlers) WayHandlers.run(profile, way, result, data, handlers, relations)
end end
function process_turn(profile, turn) function process_turn(profile, turn)