Routing

How Flow avoids freeways and finds good roads

On this page 6

Electric unicycles, e-scooters, e-bikes, and onewheels span a wide range of capability — many riders cruise at 25–35 mph, while modern performance wheels hold 50 and top out past 90. What every PEV shares is exposure: no cage, no crumple zone, and — for most machines — a real speed differential with freeway traffic. That makes an interstate a bad trade at any cruise speed, though not always a forbidden one: some western freeway shoulders legally carry bicycles, and where that's true Flow says so plainly. Flow's route selection is built around a simple principle: give riders the most interesting, safest road that still gets them where they're going.

The freeway-avoidance approach

For shorter trips (under ~30 miles by straight-line distance), Flow requests a exclude=motorway route from Mapbox as its primary candidate. This parameter tells the Mapbox directions engine to avoid roads classified as motorway — interstates and limited-access highways.

There's a known complication: Mapbox classifies some 2-lane rural roads as "motorway" based on their route designation, not their physical character. US-101 through Mendocino, CA-1 along the coast — Mapbox calls these motorways on some segments. Excluding them outright forces absurd detours on routes PEV riders actually want. So the exclusion is applied as a parallel candidate rather than a hard constraint. If the no-motorway route is more than 1.5× the haversine distance — a strong signal that it's routing around something it shouldn't — Flow falls back to the plain driving route and lets the scoring system handle it.

For longer routes, the no-motorway driving path is fetched in parallel alongside standard driving alternatives, a cycling-profile route, and any matching bicycle network corridors. All candidates go through the adventure scorer, which penalizes freeway distance proportionally.

How Flow detects dangerous road segments

Before scoring, every route candidate passes through a safety analyzer that scans the Mapbox directions step data:

  • Interstates (I-5, I-80, I-280, etc.): flagged as "danger" no matter how short the stretch — a hundred metres of interstate is still an interstate. The one exception is legality: where bikes are actually permitted on a freeway shoulder, as on some western stretches, Flow says so plainly instead of crying danger. Legal access outranks road classification, so a road you are allowed to ride is never dressed up as a hazard.
  • US highways (US-101, US-6): flagged as "caution" only when the segment is long enough and has step intervals suggesting a divided highway (few intersections). Short shared stretches of a US highway through a small town are not flagged.
  • State highways (CA-1, OR-36, WA-20): usually not flagged — these are the good roads, and Flow classifies them as ordinary surface road. The exception is a state highway built to freeway standard: where OSM classes the way as motorway, Flow flags it as limited-access and treats it as dangerous even though its number looks like any other state route. CA-24 through the Caldecott is the local example.

Safety warnings carry the hazard type, severity, entry coordinates, total distance on that road, and a human-readable message. The adventure scorer uses this data as the "safety" input factor.

Adventure scoring

Flow's route scorer ranks candidates on five factors. The weights reflect PEV riding priorities:

Factor Weight What it measures
Bicycle network 30% Named bicycle routes (NCN > RCN > cycling profile > none)
Safety 25% Inverse freeway/dangerous-highway fraction
Road character 20% State-highway and local-road fraction vs. interstate
Through-route 15% Whether the dominant road passes near the destination
Duration 10% Soft penalty for slower routes (up to 2× fastest = 0)

Bicycle network is the top-weighted factor because named routes (Pacific Coast Route, Adventure Cycling routes, etc.) are almost always the right road for a PEV rider — purpose-built for the experience, avoiding interstates, and passing through towns with services.

Road character rewards state highways (CA-1, OR-36) and local/unnamed roads, and gives zero credit to interstates and US highways. A route along CA-1 plus unnamed coastal roads scores near 1.0 on this dimension.

Safety is additive with road character but computed separately. Even 33% interstate distance zeroes out the safety score (the multiplier is 3×). A route that clips one short freeway stretch gets significantly penalized.

Through-route rewards candidates whose dominant road passes close to the destination (within 5 km = full score; beyond 15 km = zero). This catches cases where a "scenic" route diverges so far it's impractical.

Duration applies a soft penalty: up to 1.3× the fastest candidate loses proportionally; beyond 2× gets zero. This prevents adventure scoring from recommending a 3-day detour.

Shorter trips use a reduced scoring set — safety, duration, and how coherently a candidate holds one road rather than stitching turns together. The trip-scale gate reads road distance, not straight-line distance, so a winding coastal run counts for what it actually costs to ride.

Bicycle network candidates

Once a trip is long enough to be worth it, Flow looks for named bicycle routes along the corridor. These come from OSM relations tagged route=bicycle — ncn (national) and rcn (regional) networks, and on city-scale trips lcn (local) as well.

These are not fetched live while you plan. Querying Overpass mid-route-build was slow and fragile, so the networks are baked ahead of time into Flow's corridor table and read from there; the bake script is now the only thing that talks to Overpass.

When a bicycle route is found:

  1. If it closely overlaps an existing driving candidate, it can replace that candidate within the same slot, keeping its name as the label — unless taking it would stretch the ride too far, in which case it is offered alongside instead of displacing anything.
  2. Otherwise it's added as an additional candidate.

Bicycle route labels come from the OSM relation's name or ref tag — "Pacific Coast Route," "California Coast Route 1," and so on — instead of the differential road-labeling used for driving candidates.

Matching uses corridor proximity: the bicycle route's waypoints are sampled, and the route qualifies when enough of your trip runs inside its buffer and at least one end of your trip lands near it — not both ends. Requiring both was too strict and silently discarded good corridors: a rider joining a long national route partway along it would match nothing.

Only a small number of bicycle network candidates are carried into a single route request — enough to offer a real alternative without burying the choice.

Pre-baked good-roads corridors

Some corridors are too important to leave to on-demand routing every time. Flow maintains a public.corridors table in its backend holding pre-computed waypoint chains for the bicycle networks worth routing along — national and regional routes such as the Pacific Coast Route, plus city-scale local networks.

When a rider plans a route along one of these corridors, the waypoint chain is passed to Mapbox as intermediate waypoints, forcing the route to follow the corridor road instead of defaulting to US-101 inland. The pre-baked corridors carry the bicycle network through the engine: the Pacific Coast Route waypoints are the same ones an OSM query would return, but without the latency of a live Overpass query.

Each corridor is stored with its network class, a region, a bounding box, and its geometry as an encoded polyline. The engine finds candidates by testing which corridor bounding boxes the rider's trip overlaps, then works with the matching chains. For a multi-day route from SF to Fort Bragg, this is what surfaces CA-1 through Bodega Bay and Jenner rather than the highway.

What this means in practice

On a 230-mile run from San Francisco to Fort Bragg:

  • The recommended route follows CA-1 north through Marin, then the coast highway through Bodega Bay, Jenner, and Gualala.
  • The Pacific Coast bicycle route waypoints keep the engine on the coast road where Mapbox would otherwise drift to US-101.
  • Interstates appear nowhere in the route. US-101 may appear for short urban segments in San Francisco; those segments are flagged as caution and visible to the rider before starting.
  • Charger stops are placed at J1772 pedestals at state parks, hotels, and campgrounds along the corridor — not at car fast-charger clusters inland.

The effect is a route that reads like a curated ride, not a navigation shortcut.


See also: How Flow routes around chargers you can actually use →