The problem

Whilst reading “Run Faster from the 5K to the Marathon” by Brad Hudson and Matt Fitzgerald, a problem struck me. One workout they recommend year-round is short hill sprints on a 6-8% grade. How do you find the perfect nearby hill for hill sprints? I used online mapping tools and manually calculated the gradient of various hills near me.

Another book I was reading, “Training for the Uphill Athlete” by Steve House, Scott Johnston and Kílian Jornet, suggests 10-minute hill repeats at a runnable 8% grade. How can I find a nearby hill long enough to run up for 10 minutes at a given pace? Using online mapping tools again, I looked for hills in the area, estimated the pace I would run at, and tried to find one I could run up for the required time.

What I wanted was a way to view all the nearby hills on a map, with the ability to filter by gradient, distance and ascent time.

Why not just buy a treadmill?

I started working on this on and off towards the start of the year, leaning heavily on LLMs to help me research, plan and implement. The total I spent on LLMs is far less than the price of a treadmill.

Data

Thanks to projects like OSM, it is easy to build software that requires maps and can LLMs bring you up to speed working with these projects without specialist knowledge. This project would have taken much longer without LLM assistance, and likely wouldn’t have been attempted in the first place.. I would have bought that treadmill. Several projects that do something similar to Vertfinder have appeared recently, e.g. hill-finder.com, hillism.com and vertmatch.run, but none of them scratched my particular itch, so I built my own.

This post documents how I generate and categorise the climbs in OSM data using freely available elevation data, which may be useful for other projects to build on.

Geofabrik

For each region, the first step is to download the OSM data from Geofabrik. I started with Bristol, as that is where I wanted to find hills for my workouts.

Way chaining

OSM has ways, which represent linear features on the ground such as roads and trails.

After sourcing the OSM data, the first processing step is to extract all runnable ways, e.g. non-private roads and trails. HIGHWAY_TYPES has the full list.

The pipeline stores these runnable ways in a SQLite GraphStore, along with the latitude and longitude of every node in them, for elevation lookups later.

In OSM, a way has a way ID and an ordered list of node IDs, e.g.:

Way 10: nodes = [A, B, C, D]

A ─── B ─── C ─── D
└─┬─┘ └─┬─┘ └─┬─┘
(A,B) (B,C) (C,D)   ← the edges

Two ways are connected when they share a node ID:

 INPUT
    Way 10 (path): [A, B, C, D]
    Way 20 (path): [B, C, E]

                        E
                       ╱
            A ─── B ══ C ─── D
                  └──┘

Connected ways need to be chained, because a single OSM way doesn’t necessarily correspond to a full runnable climb. In the example above, the climb could be A→B→C→E, where C→E keeps gaining elevation and C→D levels off or goes downhill. In that case we want to detect A→B→C→E as the climb.

The pipeline stores the chained ways in a chains table in SQLite, with the node IDs that make up each chain.

Choosing an elevation model

I compared Copernicus GLO-30 and Viewfinder Panoramas’ 1 arcsecond data, put together by Jonathan de Ferranti, and wrote an audit skill to compare climb quality between pipeline runs.

Copernicus GLO-30 includes trees and buildings, which produced false gradients on climbs in cities and woods. I noticed this when spot-checking various climbs in Paris against Street View. Rue de Maubeuge was the worst one I found. Copernicus had the first 100 m at 12%, when it’s actually closer to 2%.

Elevation profile of Rue de Maubeuge, Paris. Copernicus climbs about 28 m over 559 m, while Viewfinder and the IGN LiDAR reference both climb about 15 m and track each other closely.

To check this wasn’t just a few bad streets, I also tried FABDEM and GEDTM30. I compared all four models against LiDAR data on 35 routes in Bristol and 30 in Paris, using Environment Agency LiDAR for Bristol and IGN for Paris. Viewfinder was much closer than the others, and beat Copernicus on 64 of the 65 routes. Average gradient error over 100 m, in percentage points:

RegionCopernicusFABDEMGEDTM30Viewfinder
Bristol1.852.151.650.57
Paris3.562.113.440.59

Viewfinder is resampled national LiDAR data, which explains why it matches so well. It doesn’t have trees and buildings messing with the real elevation.

Copernicus remains an option for regions Viewfinder’s 1 arcsecond data doesn’t cover. The pipeline lets each region use a different elevation model. Long term it would be good to use 1 m LiDAR data wherever it exists, as it’s the most accurate, but not every region has it.

Sampling the elevation model

For each chain in chains, the pipeline samples the elevation model at each node’s latitude and longitude and writes the result to a separate heights table.

With heights in place, the pipeline splits each chain wherever it changes direction, i.e. where it goes up and then back down by at least 5 m, or down and then up. Each uphill part is then a candidate climb.

Selecting the steep core of a climb

Some climbs have a long flat section at the start or end, which isn’t useful for Vertfinder. E.g.:

  elevation
     │              ╭──── flat top (trimmed)
     │          ╭───╯
     │       ╭──╯   ← steep core (kept)
     │ ──────╯
     │ flat approach (trimmed)
     └──────────────────────── distance

The next step is to walk through each node in the climb and calculate how much it has climbed since the start.

Each node gets a score for how much more it has climbed than a steady 3%:

score(node) = elevation gained since the start − 3% × distance from the start

Stretches steeper than 3% make the score rise, and flatter stretches make it fall. I chose 3% by eye, by checking where the trimmed climbs started and ended on hills local to me.

After scoring all nodes, the pipeline keeps the stretch with the biggest score gain. Any remaining parts become climbs of their own if they pass the global filter below. Otherwise the pipeline drops them.

To reduce noise, a climb must be at least 200 m long with an average gradient of at least 5%. Climbs made only of steps are the exception. They need 5% and at least 20 m of gain instead of 200 m.

GAP model

Each climb gets a grade-adjusted distance from an approximation of the GAP model published by Strava. The pipeline multiplies each segment’s distance by an effort factor for its gradient, read off Strava’s curve. That gives the flat distance that would take the same effort. Dividing it by your flat pace gives an estimated ascent time, so Vertfinder can find a hill that will take me 10 minutes to run up at a given pace.

Naming the nearest settlement

As a final piece of housekeeping, I add metadata to the climbs to make it easier to tell where they are.

With just the OSM names, climbs are either unnamed or named after the road. For example, with made-up IDs:

way_idnamehighwaydist_mavg_grad
101Lime Lanefootway45014%
205—footway3209%
317—track6107%

Instead, I take the midpoint of each climb and look up three things:

  • locality: the nearest OSM place within 10 km, weighted by type so that a nearby suburb beats a city centre further away.
  • area: the smallest named park, wood, nature reserve or protected area containing the midpoint.
  • route: a walking, running or cycling route relation the climb is part of.

These go in a climb_places table:

way_idlocalityarearoute
101Abbots LeighLeigh Woods—
205Clifton——
317Wrington—Limestone Link

Vertfinder uses these to name unnamed climbs, e.g. “Footpath in Leigh Woods”.

Pipeline

To automate the steps above, Claude initially chained a load of Python scripts together, but I switched to Snakemake to standardise things.

To scale beyond Bristol, the workflow downloads the Geofabrik extracts, processes each region separately, then combines them into a single SQLite database at the end.

The whole workflow is open source on GitHub.

What’s next

More regions. Each new region is a config change. You point the pipeline at the Geofabrik extract and an elevation model, and it does the rest.

The other thing I’m hoping for is help from other runners and developers to improve accuracy. Every climb on Vertfinder has a rating and a “Report a problem” button. If you spot a climb that’s off, please report it, or open a PR on the pipeline repo.