Skip to content

Commit c3a4070

Browse files
committed
Add OSRM server to repo
1 parent 2ef7d8a commit c3a4070

File tree

9 files changed

+191
-0
lines changed

9 files changed

+191
-0
lines changed

osrm/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.osrm*
2+
*.pbf

osrm/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM ghcr.io/project-osrm/osrm-backend:v5.27.1
2+
3+
RUN apt-get update && apt-get upgrade -y
4+
RUN apt-get install wget make osmium-tool docker -y
5+
6+
WORKDIR /opt/host
7+
8+
COPY . /opt/host
9+
RUN make all
10+
11+
EXPOSE 5000
12+
13+
CMD ["make", "serve"]

osrm/Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.PRECIOUS: %.pbf
2+
3+
# List all the source countries we need
4+
WANTED_COUNTRIES := $(shell grep -v "\#" countries.wanted)
5+
6+
# Transform "belgium" to "world/belgium-latest.osm.pbf"
7+
COUNTRIES_PBF := $(addsuffix -latest.osm.pbf,$(addprefix world/,$(WANTED_COUNTRIES)))
8+
9+
# Download the raw source file of a country
10+
world/%.osm.pbf:
11+
wget -N -nv -P world/ https://download.geofabrik.de/europe/$*.osm.pbf
12+
13+
# Filter a raw country (in world/*) to rail-only data (in filtered/*)
14+
filtered/%.osm.pbf: world/%.osm.pbf filter.params
15+
osmium tags-filter --expressions=filter.params $< -o $@ --overwrite
16+
17+
# Combine all rail-only data (in filtered/*) into one file
18+
output/filtered.osm.pbf: $(subst world,filtered,$(COUNTRIES_PBF))
19+
osmium merge $^ -o $@ --overwrite
20+
21+
# Compute the real OSRM data on the combined file
22+
output/filtered.osrm: output/filtered.osm.pbf basic.lua
23+
osrm-extract -p /opt/host/basic.lua /opt/host/$<
24+
25+
osrm-partition /opt/host/$<
26+
osrm-customize /opt/host/$<
27+
28+
all: output/filtered.osrm
29+
30+
serve: output/filtered.osrm basic.lua
31+
osrm-routed --algorithm mld /opt/host/$<

osrm/basic.lua

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
-- Copyright 2017-2019 Railnova SA <[email protected]>, Nikita Marchant <[email protected]>
2+
-- Code under the 2-clause BSD license
3+
4+
api_version = 4
5+
6+
function setup()
7+
return {
8+
properties = {
9+
max_speed_for_map_matching = 400/3.6, -- speed conversion to m/s
10+
weight_name = 'train',
11+
left_hand_driving = false,
12+
u_turn_penalty = 60 * 2, -- 2 minutes to change cabin
13+
-- turn_duration = 20,
14+
continue_straight_at_waypoint = false,
15+
max_angle = 30,
16+
17+
secondary_speed = 20,
18+
speed = 100,
19+
},
20+
21+
default_mode = mode.train,
22+
default_speed = 100,
23+
}
24+
25+
end
26+
27+
28+
function ternary ( cond , T , F )
29+
if cond then return T else return F end
30+
end
31+
32+
33+
function process_node(profile, node, result, relations)
34+
local railway = node:get_value_by_key("railway")
35+
36+
-- refuse railway nodes that we cannot go through
37+
result.barrier = (
38+
railway == "buffer_stop" or
39+
railway == "derail"
40+
)
41+
result.traffic_lights = false
42+
end
43+
44+
function process_way(profile, way, result, relations)
45+
local data = {
46+
railway = way:get_value_by_key("railway"),
47+
service = way:get_value_by_key("service"),
48+
usage = way:get_value_by_key("usage"),
49+
maxspeed = way:get_value_by_key("maxspeed"),
50+
gauge = way:get_value_by_key("gauge"),
51+
}
52+
53+
-- Remove everything that is not railway
54+
if not data.railway then
55+
return
56+
-- Remove everything that is not a rail, a turntable, a traverser
57+
elseif (
58+
data.railway ~= 'rail' and
59+
data.railway ~= 'turntable' and
60+
data.railway ~= 'traverser' and
61+
data.railway ~= 'ferry'
62+
) then
63+
return
64+
-- Remove military and tourism rails
65+
elseif (
66+
data.usage == "military" or
67+
data.usage == "tourism"
68+
) then
69+
return
70+
-- Keep only most common gauges (and undefined)
71+
-- uses .find() as some gauges are specified like "1668;1435"
72+
elseif (
73+
data.gauge ~= nil and
74+
data.gauge ~= 1000 and not string.find(data.gauge, "1000") and
75+
data.gauge ~= 1435 and not string.find(data.gauge, "1435") and
76+
data.gauge ~= 1520 and not string.find(data.gauge, "1520") and
77+
data.gauge ~= 1524 and not string.find(data.gauge, "1524") and
78+
data.gauge ~= 1600 and not string.find(data.gauge, "1600") and
79+
data.gauge ~= 1668 and not string.find(data.gauge, "1668")
80+
) then
81+
return
82+
end
83+
84+
local is_secondary = (
85+
data.service == "siding" or
86+
data.service == "spur" or
87+
data.service == "yard" or
88+
data.usage == "industrial"
89+
)
90+
91+
-- by default, use 20km/h for secondary rails, else 140
92+
local default_speed = ternary(is_secondary, profile.properties.secondary_speed, profile.properties.speed)
93+
-- but if OSM specifies a maxspeed, use the one from OSM
94+
local speed = default_speed
95+
if (not data.maxspeed and not data.maxspeed == '' and tonumber(data.maxspeed) < default_speed) then
96+
speed = data.maxspeed
97+
end
98+
99+
100+
-- fix speed for mph issue
101+
speed = tostring(speed)
102+
if speed:find(" mph") or speed:find("mph") then
103+
speed = speed:gsub(" mph", "")
104+
speed = speed:gsub("mph", "")
105+
speed = tonumber (speed)
106+
if speed == nil then speed = 20 end
107+
speed = speed * 1.609344
108+
else
109+
speed = tonumber (speed)
110+
end
111+
-- fix speed for mph issue end
112+
113+
114+
result.forward_speed = speed
115+
result.backward_speed = speed
116+
--
117+
result.forward_mode = mode.train
118+
result.backward_mode = mode.train
119+
--
120+
result.forward_rate = 1
121+
result.backward_rate = 1
122+
123+
end
124+
125+
function process_turn(profile, turn)
126+
-- Refuse turns that have a big angle
127+
local angle = math.abs(turn.angle)
128+
if angle > profile.properties.max_angle then
129+
turn.duration = turn.duration + (angle - profile.properties.max_angle) * 3
130+
end
131+
132+
-- If we go backwards, add the penalty to change cabs
133+
if turn.is_u_turn then
134+
turn.duration = turn.duration + profile.properties.u_turn_penalty
135+
end
136+
end
137+
138+
return {
139+
setup = setup,
140+
process_way = process_way,
141+
process_node = process_node,
142+
process_turn = process_turn
143+
}

osrm/countries.wanted

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
poland

osrm/filter.params

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nw/railway

osrm/filtered/.keep

Whitespace-only changes.

osrm/output/.keep

Whitespace-only changes.

osrm/world/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)