routing-builder (orix-routing-build)
Build-time tool (macOS only, never linked into the app): turns an OpenStreetMap .osm.pbf extract into one routing
graph file (routing.orixgraph) for Packages/ORIXRouting, and lets a person check routes from the command line.
ORIXRoutingBuildKit(library):TagInterpreter(OSM tags → routing attributes),GraphExtractor(PBF → graph),BenchmarkPlaces(fixed origin–destination list).orix-routing-build(executable):build,info,route,bench.- Depends on
Packages/ORIXRouting(format writer and engine),Packages/ORIXGeoCore,Infrastructure/ingestion/ORIXOSM(the PBF reader). No third-party code.
The file format is specified in Packages/ORIXRouting/docs/ORIXGRAPH_FORMAT.md; this package does not write bytes
itself, it feeds RoutingGraphWriter.
Commands
cd Infrastructure/routing-builder
swift build -c release
B=.build/release/orix-routing-build
D=../../data
# Build a graph (output under data/build/ only).
$B --pbf $D/quebec-latest.osm.pbf --region ca-qc --out $D/build/routing/quebec.orixgraph \
[--bbox minLon,minLat,maxLon,maxLat] [--simplify 0.5] [--report $D/build/routing/quebec.report.json]
# Metadata, counts, component sizes, builder counters; also times the full validation.
$B info --graph $D/build/routing/quebec.orixgraph
# One route with its instructions (English or French), for checking by hand.
$B route --graph $D/build/routing/quebec.orixgraph --from 45.5048,-73.5772 --to 46.8087,-71.2140 \
[--via lat,lon]… [--mode car|bicycle|pedestrian] [--avoid tolls,ferries,motorways,unpaved] [--alternatives 0…2] \
[--lang en|fr] [--units metric|imperial] [--heading degrees] [--snap metres] [--dijkstra] \
[--geojson $D/build/routing/route.geojson] [--json $D/build/routing/route.json]
# Fixed list of origin–destination pairs per mode: distance, duration, compute time (median and best of n), settled
# states, search memory; --verify recomputes each pair with Dijkstra and exits with status 3 on any cost difference.
$B bench --graph $D/build/routing/montreal.orixgraph --set montreal [--modes car,bicycle,pedestrian] [--verify] [--repeat 5]
$B bench --graph $D/build/routing/quebec.orixgraph --set province --verify --repeat 5Example (route --lang fr, Plateau → Marché Jean-Talon by car, Montréal graph):
route: 4,1 km (4.1 km), 11 min, cost 635 s, 126 points
1. Dirigez-vous vers le sud-ouest sur l'avenue du Mont-Royal Est [20 m]
2. Tournez à droite sur la rue Rivard [450 m]
3. Tournez à gauche sur le boulevard Saint-Joseph Est [600 m]
4. Tournez à droite sur le boulevard Saint-Laurent [2,5 km]
5. Tournez à droite sur la rue Jean-Talon Est [350 m]
6. Tournez à droite sur l'avenue Henri-Julien [150 m]
7. Tournez à droite [10 m]
8. Vous êtes arrivé à destination, à votre droiteHow the graph is built
Two passes over the PBF with OSMPBFReader:
- Ways and relations. Routable ways are kept with their node references;
type=restrictionrelations are parsed. - Nodes. Only the nodes referenced by routable ways are kept (coordinates in E7, barrier and signal tags): in the province 9.7 M of 139 M nodes. Node ids are mapped to dense indices through one sorted array (merge join with the file order), not a dictionary.
Then: a node becomes a graph node when it is used by two ways (or twice by one), ends a way, carries a barrier
that blocks some mode, or is the via node of a restriction; ways are cut into edges at graph nodes; a loop that
returns to its own start is cut in two (no edge has the same node at both ends); intermediate points are simplified
(Douglas–Peucker, 0.5 m by default, --simplify 0 keeps every point); restrictions are attached to the edges of
their from / to ways at the via node; the writer computes lengths, bearings, components, the spatial index and
renumbers everything along a Morton curve.
With --bbox, only segments whose two ends are inside the box are kept and the box becomes the coverage of the graph.
Without it the coverage is the bounding box of the PBF header, or the extent of the data when the header has none.
Tag rules (TagInterpreter, unit-tested)
- Routable:
highway= motorway, trunk, primary, secondary, tertiary (and_link), unclassified, residential, living_street, service, track, pedestrian, footway, path, bridleway, cycleway, steps, road; androute=ferry. Everything else is dropped, includingconstruction,proposed,platform,corridor,bus_guideway,raceway, and any way taggedice_road=yesorwinter_road=yes. - Default access: motorway = cars only (also with
motorroad=yes); footway and steps = pedestrians; path = pedestrians and bicycles (bridleway: pedestrians); cycleway and pedestrian streets = bicycles and pedestrians; other roads, tracks and ferries = everybody. - Access tags, most specific first: car
motorcar>motor_vehicle>vehicle>access; bicyclebicycle>vehicle>access; pedestrianfoot>access.no-like values close;private,destination,customers,delivery,permit,residentskeep the way routable with the restricted flag of the mode;agricultural,forestry,psv… close it to cars. A genericaccess=yesnever opens a class to a mode it excludes by nature, andvehicle=yesnever lets a car on foot or cycle infrastructure. - One-way:
oneway=yes|-1|no, implied byjunction=roundabout|circularand byhighway=motorway;reversible/alternatingcloses the way to cars. Bicycles follow the same rule unlessoneway:bicycle=no,cycleway*=opposite*orcycleway:*:oneway=-1(contraflow);oneway:bicycle=yes|-1is honoured. Pedestrians ignore one-ways. - Speed:
maxspeedas an explicit number in km/h, mph or knots between 5 and 150 km/h; anything else ("signals", zones, "none") leaves the speed assumed. Ferries: speed = mapped length ÷duration, accepted between 2 and 80 km/h. - Surface: paved / unpaved lists from
surface, elsetracktype(grade1 = paved), else unpaved for tracks, else unknown. - Flags:
toll,tunnel,bridge, roundabout, link, cycle lane or track, minor service roads (driveway,parking_aisle,drive-through,emergency_access). - Nodes:
highway=traffic_signals(on a graph node, or flagged on the edge when it is an intermediate point);barrier=*: cars pass gates, lift gates, cattle grids, toll booths, border controls, kerbs and a few others unlesslocked=yes, and are blocked by everything else (bollards, blocks…); bicycles are blocked by stiles, turnstiles, jersey barriers and walls / fences / hedges; pedestrians by walls / fences / hedges. Access tags on the node override (nocloses,yesopens;privateanddestinationdo not close). - Turn restrictions with a via node:
no_left_turn,no_right_turn,no_straight_on,no_u_turn,no_entry,no_exit,only_left_turn,only_right_turn,only_straight_on,only_u_turn. They apply to cars and bicycles;except=removes modes;restriction:motorcar/:motor_vehicle(car),restriction:vehicle(both),restriction:bicycleand thetype=restriction:<vehicle>form are understood; restrictions for other vehicles (hgv, bus…) are ignored.
Everything that is skipped is counted in the report and in the metadata of the file (buildCounters), never silently:
| Counter (province build, 2026-11-25) | Value |
|---|---|
restrictionRelations (supported form, via node) |
12 967 |
restrictionsApplied → restrictionRecords |
12 699 |
restrictionsOutsideGraph (a member way is not routable or not in the extract) |
246 |
restrictionsAmbiguousSkipped (the from or to way does not end at the via node) |
22 |
restrictionsViaWaySkipped (via way: not supported) |
2 884 |
restrictionsConditionalIgnored |
757 |
restrictionsInvalid (missing members, unknown value) |
294 |
restrictionsOtherVehiclesIgnored |
1 |
ferryWays / ferryWaysWithDuration / ferryDurationsRejected |
100 / 29 / 4 |
routableWays / waysWithMaxspeed |
1 252 493 / 161 925 |
shapePoints kept / shapePointsDropped by the 0.5 m simplification |
5 685 853 / 2 133 132 |
Measured numbers
Mac with 18 cores and 48 GB, macOS 27.0, Swift 6.4.2, release build, 2026-11-25, other jobs running on the machine.
Command: /usr/bin/time -l $B --pbf <extract> --region <id> --out <file>.
| Extract | Size | Wall time | Peak resident memory | Peak memory footprint | Output |
|---|---|---|---|---|---|
data/quebec-city.osm.pbf |
22 MB | 0.46 s | 219.6 MB | 113.0 MB | 10.2 MB, 144 333 edges |
data/montreal.osm.pbf |
97 MB | 4.60 s | 1 038 MB | 716 MB | 91.0 MB, 1 395 361 edges |
data/quebec-latest.osm.pbf |
1 169 MB | 12.64 s | 2 994 MB | 1 413 MB | 184.6 MB, 2 467 372 edges |
Province, by phase: pass 1 (ways, relations) 3.7 s, pass 2 (nodes) 4.2 s, graph construction 1.7 s, serialization (components, spatial index, sections) 1.8 s. Other runs of the same build on the same day took 10.4 s and 15.7 s depending on the load of the machine. The resident peak includes the memory-mapped PBF pages and the blocks decoded in parallel by the reader; the footprint is the builder's own memory.
File sizes, bytes per edge, routing times and the plausibility checks are in Packages/ORIXRouting/README.md.
The Montréal and Québec City extracts carry no replication timestamp in their header: their graphs have no
osmTimestamp (shown as "unknown"). The province extract gives 2026-11-24T21:21:23Z.
Tests
cd Infrastructure/routing-builder
swift test # 11 testsResult on 2026-11-25: 11 passed, 0 failed.
TagInterpreterTests(7): classes and default access, access hierarchy, one-ways and contraflow, attributes (maxspeed, surface, flags), ferries and durations, barriers and signals, restriction relations (each value,except, vehicle-specific forms, conditional, via way, broken relations).ExtractorTests(4): end to end on the Monaco extract thatORIXOSMships as a test fixture (read in place): the graph passes full validation, every restriction relation is applied or counted, no edge has the same node at both ends, routes Casino → Palace for the three modes with A* = Dijkstra, builds are byte-for-byte deterministic for a fixed build date, simplification only removes shape points,--bboxclipping. The suite is skipped when the fixture is missing.
Known limits
- The whole graph is assembled in memory before it is written (3 GB resident for the province). A country-sized extract would need a streaming writer.
- No incremental build: any change in the extract means a full rebuild (13 s for the province).
- Ways are followed as mapped: areas (
highway=pedestrian+area=yes) are routed along their outline only. - Places of the benchmark are landmarks typed by hand, not geocoded; they only need to be within 500 m of a road.
ORIXOSMentities (OSMNode,OSMWay,OSMRelation) have no public initializer, so tests cannot build them; the restriction parser therefore also accepts plain tags and members (TagInterpreter.interpret(restrictionID:tags:members:)).
Not done
- Via-way restrictions, conditional restrictions, direction-specific access and speed tags, seasonal closures,
destination/ exit numbers of motorway junctions, mini-roundabouts, lanes. - Elevation: nothing is read (there is no elevation source in the project yet).
- No urban / rural classification for assumed speeds.
- No integration with the region package builder (
Infrastructure/package-builder): this tool only writes the.orixgraphfile; naming itrouting.orixgraphinside a package and checksumming it belong to that tool.