OSM2VectorTiles is no longer maintained. Please switch to the successor project openmaptiles.org

Generate your own vector tiles

In this tutorial you will learn how to create your own vector tiles with the help of the OSM2VectorTiles toolset. In order to run through the following steps you need to have docker and docker-compose installed.

Clone the OSM2VectorTiles repository and change directory to it.

git clone https://github.com/osm2vectortiles/osm2vectortiles.git
cd ./osm2vectortiles

Start up your PostGIS container with the data container attached.

docker-compose up -d postgis

Download a PBF and put it into the local import directory. You can use extracts from Mapzen or Geofabrik

wget https://s3.amazonaws.com/metro-extracts.mapzen.com/zurich_switzerland.osm.pbf -P ./import

Now you need to import several external data sources. Import water polygons from OpenStreetMapData.com, Natural Earth data for lower zoom levels and custom country, sea and state labels.

docker-compose up import-external

With the next command the downloaded PBF file gets imported into PostGIS.

docker-compose up import-osm

The following command imports custom SQL utilities such as functions and views, which are needed to create the vector tiles.

docker-compose up import-sql

Now export a MBTiles file by passing the bounding box you want your desired extract for.

docker-compose run \
  -e BBOX="8.34,47.27,8.75,47.53" \
  -e MIN_ZOOM="8" \
  -e MAX_ZOOM="14" \

Finally, the following command generates the vector tiles and creates an MBTiles file in the export directory.

docker-compose up export

In order to display your vector tiles follow the getting started tutorial.

Optional: Merge lower zoom levels (z0 to z5) into extract (prerequisite: sqlite3 installed)

Download lower zoom level extract.

wget -P ./export/ https://osm2vectortiles-downloads.os.zhdk.cloud.switch.ch/v2.0/planet_z0-z5.mbtiles

Download the patch.sh script from the Mapbox mbutil project.

wget https://raw.githubusercontent.com/mapbox/mbutil/master/patch
chmod +x patch

Merge lower zoom levels into extract.

./patch "./export/planet_z0-z5.mbtiles" "./export/zurich.mbtiles"

Project Partners

Do you need commercial support, help with rendering of your own vector tiles, parallelisation in a cluster or Amazon Cloud, tile hosting, or efficient rendering of imagery and raster geodata? Contact us.

OSM2VectorTiles is no longer maintained. Please switch to the successor project openmaptiles.org