OpenStreetMap Slippy Maps

[an error occurred while processing this directive]

The OpenStreetMap project was started to provide free access to geographic and mapping data. You may be surprised to learn that in some countries, for example the United Kingdom, everyone has to pay to access and use Government collected map data. In addition web based mapping services such as Google and Yahoo are not free to use in the same way as we describe Free Software. OSM was started to provide mapping data, tools, and infrastructure, that are available under Opensource and Free Software licences.

This article describes how to take the weekly planet.osm XML dump file and build an online slippy map, similar to those provided by Google and Yahoo, using Fedora and some additional Free Software mapping tools.

The software

There are a number of different software components requried to build a slippy map. Some you will have heard of or used before such as Python, Apache HTTPD, mod_python, and Postgresql. Others you may have less experiences with.

OpenLayers

OpenLayers is a JavaScript toolkit that makes it simple to create dynamic maps within web pages. It was originally developed by MetaCarta and is available under a BSD licence.

Tilecache

TileCache is another project originally developed by MetaCarta and released under a BSD licence. TileCache is an implementation of a WMS-C compliant server.

Mapnik

Mapnik is a toolkit for developing mapping applications. It's written in C++ and there are Python bindings available. Mapnik is primarily about making beautiful maps.

PostGIS

PostGIS adds support for geographic objects to the PostgreSQL object-relational database. In effect, PostGIS "spatially enables" the PostgreSQL server, allowing it to be used as a backend spatial database for geographic information systems (GIS), much like ESRI's SDE or Oracle's Spatial extension.

Getting the data

There are two large data files you need to download to build your slippy map. These are planet.osm.bz2 and world_boundaries.tar.bz2. You can download these using the commands:

wget http://planet.openstreetmap.org/planet-latest.osm.bz2
wget http://artem.dev.openstreetmap.org/files/world_boundaries.tar.bz2

Install the applications

The software you need to build the slippy map has been packaged for Fedora 7 and is being made available in a Yum repository. First you need to install a single RPM that configures Yum to enable the Passback repository, to do this run the following command as root:

rpm -ivh http://www.passback.org.uk/packages/fedora/7/i386/passback-release-7-1.fc7.noarch.rpm

Then to install the software use the command:

yum install osm-slippymap osm2pgsql

The magic of Yum should pull in all of the required dependencies such as the Apache Web Server and PostgreSQL Database.

Configure the database

First you need to initialise the database and start the postgresql system:

service postgresql initdb
service postgresql start
chkconfig postgresql on

There are a number of steps we need to take to configure the Postgresql database to work with our slippy map. You should run the following commands as the postgres user:

su - postgres

Then run the following commands:

createdb -EUNICODE gis
createuser -S -D -R apache
echo "GRANT ALL ON SCHEMA PUBLIC TO apache;" | psql gis
echo "create language plpgsql;" | psql gis
psql gis < /usr/share/pgsql/contrib/lwpostgis.sql
echo "grant all on geometry_columns to apache;" | psql gis
echo "grant all on spatial_ref_sys to apache;" | psql gis

If you are more of a Postgresql expert than I am then you might want to change things as regards user accounts and permissions.

Populate the database

Still as user postgres we need to convert the planet.osm XML file into SQL and load it into the database. We do this with the following command:

osm2pgsql /path/to/planet-latest.osm.bz2

This command may take some time depending on how fast your machine is. Once the command has finished return to being user root and unpack the World Boundaries files:

cd /usr/share/osm/map
tar jxvf /path/to/world_boundaries.tar.bz2

You can install the world boundaries files in a different location, but if you do you must update the osm.xml file found in /usr/share/osm/map/ so that the world boundaries references are updated.

Start the web server

The last stage is to reload or restart your Apache Web Server so that it picks up the configuration files we have installed:

service httpd restart
chkconfig httpd on

And that is the installation completed!

Accessing the map

Accessing the map is simple, point your web browser at:

http://address.of.server/openstreetmap.html

and enjoy.

Where to go from here

Now that you have a map up and running there are a couple of things you might like to do: