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')
Sequence = require('lib/sequence')
Handlers = require("lib/way_handlers")
Relations = require("lib/relations")
find_access_tag = require("lib/access").find_access_tag
limit = require("lib/maxspeed").limit
@ -32,6 +33,7 @@ function setup()
turn_penalty = 6,
turn_bias = 1.4,
use_public_transport = true,
route_preference = 1.1,
allowed_start_modes = Set {
mode.cycling,
@ -212,7 +214,9 @@ function setup()
avoid = Set {
'impassable',
'construction'
}
},
relation_types = Sequence { 'route' },
}
end
@ -464,6 +468,16 @@ function cycleway_handler(profile,way,result,data)
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)
-- pushing bikes - if no other mode found
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
-- affects processing times significantly, because all ways
-- have to be checked.
@ -648,6 +662,9 @@ function process_way(profile, way, result)
-- compute speed taking into account way type, maxspeed tags, etc.
WayHandlers.surface,
-- handle preference of bicyle route relations
bicycle_relation_handler,
-- handle turn lanes and road classification, used for guidance
WayHandlers.classification,
@ -667,7 +684,7 @@ function process_way(profile, way, result)
WayHandlers.weights
}
WayHandlers.run(profile, way, result, data, handlers)
WayHandlers.run(profile, way, result, data, handlers, relations)
end
function process_turn(profile, turn)