forked from fossgis-routing-server/cbf-routing-profiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
foot.lua
340 lines (281 loc) · 8.93 KB
/
foot.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
-- Foot profile
api_version = 4
Set = require('lib/set')
Sequence = require('lib/sequence')
Handlers = require("lib/way_handlers_weight")
find_access_tag = require("lib/access").find_access_tag
local Tags = require('lib/tags')
function setup()
return {
properties = {
weight_name = 'routability',
weight_precision = 2,
max_speed_for_map_matching = 40/3.6, -- kmph -> m/s
call_tagless_node_function = false,
traffic_light_penalty = 2,
u_turn_penalty = 2,
continue_straight_at_waypoint = false,
use_turn_restrictions = false,
},
default_mode = mode.walking,
default_speed = 4.5,
default_weight = 1,
designated_weight = 1.2,
oneway_handling = 'specific', -- respect 'oneway:foot' but not 'oneway'
traffic_light_penalty = 2,
u_turn_penalty = 2,
barrier_whitelist = Set {
'kerb',
'block',
'bollard',
'border_control',
'cattle_grid',
'entrance',
'sally_port',
'toll_booth',
'cycle_barrier',
'gate',
'no',
'stile',
'bock',
'kissing_gate',
'turnstile',
'hampshire_gate'
},
access_tag_whitelist = Set {
'yes',
'foot',
'permissive',
'designated'
},
access_tag_blacklist = Set {
'no',
'agricultural',
'forestry',
'emergency',
'customers',
'private',
'delivery',
'destination'
},
restricted_access_tag_list = Set {
'private',
'delivery',
'destination',
'customers',
},
restricted_highway_whitelist = Set { },
construction_whitelist = Set {},
access_tags_hierarchy = Sequence {
'foot',
'access'
},
-- tags disallow access to in combination with highway=service
service_access_tag_blacklist = Set { },
restrictions = Sequence {
'foot'
},
-- list of suffixes to suppress in name change instructions
suffix_list = Set {
'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'North', 'South', 'West', 'East'
},
avoid = Set {
'impassable',
'proposed'
},
speeds = Sequence {
highway = {
footway = {1.2, 4.5},
cycleway = {1.0, 4.5},
primary = {0.7, 4.5},
primary_link = {0.7, 4.5},
secondary = {0.8, 4.5},
secondary_link = {0.8, 4.5},
tertiary = {0.9, 4.5},
tertiary_link = {0.9, 4.5},
unclassified = {1.0, 4.5},
residential = {1.0, 4.5},
road = {1.0, 4.5},
living_street = {1.1, 4.5},
service = {1.0, 4.5},
path = {1.2, 4.5},
track = {1.1, 4.5},
steps = {1.1, 4.5},
pedestrian = {1.2, 4.5},
pier = {1.0, 4.5},
},
railway = {
platform = {1.0, 4.5},
},
amenity = {
parking = {1.0, 4.5},
parking_entrance= {1.0, 4.5}
},
man_made = {
pier = {1.0, 4.5}
},
leisure = {
track = {1.0, 4.5}
}
},
route_weights = {
ferry = {0.3, nil}
},
bridge_speeds = {
},
surface_speeds= {
["fine_gravel"] = {0.8, 4.5},
["gravel"] = {0.7, 3.5},
["pebblestone"] = {0.7, 3.5},
["mud"] = {0.5, 3.5},
["ground"] = {0.8, 4.5},
["unpaved"] = {0.8, 4.5},
["grass"] = {0.5, 3.5},
["dirt"] = {0.5, 3.5},
["compacted"] = {0.9, 4.5},
["grit"] = {0.8, 4.5},
["sand"] = {0.6, 4.5}
},
tracktype_speeds = {
grade1 = {1.1, 4.5},
grade2 = {1.1, 4.5},
grade3 = {1.0, 3.5},
grade4 = {0.9, 3.5},
grade5 = {0.9, 3.5}
},
smoothness_speeds = {
},
speed_path = {
sac_scale = { hiking = {0.5, 3.5},
mountain_hiking = {0,0},
demanding_mountain_hiking = {0,0},
alpine_hiking = {0,0},
demanding_alpine_hiking = {0,0},
difficult_alpine_hiking = {0,0}
},
bicycle = { designated = {0.5, 4.5}, yes = {0.9, 4.5} }
}
}
end
function process_node (profile, node, result)
-- parse access and barrier tags
local access = find_access_tag(node, profile.access_tags_hierarchy)
if access then
if profile.access_tag_blacklist[access] and not profile.restricted_access_tag_list[access] then
result.barrier = true
end
else
local barrier = node:get_value_by_key("barrier")
if barrier then
-- make an exception for rising bollard barriers
local bollard = node:get_value_by_key("bollard")
local rising_bollard = bollard and "rising" == bollard
if not profile.barrier_whitelist[barrier] and not rising_bollard then
result.barrier = true
end
end
end
-- check if node is a traffic light
local tag = node:get_value_by_key("highway")
if "traffic_signals" == tag then
result.traffic_lights = true
end
end
-- main entry point for processsing a way
function process_way(profile, way, result)
-- the intial filtering of ways based on presence of tags
-- affects processing times significantly, because all ways
-- have to be checked.
-- to increase performance, prefetching and intial tag check
-- is done in directly instead of via a handler.
-- in general we should try to abort as soon as
-- possible if the way is not routable, to avoid doing
-- unnecessary work. this implies we should check things that
-- commonly forbids access early, and handle edge cases later.
-- data table for storing intermediate values during processing
local data = {
-- prefetch tags
highway = way:get_value_by_key('highway'),
bridge = way:get_value_by_key('bridge'),
route = way:get_value_by_key('route'),
leisure = way:get_value_by_key('leisure'),
man_made = way:get_value_by_key('man_made'),
railway = way:get_value_by_key('railway'),
platform = way:get_value_by_key('platform'),
amenity = way:get_value_by_key('amenity'),
public_transport = way:get_value_by_key('public_transport')
}
-- perform an quick initial check and abort if the way is
-- obviously not routable. here we require at least one
-- of the prefetched tags to be present, ie. the data table
-- cannot be empty
if next(data) == nil then -- is the data table empty?
return
end
local handlers = Sequence {
-- set the default mode for this profile. if can be changed later
-- in case it turns we're e.g. on a ferry
WayHandlers.default_mode,
-- check various tags that could indicate that the way is not
-- routable. this includes things like status=impassable,
-- toll=yes and oneway=reversible
WayHandlers.blocked_ways,
-- determine access status by checking our hierarchy of
-- access tags, e.g: motorcar, motor_vehicle, vehicle
WayHandlers.access,
-- check whether forward/backward directons are routable
WayHandlers.oneway,
-- check whether forward/backward directons are routable
WayHandlers.destinations,
-- check whether we're using a special transport mode
WayHandlers.ferries,
WayHandlers.movables,
-- compute speed taking into account way type, maxspeed tags, etc.
WayHandlers.speed,
WayHandlers.surface,
-- set speed for path
WayHandlers.adjust_speed_for_path,
-- handle turn lanes and road classification, used for guidance
WayHandlers.classification,
-- handle various other flags
WayHandlers.roundabouts,
WayHandlers.startpoint,
-- set name, ref and pronunciation
WayHandlers.names,
}
WayHandlers.run(profile, way, result, data, handlers)
if result.forward_rate > 0 then
result.forward_rate = result.forward_rate * 10
end
if result.backward_rate > 0 then
result.backward_rate = result.backward_rate * 10
end
if result.forward_rate == -1 and result.forward_speed > 0 then
result.forward_rate = result.forward_speed / 3.6;
end
if result.backward_rate == -1 and result.backward_speed > 0 then
result.backward_rate = result.backward_speed / 3.6;
end
end
function process_turn(profile, turn)
turn.duration = 0.
if turn.is_u_turn then
turn.duration = turn.duration + profile.properties.u_turn_penalty
end
if turn.has_traffic_light then
turn.duration = turn.duration + profile.properties.traffic_light_penalty
end
if profile.properties.weight_name == 'cyclability' then
turn.weight = turn.duration
end
-- penalize turns from non-local access only segments onto local access only tags
if not turn.source_restricted and turn.target_restricted then
turn.weight = turn.weight + 3000
end
end
return {
setup = setup,
process_way = process_way,
process_node = process_node,
process_turn = process_turn
}