User:Stanton/Using the Mapquest Style

From OpenStreetMap Wiki
Jump to navigation Jump to search

Mapquest produces style files for Mapnik, which can be used as a starting point for custom maps. However, they come with little documentation, hence I tried ti create a step-by-step guide based mostly on trial and error.

Prerequisites

Set up a Mapnik rendering chain, e.g. as described in User:Stanton/Mapnik Test Server. Complete the Setup section of the article and populate the database with OSM data as described in the following section. For now, I imported the data unfiltered.

The rest of this article assumes you have followed the procedures in the article for a setup based on Ubuntu 12.04 LTS.

Get Mapnik Styles

Download the archive from https://github.com/MapQuest/MapQuest-Mapnik-Style/archive/master.zip. Extract the files and move the contents of the MapQuest-Mapnik-Style-master folder to /usr/share/mapgen' on your server (where you also have all the other Mapnik stuff).

Get GeoTiffs

Mapnik has some predefined GeoTIFFs for lower zoom levels, which are expected by the style file. Get them from http://developer.mapquest.com/content/static/geotiffs/mercator_tiffs.tar.

cd /usr/share/mapgen/mapnik/world_boundaries
wget http://developer.mapquest.com/content/static/geotiffs/mercator_tiffs.tar
tar -xf *.tar
rm *.tar
mv */* .
rmdir * 2>/dev/null

Mapnik Initialization

To use Mapnik with the mew style files, some initializations are needed.

cd /usr/share/mapgen/mapnik
./generate_xml.py --inc ./mapquest_inc --host localhost --user mapuser --dbname mapdb --symbols ./mapquest_symbols --world_boundaries ./world_boundaries --port '' --password ''

The Mapquest styles use the Arial font family, which is not installed on a Unix system. To work around this, your options are:

  • Get the Arial fonts and install them into the Mapnik fonts dir
  • Replace mapquest_inc/fontset-settings.xml.inc with inc/fontset-settings.xml.inc (provided that you have previously initialized the standard OSM XML).
  • Run ls `python -c "import mapnik2 as mapnik;print mapnik.fontscollectionpath"` to see your available fonts, then hand-edit mapquest_inc/fontset-settings.xml.inc to use fonts available on your system

I went for the second option for the moment, as it was easiest.

Test the Chain

Now test if the renderer works as expected. The nik2img program will help us do this. Let's pick an area for which we have already imported GIS data – set the coordinates with the -c parameter and the zoom with -z. Generate a test image.

cd /usr/share/ptgen
cd mapnik
nik2img.py mapquest-uk.xml image.png -c 10.27 47.13 -z 16 -d 256 256 --no-open -f png256

Open the test image in the application of your choice and verify everything is OK.

Note: the mapquest-us.xml stylesheet uses some columns which do not get imported in the default configuration. If you want to use the US style, you need to edit /usr/share/osm2pgsql/default.style and add the missing columns, then reimport your data.

For more information on nik2img.py refer to User:Stanton/Mapnik Test Server#Test the Chain