My OSM vector tile script

I use the fantastic OpenMapTiles project to generate my OSM vector tiles. There’s nothing complicated or magical in my bash script I use to handle everything, but if you don’t bash, maybe it’ll be helpful.

I grab US South from Geofabrik, as it covers the extent I need, which I chop to size using osmconvert (available in the Arch User Repository if that applies to you). I drop the chopped PBF into the OpenMapTiles data folder with the name meck.osm.pbf, and then call quickstart.sh meck.

When tiles.mbtiles file is ready, I use scp to move it to a server under a temporary name to avoid down time while it uploads. Then I use ssh to remotely swap the uploaded file into production (osm.mbtiles). The previous tile set is retained until the next upload in case something terrible happened.

The MBTiles file is ~160MB, which for a multi-state area still blows my mind, and the whole process on my i3 desktop with 32GB of RAM takes 15-20 minutes, depending on how fast Time Warner is feeling.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#! /bin/bash

set -e -o pipefail

echo "Removing us-south..."
if [ -f us-south-latest.osm.pbf ] ; then
rm us-south-latest.osm.pbf
fi

echo "Getting OSM data..."
wget http://download.geofabrik.de/north-america/us-south-latest.osm.pbf -q --show-progress

echo "Removing meck.osm.pbf..."
if [ -f ~/workspace/openmaptiles/data/meck.osm.pbf ] ; then
rm ~/workspace/openmaptiles/data/meck.osm.pbf
fi

echo "Clipping PBF..."
osmconvert us-south-latest.osm.pbf -b=-82.641,34.125,-79.008,36.762 --complex-ways -o=openmaptiles/data/meck.osm.pbf

echo "Get to the right place..."
cd ~/workspace/openmaptiles

echo "Run OpenMapTiles..."
./quickstart.sh meck

echo "Move tiles to your server in temp location..."
scp ./data/tiles.mbtiles user@server.com:/opt/apps/node/mbtiles-server

echo "Swap active tiles on server..."
ssh user@server.com "rm /opt/apps/node/mbtiles-server/osm.mbtiles.old && mv /opt/apps/node/mbtiles-server/osm.mbtiles /opt/apps/node/mbtiles-server/osm.mbtiles.old && mv /opt/apps/node/mbtiles-server/tiles.mbtiles /opt/apps/node/mbtiles-server/osm.mbtiles"