Files
maptool/docs/routing-design.adoc
T

114 lines
4.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
= Offline routing — design
:toc:
:toclevels: 1
Status: proposal, nothing implemented yet.
== Goal
Car/camper routing that works with no internet, from the same OSM
extracts the offline map is built from, with the vehicle's dimensions
(height, width, length, weight) respected, so the route doesn't go
under a 3 m bridge or over a 3.5 t bridge. Later on the same engine:
an elevation profile of the route and isochrones ("how far in 2 hours").
== Engine: Valhalla
[cols="1,3"]
|===
| Valhalla
| `truck` costing takes height/width/length/weight/axle load per
*request*, so one graph serves any vehicle. Has `/isochrone`,
`/height` and `/optimized_route` built in. Tiles are a memory-mapped
tar, so RAM stays modest even for many countries. Chosen.
| GraphHopper
| Java is already in the image (Planetiler), and custom models can do
dimensions too, but the import for ~16 GB of PBF wants a heap close
to the server's 30 GB RAM.
| OSRM
| Fastest queries, but restrictions are baked in at build time: one
graph per vehicle profile, no dimension parameters per request.
|===
== Data
The PBF files are already there: `data/geofabrik_cache/<CC>.osm.pbf`,
one per country selected for the offline map (`data/offline_regions.json`,
currently 14 countries, ~16 GB). Routing uses exactly that set, so
there's no second region picker. The files are hard-linked into
`data/routing/pbf/` (same file system, no copies, and Geofabrik refreshes
don't change a build that's in progress).
Measured on the server: 16 cores, 30 GB RAM, 780 GB free. Rough
expectation for this set: tiles 15–25 GB, a build of a few hours. The
build runs at a low priority and the old tiles keep serving while it
runs.
== Containers
Valhalla isn't packaged for Debian trixie, so it doesn't go into the
maptool image. Instead there's one more compose service, the same pattern
as `kiwix`:
[source,yaml]
----
valhalla:
image: ghcr.io/valhalla/valhalla:<pinned tag> # renovate bumps it
restart: unless-stopped
command: ["/app/bin/routing-service.sh"]
volumes:
- ./data/routing:/routing:z
- ./build/bin/routing-service.sh:/app/bin/routing-service.sh:ro,z
----
It uses the base image (binaries only), not `valhalla-scripted`. The
scripted image only rebuilds when the container restarts, and maptool
can't restart containers. Instead `bin/routing-service.sh` (~40 lines of
shell) runs inside it:
. Serve `valhalla_service` from `tiles.tar`, if one exists.
. Poll for `data/routing/build-request.json`. When it shows up, build
into `staging/` (`valhalla_build_config`, `valhalla_build_admins`,
`valhalla_build_timezones`, `valhalla_build_tiles`,
`valhalla_build_extract`), writing the current step to `status.json`.
. When the build succeeds, swap `staging/tiles.tar` in and restart
`valhalla_service`. When it fails, keep the old tiles and put the log
in `status.json`.
maptool reaches it at `http://valhalla:8002` (`VALHALLA_URL`), server
side only, like `KIWIX_URL`.
== maptool side
* "Build routing" next to the existing offline/terrain builds, login
required. It writes `build-request.json` and links the PBF files.
Status and history appear in the same build panel (`build_history`).
* `POST /api/route` proxies to Valhalla `/route` with `costing: truck`
and the vehicle profile filled in. It's open to everyone, like the
map. Login is required only to save the result.
* Vehicle profile: height, width, length, weight. Stored server-side,
one for now, editable in the route panel.
* Route panel: start, end and via points (map click, search result, GPS
position, a library point), the route drawn with distance, time and
turn list. "Save to library" stores it as a `route` item, so the
route goes to OsmAnd/Locus through the same export as everything
else.
== Phases
. Container + build script + "Build routing" + status. Done when
`curl valhalla:8002/route` answers on the server.
. `/api/route`, the vehicle profile, the route panel, save to library.
. Elevation profile of the route (sampled from `terrain.pmtiles`, which
is already there, instead of Valhalla's own SRTM download), then
isochrones.
== Open questions
* Pin a Valhalla version: take the latest `ghcr.io/valhalla/valhalla`
release tag at implementation time and add it to Renovate (a docker
image in compose is tracked by default).
* Trailer / several vehicle profiles: one profile until it's needed.