Blog 7 min read

I casually downloaded the whole planet

I couldn't rely on OpenStreetMap's public servers, so i built my own API out of static files, on GitHub Actions

today the site is colourful

In A smile in the sky i promised a more technical post about the names on the planetarium’s skyline. This is it.

The planetarium puts names on the land around you: peaks, towns, lighthouses, observatories. On Monday they only showed up some of the time. A friend who’s currently in Japan opened a link i’d shared of where i was. They saw nothing, and wondered whether that was OpenStreetMap’s fault or just Denmark not having any mountains. Fair question. But this is what it should have looked like:

The planetarium on a phone held sideways, looking south-west near Copenhagen in the afternoon, with the Sun above a low hill labelled Herstedhøje and other names along a flat skyline

Looking towards Herstedhøje, 23 November

By Wednesday night every name in the world was coming from my own static files. Here’s how.

Where the names came from

The names come from OpenStreetMap, and the planetarium used to ask for them through Overpass: a public server that answers queries over the whole of OpenStreetMap, like “every named peak within 50 km of here”. Every time you went somewhere new, the app asked again.

Overpass is run by volunteers, and it’s often busy. It limits how often each visitor can ask, and on a bad day you get no names at all. When i tried to fetch the whole of Norway in one go, the answer was:

This Overpass API server is currently at capacity. All query workers are busy and the request queue is full. […] For automated or high-volume use, run a local Overpass API instance

The Overpass wiki page gives a few options: run your own server, pay for a commercial one, or download the regional extracts and filter them yourself.

My first idea was a Firebase database, caching the names we’d already fetched. But:

My own API, made of static files

So i made a second project, planetarium-labels. It cuts the world into 1° squares of latitude and longitude, and each square is one small JSON file, named by its south-west corner. Copenhagen is squares/55_12.json. Next to them, index.json says when the files were built and how many names each square holds.

Each name is one row:

["n274858187", "peak", 55.68909, 12.36411, "Herstedhøje", 67]

That’s the OpenStreetMap id (n for a node), what kind of thing it is, where it is, its name, and a number: the height for a peak, the population for a town.

Herstedhøje is the nearest “mountain” to where i live. It’s a human-made hill, and it stands a whopping 67 m above the sea. Denmark is so flat that a 147 m hill is called Himmelbjerget, “the sky mountain” (i made a video when i visited). Once the Danish squares were up, i could hop all over the country between the peaks.

The planetarium loads the squares within 50 km of you and caches them in the browser, so the places you’ve been still have their names offline. It feels like my own little API, made of static files.

Building it

Two tools do the heavy lifting:

For each extract, Osmium keeps only what the planetarium needs, then turns it into one GeoJSON feature per line:

osmium tags-filter europe-latest.osm.pbf \
  n/natural=peak,volcano n/place=city,town,village \
  nwr/man_made=lighthouse,observatory,tower,mast \
  -o labels.osm.pbf
osmium export labels.osm.pbf -f geojsonseq --attributes type,id -o labels.geojsonseq

A short Node script turns each feature into a row and sorts the rows into squares.

I started with Denmark and Norway, to prove it worked: 22,041 names in 173 squares, built in 8 seconds once the extracts were downloaded. The whole of Denmark is 63 KB gzipped. I checked the squares around Oslo and Jotunheimen against Overpass, and they matched exactly, with nothing missing and nothing extra.

Downloading the whole planet on GitHub Actions

This is the bit i still find amazing. The data is fetched, processed and published entirely by a GitHub Actions workflow, and none of it is committed to the repo. The repo is just code. The data only exists as the published site.

Geofabrik splits the world into nine regions, about 90 GB of extracts altogether. Europe alone is 35.5 GB, which is more than a GitHub runner has free on its main disk, so the job makes room first. Each region gets its own job, side by side, using a matrix:

rows:
  needs: check
  runs-on: ubuntu-latest
  strategy:
    fail-fast: true
    matrix:
      region: ${{ fromJSON(needs.check.outputs.regions) }}
  steps:
    # … install osmium and Node, make room for the extract …
    - run: npm run rows -- "$REGION" --tidy
      env:
        REGION: ${{ matrix.region }}
    - uses: actions/upload-artifact@v7
      with:
        name: rows-${{ strategy.job-index }}
        path: rows/

Each region’s rows are uploaded as an artifact. A site job downloads them all, merges them into squares, and uploads them for a deploy job to publish with actions/deploy-pages. If any region fails, nothing is published, and the last good build stays up. That way the published files always cover the whole world.

On Wednesday evening i started it and watched:

Two views of the GitHub Actions matrix of region jobs: on the left all nine just started, on the right eight done and Asia still running at 58 minutes

Starting, and an hour later

Antarctica was done in 21 seconds. Asia took the longest:

Region Download Names Time
Asia 16.5 GB 1,080,084 73 min
Europe 35.5 GB 778,916 21 min
Africa 8.0 GB 282,718 46 min
North America 19.6 GB 166,647 40 min
South America 4.2 GB 97,881 17 min
Russia 4.2 GB 68,427 16 min
Australia and Oceania 1.6 GB 47,711 9 min
Central America 796 MB 23,156 4 min
Antarctica 33.1 MB 3,064 21 s

That’s 2,439,280 names in 15,628 squares, once the names where neighbouring regions overlap are counted only once. Asia has more than Europe, mostly villages, and the busiest square of all is in eastern Uganda, with 6,416 names. index.json for the whole world is 56 KB over the wire.

It runs again automatically every three months, since peaks and villages hardly change, and i can start it by hand whenever i like.

One idea that didn’t work out: streaming the whole 80 GB planet file through Osmium in one go. Most observatories are drawn as outlines in OpenStreetMap, which means they need a second pass over the file, and a stream can only be read once. I could have dropped them, but i didn’t want to lose the observatories in a planetarium!

Working with Claude

I built this with Claude Code. It set up the workflow so the data could be downloaded and processed on GitHub Actions and published as soon as it had it all. It had never occurred to me that GitHub Pages could publish something that isn’t committed to the repo. That was all Claude’s idea.

I couldn’t have done this without Claude, but Claude wouldn’t have done it without me. That’s how i think about working with AI now: i’m much better with it, but i’m still the one who makes things happen in the first place, and there’s plenty of testing and checking left for me to do.

Names everywhere

At 23:18 on Wednesday the whole world was in. I opened the link my friend in Japan had sent me earlier, and Japanese place names were popping up all along the skyline.

The planetarium looking west from Tokyo at dusk, with an orange glow behind a dark line of mountains and Japanese names of peaks and towns along it

Looking west from Tokyo, 25 November

Anyone is welcome to use the data. Start with index.json, and the README explains the format. The names are © OpenStreetMap contributors, under the Open Database Licence, so anything that shows them needs to say so.

If you build something with them, i’d love to hear about it on Mastodon. And if you think anything is missing, open an issue on GitHub.