Giter Club home page Giter Club logo

mapnik-stylesheets's Introduction

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.

mapnik-stylesheets's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapnik-stylesheets's Issues

Empty Tiles during generating tiles

I have a problem while generating tiles with generate_tiles.py. It writes randomly "empty tiles" on the log during the process (zoom level 15). It seems that it is totally random and not connected to a geographic area (I loaded a full country pbf to postgis, and now generate tile to a subset). I use a slow hard disk, and run the Ubuntu on VM with more than 6 GB RAM, but it use only 2 CPU core (an old AMD Athlon X3). I checked these tiles and they are really empty.
Screenshot:
click here

special railway-element

i missed the railway-special-element "hump_yard" to split trains and create new train-combinations.

style: same like a normal railway or a service-rail.

Translate by google:
"A hill in a yard, over which runs a track. Freight cars are pushed over that hill, so they roll under its own power in the right track. If it is detected as a point on the track."

historic = ruins on a node not rendered

I've just come over to castle ruins that were not in the map. I wanted to tag them but to my surprise they already are in the map, just not rendered in Mapnik.

The area: http://www.openstreetmap.org/#map=18/49.28095/16.07840

The ruins are tagged on a node with these tags:

historic=ruins
name=zřícenina hradu Dub
ruins=castle
source=gps

According to the Wiki page that should be okay. The "ruins=castle" is added by me just a while ago but it did not help anyway.

blended array: world_boundaries

$ ./generate_xml.py --dbname osm --user postgres --password password --accept-none
{'dbname': 'osm', 'host': '', 'user': 'postgres', 'extent': '-20037508,-19929239,20037508,19929239', 'password': 'password', 'port': '', 'estimate_extent': 'false'}
Traceback (most recent call last):
File "./generate_xml.py", line 174, in
validate(blended,parser)
File "./generate_xml.py", line 90, in validate
if not os.path.exists(params['world_boundaries']):
KeyError: 'world_boundaries'
osm@NL-Map:~/mapnik-style$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import os
os.path.exists('world_boundaries')
True

I think that the "blended" array (at line 173) isn't picking up the 'world_boundaries' properly.

vending_machine=food not rendered

I think it would be beneficial if vending machines (especially e.g. for food or drinks) are also displayed in Mapnik.
Partly the vending machines replace small grocery stores, and since even dog excrement machines are displayed, I am strongly in favor of also displaying other vending machines, which - according to my impression in my area - are increasing strongly lately.

RuntimeError: failed to initialize projection

I have cloned mapnik-stylesheets project.
I have installed python-mapnik.

I have this error when running ./generate_image.py:

RuntimeError: failed to initialize projection with: '&srs900913;' in Map of 'osm.xml'

generate_tiles grumpy about maximum-scale-denominator?

Am I not meant to use this xml file?

RuntimeError: Unable to process some data while parsing '/home/arch/openstreetmap-carto/osm.xml':
* attribute 'maximum-scale-denominator' with value '25000000' at line 0
* attribute 'minimum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '50000' at line 0
* attribute 'maximum-scale-denominator' with value '25000000' at line 0
* attribute 'maximum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '3000000' at line 0
* attribute 'minimum-scale-denominator' with value '200000' at line 0
* attribute 'maximum-scale-denominator' with value '200000' at line 0
* attribute 'maximum-scale-denominator' with value '1000000000' at line 0
* attribute 'minimum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '25000000' at line 0
* attribute 'maximum-scale-denominator' with value '25000000' at line 0
* attribute 'maximum-scale-denominator' with value '50000' at line 0
* attribute 'maximum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '50000' at line 0
* attribute 'maximum-scale-denominator' with value '200000' at line 0
* attribute 'maximum-scale-denominator' with value '200000' at line 0
* attribute 'maximum-scale-denominator' with value '5000' at line 0
* attribute 'maximum-scale-denominator' with value '200000' at line 0
* attribute 'maximum-scale-denominator' with value '50000' at line 0
* attribute 'maximum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '3000000' at line 0
* attribute 'maximum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '50000' at line 0
* attribute 'maximum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '12500' at line 0
* attribute 'maximum-scale-denominator' with value '3000000' at line 0
* attribute 'maximum-scale-denominator' with value '25000' at line 0
* attribute 'maximum-scale-denominator' with value '50000' at line 0
* attribute 'maximum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '50000' at line 0
* attribute 'maximum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '25000' at line 0
* attribute 'maximum-scale-denominator' with value '200000' at line 0
* attribute 'maximum-scale-denominator' with value '12500000' at line 0
* attribute 'minimum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '200000' at line 0
* attribute 'maximum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '400000' at line 0
* attribute 'maximum-scale-denominator' with value '2500' at line 0
* attribute 'maximum-scale-denominator' with value '400000' at line 0
* attribute 'maximum-scale-denominator' with value '500000000' at line 0
* attribute 'minimum-scale-denominator' with value '50000000' at line 0
* attribute 'maximum-scale-denominator' with value '50000000' at line 0
* attribute 'minimum-scale-denominator' with value '400000' at line 0
* attribute 'maximum-scale-denominator' with value '400000' at line 0
* attribute 'minimum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '12500' at line 0
* attribute 'maximum-scale-denominator' with value '50000' at line 0
* attribute 'maximum-scale-denominator' with value '3000000' at line 0
* attribute 'maximum-scale-denominator' with value '12500' at line 0
* attribute 'maximum-scale-denominator' with value '200000000' at line 0
* attribute 'maximum-scale-denominator' with value '100000000' at line 0
* attribute 'minimum-scale-denominator' with value '12500' at line 0
* attribute 'maximum-scale-denominator' with value '50000000' at line 0
* attribute 'maximum-scale-denominator' with value '50000000' at line 0
* attribute 'minimum-scale-denominator' with value '12500' at line 0
* attribute 'maximum-scale-denominator' with value '200000' at line 0
* attribute 'maximum-scale-denominator' with value '200000' at line 0
* attribute 'maximum-scale-denominator' with value '400000' at line 0
* attribute 'maximum-scale-denominator' with value '400000' at line 0
* attribute 'maximum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '12500' at line 0
* attribute 'maximum-scale-denominator' with value '50000' at line 0
* attribute 'maximum-scale-denominator' with value '750000' at line 0
* attribute 'minimum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '25000' at line 0
* attribute 'maximum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '25000' at line 0
* attribute 'maximum-scale-denominator' with value '400000' at line 0
* attribute 'maximum-scale-denominator' with value '25000' at line 0
* attribute 'maximum-scale-denominator' with value '1000000000' at line 0
* attribute 'minimum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '750000' at line 0
* attribute 'maximum-scale-denominator' with value '50000' at line 0
* attribute 'maximum-scale-denominator' with value '5000' at line 0
* attribute 'maximum-scale-denominator' with value '5000' at line 0
* attribute 'maximum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '400000' at line 0
* attribute 'maximum-scale-denominator' with value '100000' at line 0
* attribute 'maximum-scale-denominator' with value '50000' at line 0
* attribute 'maximum-scale-denominator' with value '5000' at line 0

How do I make mapnik to produce meta tiles e.g. 2x2, 4x4 or 8x8 (using generate_tiles.py)

I have read many places that mapnik will generate tiles faster if the tile cover a larger map area.
So instead of producing png tiles that are 256x256 pixlels (BASETILE), mapnik can (I believe) produce meta tiles (png) which consist of e.g. 4 (BASETILE's) so the resulting meta tile is 512 x 512 pixels. I have also read many places that instead of generating 2x2 meta tiles, one can produce e.g. 4 x 4 or 8 x 8 meta tiles - which will speed up the generation of the tiles even more.
Would appreciate if someone could explain how this can be done - when using generate_tiles.py, and eventually a modified version of mapnik (if needed). After the generation of the meta tiles, it would be needed to split the meta tiles into "normal" tile size of 256 x 256 png files - with the correct directory structure and file names.

Can changes be contributed here?

Is this repository capable of being synced up to the SVN repo? Are there any plans (please, god, I hope) to use 'just git' for this and not have to deal with SVN for this project?

extent-deg switch?

It could useful if you can insert the extent as min-longitude, min‐latitude, max-longitude, max-latitude, as for osm2pgsql.

`ST_Estimated_Extent` renamed to `ST_EstimatedExtent`

Hi, I am using the generate_image.py script as I would like to generate some image files for printing.
I should emphasize that I barely know what I am doing: I don't work with GIS and I am winging it.

The problem I encountered is that, upon calling render, some PostGIS function is called that does not exist:

Traceback (most recent call last):
  File "/generate_image.py", line 70, in <module>
    mapnik.render(m, im)
RuntimeError: Postgis Plugin: ERROR:  function st_estimated_extent(unknown, unknown) does not exist
LINE 1: ..._YMin(ext),ST_XMax(ext),ST_YMax(ext) FROM (SELECT ST_Estimat...
                                                             ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
in executeQuery Full sql was: 'SELECT ST_XMin(ext),ST_YMin(ext),ST_XMax(ext),ST_YMax(ext) FROM (SELECT ST_Estimated_Extent('planet_osm_polygon','way') as ext) as tmp'

This query, which returns the user functions

select n.nspname as function_schema,
       p.proname as function_name,
       l.lanname as function_language,
       pg_get_function_arguments(p.oid) as function_arguments,
       t.typname as return_type
from pg_proc p
left join pg_namespace n on p.pronamespace = n.oid
left join pg_language l on p.prolang = l.oid
left join pg_type t on t.oid = p.prorettype 
where n.nspname not in ('pg_catalog', 'information_schema') and p.proname like '%estimate%extent%'
order by function_schema,
         function_name;

returns

 function_schema |   function_name    | function_language |    function_arguments     | return_type
-----------------+--------------------+-------------------+---------------------------+-------------
 public          | st_estimatedextent | c                 | text, text, text, boolean | box2d
 public          | st_estimatedextent | c                 | text, text, text          | box2d
 public          | st_estimatedextent | c                 | text, text                | box2d
(3 rows)

It seems that the function was renamed at some point in the past.
I was able to find a closed issue in the Mapnik repo but I am not sure how to take it from there.

Any help would be appreciated!
FYI, I am running on Windows 10, PostgreSQL 13 and PostGIS 3.1.0.

Proposed features

Hi!

Is it possible to change rendering of "proposed" features? IMHO: currrent version of "proposed" features is quite heavy. Sometimes it can take years (or decades) to build proposed railways or highways.

I suggest that proposed highways will be only dashlines as outerlines (no fill at all).

P

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.