OpenSourceRoutingMachine.jl is a Julia wrapper for OSRM, a high-performance routing engine for road networks built on OpenStreetMap data.
Features
- Graph — Build routing graphs from OpenStreetMap
.pbffiles (MLD or Contraction Hierarchies) with built-in car, bicycle, and foot profiles - Route — Shortest path with full geometry, turn-by-turn instructions, and per-edge annotations
- Table — Distance/duration matrices between many-to-many points
- Nearest — Snap coordinates to the nearest road network point
- Match — Map-match noisy GPS traces to the road network
- Trip — Solve the Traveling Salesman Problem over road networks
- Tile — Retrieve road network geometry as vector tiles (MVT)
All query responses are returned as native Julia structs via FlatBuffers deserialization.
Installation
using Pkg
Pkg.add("OpenSourceRoutingMachine")
Example:
This example downloads an OpenStreetMap extract of Hamburg, builds a routing graph, computes a route from Hamburg Rathaus to the airport, and plots it on a map.
using Downloads
using OpenSourceRoutingMachine
using OpenSourceRoutingMachine.Graph
using OpenSourceRoutingMachine.Route
# 1. Download Hamburg OSM extract (~30 MB)
const OSM_FILE = joinpath(@__DIR__, "hamburg-latest.osm.pbf")
if !isfile(OSM_FILE)
Downloads.download(
"https://download.geofabrik.de/europe/germany/hamburg-latest.osm.pbf",
OSM_FILE,
)
end
# 2. Build an MLD routing graph (car profile)
const OSRM_BASE = joinpath(@__DIR__, "hamburg-latest.osrm")
extract(OSM_FILE; profile = PROFILE_CAR)
partition(OSRM_BASE)
customize(OSRM_BASE)
# 3. Create OSRM instance
osrm = OSRM(OSRM_BASE)
# 4. Route: Hamburg Rathaus → Hamburg Airport Terminal 1
params = RouteParams()
set_geometries!(params, GEOMETRIES_GEOJSON)
set_overview!(params, OVERVIEW_FULL)
add_coordinate!(params, Position(9.9937, 53.5511)) # Rathaus
add_coordinate!(params, Position(10.0055, 53.6303)) # Airport
response = route(osrm, params)
r = response.routes[1]
println("Distance: $(round(r.distance / 1000; digits = 1)) km")
println("Duration: $(round(r.duration / 60; digits = 1)) min")
# 5. Plot the route on an OpenStreetMap background
using CairoMakie
using Tyler
using Tyler.MapTiles
using Tyler.TileProviders
# Extract route coordinates and project to Web Mercator
lons = [c.longitude for c in r.coordinates]
lats = [c.latitude for c in r.coordinates]
to_webmerc(lon, lat) = Point2f(MapTiles.project((lon, lat), MapTiles.wgs84, MapTiles.web_mercator))
points = [to_webmerc(lon, lat) for (lon, lat) in zip(lons, lats)]
# Map extent with padding
pad = 0.02
extent = Rect2f(
minimum(lons) - pad, minimum(lats) - pad,
maximum(lons) - minimum(lons) + 2pad,
maximum(lats) - minimum(lats) + 2pad,
)
m = Tyler.Map(extent; provider = TileProviders.OpenStreetMap(:Mapnik))
wait(m)
# Draw route and markers
lines!(m.axis, points; color = :dodgerblue, linewidth = 4)
scatter!(
m.axis, [points[1], points[end]];
color = [:green, :red], markersize = 16,
)
display(m.figure)
The output:
