forked from Project-OSRM/osrm-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseattle-wheelchair.lua
295 lines (260 loc) · 9.42 KB
/
seattle-wheelchair.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
-- Foot profile
local find_access_tag = require("lib/access").find_access_tag
-- Begin of globals
barrier_whitelist = { [""] = true, ["cycle_barrier"] = true, ["bollard"] = true, ["entrance"] = true, ["cattle_grid"] = true, ["border_control"] = true, ["toll_booth"] = true, ["sally_port"] = true, ["gate"] = true, ["no"] = true, ["block"] = true}
access_tag_whitelist = { ["yes"] = true, ["foot"] = true, ["permissive"] = true, ["designated"] = true }
access_tag_blacklist = { ["no"] = true, ["private"] = true, ["agricultural"] = true, ["forestry"] = true, ["delivery"] = true }
access_tag_restricted = { ["destination"] = true, ["delivery"] = true }
access_tags_hierarchy = { "foot", "access" }
service_tag_restricted = { ["parking_aisle"] = true }
ignore_in_grid = { ["ferry"] = true }
restriction_exception_tags = { "foot" }
walking_speed = 5
speeds = {
["primary"] = walking_speed,
["primary_link"] = walking_speed,
["secondary"] = walking_speed,
["secondary_link"] = walking_speed,
["tertiary"] = walking_speed,
["tertiary_link"] = walking_speed,
["unclassified"] = walking_speed,
["residential"] = walking_speed,
["road"] = walking_speed,
["living_street"] = walking_speed,
["service"] = walking_speed,
["track"] = walking_speed,
["path"] = walking_speed,
["steps"] = walking_speed,
["pedestrian"] = walking_speed,
["footway"] = walking_speed,
["pier"] = walking_speed,
["default"] = walking_speed
}
route_speeds = {
["ferry"] = 5
}
platform_speeds = {
["platform"] = walking_speed
}
amenity_speeds = {
["parking"] = walking_speed,
["parking_entrance"] = walking_speed
}
man_made_speeds = {
["pier"] = walking_speed
}
surface_speeds = {
["fine_gravel"] = walking_speed*0.75,
["gravel"] = walking_speed*0.75,
["pebblestone"] = walking_speed*0.75,
["mud"] = walking_speed*0.5,
["sand"] = walking_speed*0.5
}
leisure_speeds = {
["track"] = walking_speed
}
properties.traffic_signal_penalty = 2
properties.u_turn_penalty = 2
properties.use_turn_restrictions = false
properties.continue_straight_at_waypoint = false
local fallback_names = true
function get_exceptions(vector)
for i,v in ipairs(restriction_exception_tags) do
vector:Add(v)
end
end
--------------------------------------------------
-- Called once to load raster sources into memory.
--------------------------------------------------
function source_function ()
-- Define lat/lon min/max and data dimensions from environment variable reads
raster_source = sources:load(
"./seattle.asc",
-123,
-122,
47,
48,
10812,
10812)
end
--------------------------------------------------
-- Called per segment to update edge weights.
--------------------------------------------------
function segment_function (source, target, distance, weight)
-- TODO: blacklist elevators/elevator segments (shouldn't have elevation
-- cost).
local sourceData = sources:query(raster_source, source.lon, source.lat)
local targetData = sources:query(raster_source, target.lon, target.lat)
local elev_delta = targetData.datum - sourceData.datum
local penalize = 0
local costSlope = 0
slope = math.abs(elev_delta / distance)
-- TODO: bring back separate up/downhill profiles
if slope < 0.01 then
penalize = 0
elseif slope < 0.02 then
penalize = 0.5
elseif slope < 0.03 then
penalize = 0.1
elseif slope < 0.04 then
penalize = 1.5
elseif slope < 0.05 then
penalize = 0.2
elseif slope < 0.06 then
penalize = 0.6
elseif slope < 0.07 then
penalize = 0.8
elseif slope < 0.08 then
penalize = 0.9
end
local normalizeFactor = 2
penalize = (normalizeFactor + penalize) / (normalizeFactor + 1)
if slope >= 0.08 then
-- We want to say 'this is impassible', not 'this is difficult'
--
-- FIXME: We wanted to set weight.speed to 0, but that makes the
-- 'speed' output very non-zero (and fairly large).
-- FIXME: setting weight.speed to 0.00001 would cause the server to
-- become unresponsive when the origin/destination waypoints were
-- placed close together on a very steeps treet.
-- FIXME: Setting weight.speed to 0.0000001 results in an apparent
-- rounding error (rounds to 0), very annoying.
-- FIXME: Setting weight.speed to 0.0001 results in osrm-contract
-- stalling with the seattle_washingt.osm.pbf (mapzen city downloads)
weight.speed = 0.001
else
weight.speed = weight.speed * (1 - penalize)
end
end
function node_function (node, result)
local barrier = node:get_value_by_key("barrier")
local access = find_access_tag(node, access_tags_hierarchy)
local traffic_signal = node:get_value_by_key("highway")
-- flag node if it carries a traffic light
if traffic_signal and traffic_signal == "traffic_signals" then
result.traffic_lights = true
end
-- parse access and barrier tags
if access and access ~= "" then
if access_tag_blacklist[access] then
result.barrier = true
else
result.barrier = false
end
elseif barrier and barrier ~= "" then
if barrier_whitelist[barrier] then
result.barrier = false
else
result.barrier = true
end
end
return 1
end
function way_function (way, result)
-- initial routability check, filters out buildings, boundaries, etc
local highway = way:get_value_by_key("highway")
local leisure = way:get_value_by_key("leisure")
local route = way:get_value_by_key("route")
local man_made = way:get_value_by_key("man_made")
local railway = way:get_value_by_key("railway")
local amenity = way:get_value_by_key("amenity")
local public_transport = way:get_value_by_key("public_transport")
if (not highway or highway == '') and
(not leisure or leisure == '') and
(not route or route == '') and
(not railway or railway=='') and
(not amenity or amenity=='') and
(not man_made or man_made=='') and
(not public_transport or public_transport=='')
then
return
end
-- don't route on ways that are still under construction
if highway=='construction' then
return
end
-- access
local access = find_access_tag(way, access_tags_hierarchy)
if access_tag_blacklist[access] then
return
end
result.forward_mode = mode.walking
result.backward_mode = mode.walking
local name = way:get_value_by_key("name")
local ref = way:get_value_by_key("ref")
local junction = way:get_value_by_key("junction")
local onewayClass = way:get_value_by_key("oneway:foot")
local duration = way:get_value_by_key("duration")
local service = way:get_value_by_key("service")
local area = way:get_value_by_key("area")
local foot = way:get_value_by_key("foot")
local surface = way:get_value_by_key("surface")
-- name
if ref and "" ~= ref and name and "" ~= name then
result.name = name .. " (" .. ref .. ")"
elseif ref and "" ~= ref then
result.name = ref
elseif name and "" ~= name then
result.name = name
elseif highway and fallback_names then
result.name = "{highway:"..highway.."}" -- if no name exists, use way type
-- this encoding scheme is excepted to be a temporary solution
end
-- roundabouts
if "roundabout" == junction then
result.roundabout = true
end
-- speed
if route_speeds[route] then
-- ferries (doesn't cover routes tagged using relations)
result.ignore_in_grid = true
if duration and durationIsValid(duration) then
result.duration = math.max( 1, parseDuration(duration) )
else
result.forward_speed = route_speeds[route]
result.backward_speed = route_speeds[route]
end
result.forward_mode = mode.ferry
result.backward_mode = mode.ferry
elseif railway and platform_speeds[railway] then
-- railway platforms (old tagging scheme)
result.forward_speed = platform_speeds[railway]
result.backward_speed = platform_speeds[railway]
elseif platform_speeds[public_transport] then
-- public_transport platforms (new tagging platform)
result.forward_speed = platform_speeds[public_transport]
result.backward_speed = platform_speeds[public_transport]
elseif amenity and amenity_speeds[amenity] then
-- parking areas
result.forward_speed = amenity_speeds[amenity]
result.backward_speed = amenity_speeds[amenity]
elseif leisure and leisure_speeds[leisure] then
-- running tracks
result.forward_speed = leisure_speeds[leisure]
result.backward_speed = leisure_speeds[leisure]
elseif speeds[highway] then
-- regular ways
result.forward_speed = speeds[highway]
result.backward_speed = speeds[highway]
elseif access and access_tag_whitelist[access] then
-- unknown way, but valid access tag
result.forward_speed = walking_speed
result.backward_speed = walking_speed
end
-- oneway
if onewayClass == "yes" or onewayClass == "1" or onewayClass == "true" then
result.backward_mode = mode.inaccessible
elseif onewayClass == "no" or onewayClass == "0" or onewayClass == "false" then
-- nothing to do
elseif onewayClass == "-1" then
result.forward_mode = mode.inaccessible
end
-- surfaces
if surface then
surface_speed = surface_speeds[surface]
if surface_speed then
result.forward_speed = math.min(result.forward_speed, surface_speed)
result.backward_speed = math.min(result.backward_speed, surface_speed)
end
end
end