• This repository has been archived on 23/Jan/2023
  • Stars
    star
    153
  • Rank 243,368 (Top 5 %)
  • Language
    Python
  • Created over 14 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mirror of the mapnik stylesheets formerly used on OpenStreetMap.org
Old XML format Mapnik stylesheets for OpenStreetMap 'standard' style
--------------------------------------------------------------------

This used to be the development location of the Mapnik stylesheets
powering tile.openstreetmap.org however these XML format stylesheets
have since be superceded by new CartoCSS format stylesheets which
can be found here:
https://github.com/gravitystorm/openstreetmap-carto

These old XML stylesheets are still used on some other tile servers.

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

Scalable large-area serving is typically 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://mapnik.org

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



Required
--------

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

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



Quickstart
----------

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.

First, 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.

Then customize the xml entities (the files in the inc/ directory) which are
used by the 'osm.xml' 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 # (51M)
    wget http://tile.openstreetmap.org/processed_p.tar.bz2 # (391M)
    wget http://tile.openstreetmap.org/shoreline_300.tar.bz2 # (42M)
    wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places.zip # (1.5 MB)
    wget http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_boundary_lines_land.zip # (44 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 ne_10m_populated_places.zip -d world_boundaries
    unzip -q ne_110m_admin_0_boundary_lines_land.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.

Troubleshooting
---------------

If trying to read the XML with Mapnik (or any of the python scripts included here that use Mapnik)
fails with an error like `XML document not well formed` or `Entity 'foo' not defined`, then try running
xmllint, which may provide a more detailed error to help you find the syntax problem in the XML (or its
referenced includes):

    xmllint osm.xml --noout

Not output from the above command indicates the stylesheet should be working fine.

If you see an error like: `warning: failed to load external entity "inc/datasource-settings.xml.inc"` then this
likely indicates that an include file is missing, which means that you forgot to follow the steps above to generate the needed includes on the fly either by using `generate_xml.py` or manually creating your inc files.


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

    ./generate_tiles.py

Alternatively, run

    ./polytiles.py --bbox X1 Y1 X2 Y2

Tiles will be written into 'tiles' directory. To see the list of all parameters,
run this script without any.

Files and Directories
---------------------

all_tiles
    ??

convert
    OBSOLETE. Use customize-mapnik-map instead.

customize-mapnik-map
    Run this script to convert osm-template.xml into osm.xml with your
    settings.

generate_xml.py
    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.
    
generate_image.py
    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.

generate_tiles.py
    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.

polytiles.py
    An advanced script to generate map tiles with Mapnik. Can produce
    png files, .mbtiles or just a list. Supports not only bboxes,
    but PostGIS polygons, .poly files and tile lists. Run the script
    without parameters to see the full list of options.

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

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

mkshield.pl
    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.

openstreetmap-mapnik-data
openstreetmap-mapnik-world-boundaries
    These directories contain the things needed to create Debian packages
    for OSM Mapnik stuff.

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

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

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

set-mapnik-env
    Used to customize the environment needed by the other Mapnik OSM
    scripts.

setup_z_order.sql
    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.

symbols
    Directory with icons and highway shield images.

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

More Repositories

1

iD

๐Ÿ†” The easy-to-use OpenStreetMap editor in JavaScript.
JavaScript
3,369
star
2

openstreetmap-website

The Rails application that powers OpenStreetMap
Ruby
2,188
star
3

osm2pgsql

OpenStreetMap data to PostgreSQL converter
C++
1,390
star
4

osmosis

Osmosis is a command line Java application for processing OSM data.
Java
672
star
5

mod_tile

Renders map tiles with mapnik and serves them using apache
C++
287
star
6

merkaartor

Home of Merkaartor, an openstreetmap mapping program.
C++
280
star
7

OSM-binary

Java
193
star
8

id-tagging-schema

๐Ÿ†”๐Ÿท The presets and other tagging data used by the iD editor
JavaScript
158
star
9

leaflet-osm

OpenStreetMap plugin for Leaflet
JavaScript
110
star
10

operations

OSMF Operations Working Group issue tracking
99
star
11

chef

Chef configuration management repo for configuring & maintaining the OpenStreetMap servers.
Ruby
95
star
12

tirex

Tirex tile queue manager. A drop-in replacement for renderd.
Perl
65
star
13

openstreetmap-mirror

Scripts to mirror remote repositories to http://github.com/openstreetmap
Shell
60
star
14

potlatch2

Potlatch 2 OpenStreetMap Editor
ActionScript
50
star
15

owg-website

The website for the OSMF Operations Working Group (OWG)
CSS
50
star
16

osmembrane

OSMembrane is a GUI front-end for โ€œOsmosisโ€ used by the OpenStreetMap project.
Java
42
star
17

map-icons

Mirror of the map icons used on OpenStreetMap.org
HTML
40
star
18

mkgmap

Mirror of mkgmap's Subversion repository
Java
32
star
19

tile-attribution

This repository is used for reporting and tracking sites which are using tile.openstreetmap.org tiles but without attributing OpenStreetMap. The sites are tracked in the issue tracker.
Ruby
32
star
20

osmdbt

OSM Database Replication Tools
C++
21
star
21

cgimap

Mirror of CGImap, the optimized implementation of the OpenStreetMap "/map" API call. PRs via: https://github.com/zerebubuth/openstreetmap-cgimap
C++
19
star
22

dns

OpenStreetMap DNS
JavaScript
15
star
23

gosmore

Mirror of Gosmore's Subversion repository
C++
13
star
24

stateofthemap-2019

State of the Map 2019 website
HTML
11
star
25

stateofthemap-2022

CSS
11
star
26

lane-icons

โฌ†๏ธ SVG icons for common lane markings
11
star
27

svn-archive

Archived git conversion of svn.openstreetmap.org
Java
9
star
28

stateofthemap-2020

State of the Map 2020 website
CSS
9
star
29

shp2osm

Mirror of the shp2osm Subversion repository
Python
9
star
30

osm2pgsql-website

Website for the osm2pgsql project
SCSS
8
star
31

potlatch

Mirror of Potlatch's subversion repository
ActionScript
7
star
32

gpx-updater

Retrieve new OSM GPS tracks as they are uploaded, and invalidate cached tiles
Perl
7
star
33

planetdump

Obsolete OpenStreetMap Planet Dump Generator - Replaced by https://github.com/zerebubuth/planet-dump-ng
C
6
star
34

splitter

Mirror of splitter's Subversion repository
Java
6
star
35

stateofthemap-2018

State of the Map 2018 website
HTML
6
star
36

beboj

Online OpenStreetMap editor (pre-alpha, discontinued)
Java
5
star
37

stateofthemap-website

State of the Map website resources
HTML
5
star
38

gpx-import

GPX Importer
C
4
star
39

stateofthemap-2016

State of the Map 2016
CSS
4
star
40

openstreetmap-license-change

Algorithm for OpenStreetMap ODbL transition.
Ruby
3
star
41

stateofthemap-2017

State of the Map 2017 website
HTML
3
star
42

stateofthemap-2024

State of the Map 2024 website
CSS
3
star
43

quad_tile

Native C implementation of quad_tile functions from OpenStreetMap bundled as a gem
Ruby
2
star
44

tilelog

Python
2
star
45

mediawiki-skins-osmf

OSMF Skin for MediaWiki
CSS
2
star
46

prometheus-exporters

Ruby
2
star
47

osmtaginfo

Mediawiki extension for taginfo.openstreetmap.org
PHP
2
star
48

irc-website

irc.openstreetmap.org website
HTML
2
star
49

svn-website

Minimal redirector for the svn.openstreetmap.org to the archive
Dockerfile
1
star
50

opengeodata-static

Historical OpenGeoData static content
1
star
51

hot.openstreetmap.org-website

container and builder for hot.openstreetmap.org website
Dockerfile
1
star
52

trac-website

Minimal redirector for the trac.openstreetmap.org to the archived tickets
Dockerfile
1
star
53

dmca-website

OpenStreetMap's DMCA notice website
PHP
1
star
54

stateofthemap-2021

State of the Map 2021 website
CSS
1
star