Switching gears, with the database loaded, it’s time to install more software.
OpenStreetMap Carto generates a Mapnik XML stylesheet, which can be used by any software that includes Mapnik. Some of the common options are
- renderd for serving tiles,
- Nik4 for static images,
- MapProxy for serving tiles,
- TileStache for serving tiles, and
None of these options is perfect for anything. For this particular use the requirements are
- renders using metatiles,
- creates a directory of PNGs,
- works in parallel.
The options which meet this are:
- renderd + mod_tile/tirex and curl. This requires running a server and scraping it with curl. Although it works, it’s not ideal, and involves setting up a great deal of supporting software. When you don’t need to live-render and handle data updates, a lot of the features of renderd are useless and add complexity
- generate_tiles.py and other options that call the Mapnik API. Although capable, this typically involves some work to do metatiles and parallization.
- MapProxy. MapProxy is lacking in features for continual data updates, but they aren’t needed for this use.
- TileStache. TileStache is similar to MapProxy, but I find MapProxy easier to set up, so I didn’t investigate it in detail.
MapProxy or accessing the Mapnik API directly are the best two options. It’s a lot easier to set up MapProxy than write new code, so that’s the option I’ll go with.
With MapProxy selected, we need to install it. Unfortunately, this requires installing Mapnik. Mapnik has a reputation of being difficult to compile, having an API that changes between versions when it shouldn’t, poor support for bindings for other languages, versioning problems, and generally being tricky to work with. This reputation is accurate.
If I were trying to install Mapnik on anything other than a Debian system, it would be tricky, but I can use the excellent work of the Debian GIS team. All that’s needed is
apt-get install libmapnik3.0 mapnik-utils python-mapnik, and the required software is there. In addition to Mapnik, the
virtualenv package provides virtualenv, a program for isolated Python environments.
The install script is a simple two lines
The first line creates a virtualenv named mapproxy that has access to the system Python packages, most importantly Mapnik. The second installs MapProxy 1.11 in it.