A quick update on where things stand after the first half of the coding period.

In my first post I mentioned three goals for the summer. The first one, adding a Valhalla-powered routing endpoint that genuinely avoids closed roads, is now done.

What I built

The platform already had road closure data in the database. What it was missing was any connection between that data and actual routing. The frontend was calling valhalla1.openstreetmap.de directly, with no awareness of the closures sitting in our own database.

I set up a self-hosted Valhalla instance (3.5.1) running in the project’s Docker stack, loaded with Switzerland OSM data. Then I built a backend endpoint, POST /api/v1/routing/closure-aware, that sits in front of Valhalla and does the work the frontend couldn’t do on its own:

  1. Fetches currently-active closures from the database that affect the requested transport mode (car, bicycle, or pedestrian)
  2. Buffers each closure geometry into an avoidance polygon. LineStrings get a 10m buffer, Points get 15m, Polygons are used as-is. The buffering uses per-centroid UTM reprojection so the radii are true metres anywhere
  3. Sends those polygons to Valhalla as exclude_polygons so the route detours around them
  4. Returns the trip along with a count of how many closures were excluded

The frontend routing page now calls this endpoint instead of Valhalla directly, so closure avoidance happens server-side automatically.

Coverage

The self-hosted Valhalla currently covers Switzerland only. For routes outside Switzerland the frontend falls back to the public Valhalla instance without closure avoidance, which is fine for now since the platform is Swiss-focused.

Next up is the sidecar service that feeds active closures into Valhalla’s traffic tile system, the second item from my original list. More on that soon.

The code is on GitHub if you want to follow along.

Location: Πολίχνη, Polichni Municipal Unit, Pavlos Melas Municipality, Thessaloniki Regional Unit, Central Macedonia, Macedonia and Thrace, 565 33, Greece

Discussion

Leave a comment

Log in to leave a comment