Mirror of the mapnik stylesheets used on OpenStreetMap.org
Switch branches/tags
Nothing to show
Pull request Compare This branch is 72 commits behind openstreetmap:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Rendering OpenStreetMap with Mapnik

Welcome, if you have Mapnik and osm2pgsql installed and you want
to render your own OSM tiles, you've come to the right place.

This is the development location of the Mapnik XML stylesheets powering

This directory also holds an assortment of helpful utility scripts for
working with Mapnik and the OSM Mapnik XML stylesheets.

The serving of the official tiles is done using mod_tile
 * Code is located at http://svn.openstreetmap.org/applications/utils/mod_tile.
 * Rendering is done by the 'renderd' daemon (both a python and C++ version are available).

However, the easiest way to start rendering Mapnik tiles is to use the 
'generate_tiles.py' script located within this directory.

Quick References
If you need additional info, please read:
 - http://wiki.openstreetmap.org/wiki/Mapnik

If you are new to Mapnik see:
 - http://trac.mapnik.org

If you are looking for an old file that used to be here see the 'archive' directory.


Mapnik >= 0.7.1 | The rendering library
 * Built with the PostGIS plugin
 * http://trac.mapnik.org/wiki/MapnikInstallation

osm2pgsql trunk | Tool for importing OSM data into PostGIS
 * The latest trunk source is highly recommended
 * http://svn.openstreetmap.org/applications/utils/export/osm2pgsql

Coastline Shapefiles
 * Download these locally
 * For more info see: http://wiki.openstreetmap.org/wiki/Mapnik
 * They come with Mapnik indexes pre-built (using shapeindex)

Planet.osm data in PostGIS
 * An extract (recommended) or the whole thing
   - http://wiki.openstreetmap.org/wiki/Planet.osm
 * Import this into PostGIS with osm2pgsql


The goal is to customize the Mapnik stylesheets to your local setup,
test rendering a few images, and then get set up to render tiles.

Make sure you have downloaded the coastlines shapefiles and have set up a
postgis enabled database with osm data imported using osm2pgsql. See
http://wiki.openstreetmap.org/wiki/Mapnik for more info.

Customize the 'osm.xml' entities to your setup. You can either use the 
'generate_xml.py' script or manually edit a few files inside the 'inc' directory.

Finally try rendering a few maps using either 'generate_image.py',
'generate_tiles.py' or 'nik2img.py'.

Downloading the Coastlines Shapefiles
    All these actions are regrouped in the script file get-coastlines.sh in this directory

    wget http://tile.openstreetmap.org/world_boundaries-spherical.tgz # (50M)
    wget http://tile.openstreetmap.org/processed_p.tar.bz2 # (227M)
    wget http://tile.openstreetmap.org/shoreline_300.tar.bz2 # (46M)
    wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/10m-populated-places.zip # (1.5 MB)
    wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/110m-admin-0-boundary-lines.zip # (38 KB)

    tar xzf world_boundaries-spherical.tgz # creates a 'world_boundaries' folder
    tar xjf processed_p.tar.bz2 -C world_boundaries
    tar xjf shoreline_300.tar.bz2 -C world_boundaries
    unzip -q 10m-populated-places.zip -d world_boundaries
    unzip -q 110m-admin-0-boundary-lines.zip -d world_boundaries

Using generate_xml.py

To use the 'generate_xml.py' script simply run:

    ./generate_xml.py -h  # note the optional and required parameters

Most users will need to pass their database settings with something like:

    ./generate_xml.py --dbname osm --host 'localhost' --user postgres --port 5432 --password ''

If that command works, then you are ready to render tiles!

The script will also pick up ALLCAPS global environment settings (where they must have a 'MAPNIK" prefix):

    export MAPNIK_DBNAME=osm && export MAPNIK_HOST=localhost && ./generate_xml.py 

Note: Depending on your database configuration you may be able to leave empty values for
parameters such as 'host', 'port', 'password', or even 'dbname'.

Do do this can pass the '--accept-none' flag or empty strings:

    ./generate_xml.py --dbname osm --accept-none

    ./generate_xml.py --dbname osm --host '' --user '' --port '' --password ''

Advanced users may want to create multiple versions of the Mapnik XML for various rendering
scenarios, and this can be done using 'generate_xml.py' by passing the 'osm.xml' as an argument
and then piping the resulting xml to a new file:

    ./generate_xml.py osm.xml > my_osm.xml

Manually editing 'inc' files

To manually configure your setup you will need to work with the XML snippets 
in the 'inc' directory which end with 'template'.

Copy them to a new file and strip off the '.template' extension.

    cp inc/datasource-settings.xml.inc.template inc/datasource-settings.xml.inc
    cp inc/fontset-settings.xml.inc.template inc/fontset-settings.xml.inc
    cp inc/settings.xml.inc.template inc/settings.xml.inc

Then edit the settings variables (e.g. '%(value)s') in those files to match your configuration.
Details can be found in each file. Stick with the recommended defaults unless you know better.

Testing rendering

To generate a simple image of the United Kingdom use the 'generate_image.py' script.

    ./generate_image.py # will output and 'image.png' file...

To try generating an image with the ability to zoom to different areas or output different formats
then try loading the XML using nik2img. Download and install nik2img using the
instructions from http://trac.mapnik.org/wiki/Nik2Img

To zoom to the same area as generate_image.py but at level 4 do:

    nik2img.py osm.xml image.png --center -2.2 54.25 --zoom 4

Advanced users may want to change settings and dynamically view result of the re-generated xml.

This can be accomplished by piping the XML to nik2img.py, for example:

    ./generate_xml.py osm.xml | nik2img.py test.png

Or, zoom into a specific layer's extent (useful when using a regional OSM extract):

    ./generate_xml.py --estimate_extent true --dbname osm osm.xml --accept-none | nik2img.py --zoom-to-layer roads roads.png

Rendering tiles

You are now ready to test rendering tiles.

Edit the 'bbox' inside 'generate_tiles.py' and run


Files and Directories


    OBSOLETE. Use customize-mapnik-map instead.

    Run this script to convert osm-template.xml into osm.xml with your

    A script to help customize the osm.xml. Will read parameters from the
    users environment or via command line flags. Run ./generate_xml.py -h
    for usage and help.
    A script to generate a map image from OSM data using Mapnik. Will
    read mapping instructions from $MAPNIK_MAP_FILE (or 'osm.xml') and
    write the finished map to 'image.png'. You have to change the script
    to change the bounding box or image size.

    A script to generate map tiles from OSM data using Mapnik. Will
    read mapping instructions from $MAPNIK_MAP_FILE (or 'osm.xml') and
    write the finished maps to the $MAPNIK_TILE_DIR directory. You have
    to change the script to change the bounding boxes or zoom levels
    for which tiles are created.

    An almost cut-and-paste documentation on how to use all this.

    Script for generating a simple legend from osm-template.xml, useful
    for visualizing existing styles and changes.

    Perl script to generate highway shield images. You normally don't
    have to run this because prerendered images are already stored in
    the 'symbols' directory.

    These directories contain the things needed to create Debian packages
    for OSM Mapnik stuff.

    A template for the osm.xml file which contains the rules on how
    Mapnik should render data.

    The file which contains the rules on how Mapnik should render data.
    You should generate your own version from the osm-template.xml file.

    Older script to read OSM data into a PostgreSQL/PostGIS database. Use
    the newer C version in ../../utils/export/osm2pgsql instead!

    Used to customize the environment needed by the other Mapnik OSM

    SQL commands to set up Z order for rendering. This is included in
    the C version of osm2pgsql in ../../utils/export/osm2pgsql, so you
    don't need this any more.

    Directory with icons and highway shield images.

    Comparison between zoom levels and the scale denominator numbers needed
    for the Mapnik Map file.