YuChun's Blog
Published on

How to create raster tiles with OSM data

Authors
  • avatar
    Name
    YuChun Tsao
    Twitter

Demo

In this example, I will use openstreetmap-tile-server to create raster tiles from OpenStreetMap data. You can give more information about using tiles or serving tiles from switch2osm.

Prerequisites

  • Docker

Getting Started

Prepare input data

You can download the osm.pbf you want. In my case, I use taipei.osm.pbf as input data which was extracted from taiwan-latest.osm.pbf.

Create a docker volume

docker volume create openstreetmap-data

You can remove this docker volume with docker volume rm openstreetmap-data

Import your data

time \
docker run \
  --rm \
  --name openstreetmap-tile-server \
  -v ${PWD}/data/taipei.osm.pbf:/data.osm.pbf \
  -v openstreetmap-data:/var/lib/postgresql/12/main \
  overv/openstreetmap-tile-server:1.3.10 \
  import

Run the tile server

docker run \
  --rm \
  --name openstreetmap-tile-server \
  -p 8080:80 \
  -v openstreetmap-data:/var/lib/postgresql/12/main \
  -d \
  overv/openstreetmap-tile-server:1.3.10 \
  run

You can stop container with docker stop openstreetmap-tile-server

Go to example http://127.0.0.1:8080.

You can access tiles with http://127.0.0.1:8080/tile/{z}/{x}/{y}.png

References