DE | EN

Christian NeumannDigital Solutions for Sustainable Mobility

Create OpenStreetMap vector tiles with tilemaker

Web map applications like MapLibre GL JS depend on vector tile data to render maps. It is possible to just use a service like maptiler or mapbox. They take care of generating and hosting up to date vector tiles that are simple to use in your application.

If you don't want to use a map service, for example because that's too expensive for your project or you have special needs, you could generate and host the tiles yourself. Be warned that this takes some technical experience, hardware power and / or time. A discussion about the pros and cons of generating the tiles yourself instead of using a service is beyond this post.

Required hardware

If you want to generate vector tiles for the whole planet, you need enough CPU power, RAM and disk space to generate them in reasonable time (or at all).

To generate the tiles, I used a cloud server from Hetzner, precisely a CAX41. It provides 16 virtual Ampere Altra processors, 32 GB of RAM and 320 GB NVMe SSD space. The space won't be enough, so it's best to add a disk with 500 GB of space. The hardware and space needed depends on the size of the OpenStreetMap planet extract, the version of tilemaker and its configuration. Using the OSM planet at the time of writing, the following steps generated the tiles using about 320 GB of space and 22 GB of RAM.

Preparing the server

Provision the server with the latest stable Debian GNU/Linux release.

The following commands will update the software list and install git, Docker, and the Osmium Tool.

apt-get update
apt-get install git docker.io apparmor osmium-tool

Docker is used to run the latest version of tilemaker without the need for compilation:

git clone https://github.com/systemed/tilemaker.git
cd tilemaker
docker build . -t tilemaker

Fetching OpenStreetMap data

Create and change to a working directory on a disk that is large enough for all the downloaded and generated data. Fetch the planet data (or only the data for a region) from one of the mirrors:

wget https://[the-mirror-url]/planet-latest.osm.pbf

Optimizing the data

Tilemaker suggests that you optimize the data with the following command. This step does not take as long as the generation process.

osmium cat -f pbf planet-latest.osm.pbf -o optimized.osm.pbf

Generating the tiles

Finally, generate the vector tiles by running tilemaker through the Docker container built previously:

docker run -it --rm -v $(pwd):/data tilemaker /data/planet-latest.osm.pbf --output /data/planet-latest.pmtiles --store /data/store

This will generate a PMTiles container with the generated vector data.