Running a map server with Mapnik and TileStache on Ubuntu 16.04

This guide shows the setup of a simple map server with Mapnik 3 and TileStache 1.51.6 using Apache2 on Ubuntu 16.04 Desktop.

Mapnik is a powerful tool for generating maps from geographic data, TileStache a simple vetor and raster tile server for geographic data.

1. Installing Mapnik

sudo apt-get install libmapnik3.0 mapnik-utils python-mapnik

2. Installing TileStache

First we install the dependencies with this 2 commands:

sudo apt-get install python-software-properties
sudo apt-get install curl git-core python-setuptools python-dev python-gdal libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev

Now we get TileStache and install it into /opt folder:

cd /opt
sudo curl -O https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py
sudo pip install -U werkzeug
sudo pip install -U pyproj
sudo pip install -U modestmaps
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib
sudo ln -s -T /usr/include/freetype2/ /usr/include/freetype
sudo git clone https://github.com/migurski/TileStache.git
cd TileStache/
sudo python setup.py install

Now we configure TileStache editing the file /opt/TileStache/tilestache.cfg:

"cache":
{
"name": "Disk",
"path": "/var/www/html/tiles",
"umask": "0000"
}

3. Configuring Apache

Apache module mod_python is dead so we use mod_wsgi to execute python from Apache.

First we create the file tilestache.wsgi on a path Apache can read, for example on /var/www/wsgi:

import os, TileStache
application = TileStache.WSGITileServer('/opt/TileStache/tilestache.cfg')

Next we add WSGI to Apache adding this line to the <VirtualHost *:80> section of the file /etc/apache2/sites-available/000-default.conf:

WSGIScriptAlias /tiles /var/www/wsgi/tilestache.wsgi

No install apache mod_wsgi:

sudo apt-get install libapache2-mod-wsgi
sudo a2enmod wsgi
sudo service apache2 restart

4. Putting it all together

Now we create the folder for the tiles and clean up:

sudo mkdir /var/www/html/tiles
sudo chmod 777 -R /var/www/html/tiles
sudo rm /opt/get-pip.py

No we open the browser with the following URL:

http://localhost/tiles/osm/preview.html

You should see apearing a OSM map tile by tile. All the newly rendered tiles get stored in the folder /var/www/html/tiles. Inside you’ll find tiles in png format ordered zoom level.

Tags: , , , ,

Leave a Reply