OpenStreetMap

skaiwalker's Diary

Recent diary entries

Creating maptiles with german style offline using mapnik and Ubuntu 12.04 LTS

Posted by skaiwalker on 28 December 2012 in English. Last updated on 30 December 2012.

Please note

This post is obsolete and uses rather dirty methods. I added a quickstart guide to the README file in the mapnik-german repository, which should be used. However, this post might still be valuable for troubleshooting.

First, try to make Mapnik run using this guide:
http://wiki.openstreetmap.org/wiki/Mapnik#Installation

In case things don’t work, you might find clues there:
http://forum.openstreetmap.org/viewtopic.php?pid=253552
http://wiki.openstreetmap.org/wiki/Mapnik/PostGIS
http://switch2osm.org/serving-tiles/manually-building-a-tile-server-12-04/

In any case, you want to use the latest available sofware, but you do not need to compile from source. There are PPAs.

Install necessary software

#### Mapnik Uninstall any python-mapnik or python-mapnik2 packages from your system (https://github.com/mapnik/mapnik/wiki).

    sudo add-apt-repository ppa:mapnik/v2.1.0
    sudo apt-get update
    sudo apt-get install libmapnik mapnik-utils python-mapnik #[!sic]

osm2pgsql

    sudo add-apt-repository ppa:kakrueger/openstreetmap
    sudo apt-get update
    sudo apt-get install osm2pgsql

postgis

    sudo apt-get install postgis postgresql postgresql-9.1-postgis

Set-up data base

    sudo -u postgres createdb -E UTF8 -O postgres osm
    sudo -u postgres createlang plpgsql osm
    sudo -u postgres psql osm < /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
    sudo -u postgres psql osm < /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql

Create user with YOUR name (somehow only works like this) postgis superuser? yes

    sudo -u postgres createuser -P YOURUSERNAME

Now, get a map file. These are available at e.g.
http://download.geofabrik.de/openstreetmap/

    wget http://download.geofabrik.de/openstreetmap/europe/germany/sachsen.osm.bz2
    unp sachsen.osm.bz2

Finally, import your image into the database

    osm2pgsql -m -d osm -S /usr/share/osm2pgsql/default.style -W  sachsen.osm

In case of the german scripts, you either need to edit default.style a little or work with the views. The views seem to be necessary when still working with the default OSM style.

    # default.style
    #
    node,way	3dshapes:ggmodelk	text	delete
    node,way	AND_nosr_r	text	delete
    node,way	b5m:*	text	delete
    node,way	bak:*	text	delete
    node,way	canvec:*	text	delete
    node,way	created_by	text	delete
    node,way	dcgis:*	text	delete
    node,way	FIXME	text	delete
    node,way	geobase:*	text	delete
    node,way	gnis:*	text	delete
    node,way	kms:*	text	delete
    node,way	KSJ2:*	text	delete
    node,way	massgis:*	text	delete
    node,way	mvdgis:*	text	delete
    node,way	naptan:*	text	delete
    node,way	ngbe:*	text	delete
    node,way	nhd:*	text	delete
    node,way	NHD:*	text	delete
    node,way	note	text	delete
    node,way	note:*	text	delete
    node,way	notes	text	delete
    node,way	osak:*	text	delete
    node,way	source	text	delete
    node,way	source:*	text	delete
    node,way	sourcedb:*	text	delete
    node,way	tiger:*	text	delete
    node,way	WroclawGIS:*	text	delete
    node,way	yh:*	text	delete
    node,way	rednap:* text	delete
    node,way	ideewfs:* text	delete
    node,way	ign:* text	delete

    node,way   aerialway    text         linear
    node,way   addr:housenumber text     linear
    node,way   aeroway      text         polygon
    node,way   amenity      text         nocache,polygon
    node,way   barrier      text         linear
    node,way   boundary     text         linear
    node,way   building     text         polygon
    node,way   highway      text         linear
    node,way   historic     text         polygon
    node,way   landuse      text         polygon
    node,way   leisure      text         polygon
    node,way   lock         text         linear
    node,way   man_made     text         polygon
    node,way   military     text         polygon
    node,way   place        text         polygon
    node,way   power        text         polygon
    node,way   railway      text         linear
    node,way   route        text         linear
    node,way   shop         text         polygon
    node,way   tourism      text         polygon
    node,way   waterway     text         polygon
    node,way   natural      text         polygon

    node,way   width        real         linear
    node       ele          real         linear

    node,way   z_order      int4         linear # This is calculated during import
    way        way_area     real                # This is calculated during import

    # Needed additions for german style to work
    node,way   wood     text         polygon
    node,way   name:de        text         linear
    node,way   name        text         linear
    node,way   religion        text         linear
    node,way   tunnel        text         linear
    node,way   disused        text         linear
    node,way   bridge        text         linear
    node,way   horse      text         linear
    node,way   foot      text         linear
    node,way   bicycle      text         linear
    node,way   tracktype      text         linear
    node,way   construction      text         linear
    node,way   proposed      text         linear
    node,way   service      text         linear
    node,way   access      text         linear
    node,way   oneway      text         linear
    node,way   layer      text         linear
    node,way   ref     text         linear
    node,way   lcn_ref     text         linear
    node,way   admin_level    text         linear
    node   capital    text         linear
    node,way   generator:source    text         linear
    node,way   power_source    text         linear
    node,way   ruins    text         linear
    node,way   addr:flats   text         polygon
    node,way   addr:interpolation  text  linear
    node,way   addr:housename  text  linear

    node,way   rcn_ref     text     linear
    node,way   ncn_ref     text     linear
    way       lcn          text     linear
    way       rcn          text     linear
    way       ncn          text     linear
    #way       lwn_ref      text     linear
    #way       rwn_ref      text     linear
    #way       nwn_ref      text     linear
    way       lwn              text     linear
    way       rwn              text     linear
    way       nwn              text     linear
    #way       route_pref_color text     linear
    way       route_name       text     linear
    way       network          text     linear
    way       surface          text     linear
    way       voltage          text     linear
    way       line             text     linear
    node      public_transport text     linear
    node      information      text     linear
    node      bus              text     linear
    node      tram             text     linear
    node      hiking           text     linear

Rendering tiles

#### Getting style files Standard OSM:

    svn checkout http://svn.openstreetmap.org/applications/rendering/mapnik

German OSM style:

    svn checkout http://svn.openstreetmap.org/applications/rendering/mapnik-german/

Follow the README files in there until you get to generate_xml.py:

     ./generate_xml.py --dbname osm --host 'localhost' --user YOURUSERNAME --port 5432 --password 'YOURPWD'  osm-de.xml > osm-local.xml 

If there are no errors, you may edit the generate_tiles.py (make sure it uses the right osm-local.xml) and run it

     ./generate_tiles.py

Problems

#### hstore in postgis In some cases you want to use the –hstore option (-k) to store additional info (see osm2pgsql -h).

    osm2pgsql -m -k -d osm -S /usr/share/osm2pgsql/default.style -W  sachsen.osm

In that case, postgis needs to know that.

    sudo -u postgres psql
    CREATE EXTENSION hstore;

world boundaries

Get the missing ones from http://www.mmnt.net/db/0/0/195.16.220.82/pub/osm/mapnik-data-files/world_boundaries

    wget ftp://195.16.220.82/pub/osm/mapnik-data-files/world_boundaries/110m_admin_0_boundary_lines_land.dbf
    wget ftp://195.16.220.82/pub/osm/mapnik-data-files/world_boundaries/110m_admin_0_boundary_lines_land.shp

flooded cities

If you see a lot of water in the rendered images, then you downloaded the wrong (WGS84) projection of the land-polygons.
Use the Mercator projection http://openstreetmapdata.com/data/land-polygons

fontset-settings.xml.inc

Errors with unifont Medium - comment out offending lines from fontset-settings.xml.inc.

    <!--
    <Font face-name="unifont Medium" />
    -->