Mapping server



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


Install Mapnik

aptitude install python-mapnik2

Confirm Mapnik Install

# python
>>> import mapnik2

Openstreetsmap Mapnik (ref)

git clone git://


cd mapnik-stylesheets

Download the mapping data for the country of your choice (or everything from (ref)


Download the additional data-files to be used when generating maps (ref):

wget # (50 MB)
wget # (349 MB)
wget # (44 MB)
wget # (39 KB)

Extract the files using the following commands;

cd ~/mapnik-stylesheets # or whatever directory you put the project in
tar xzf world_boundaries-spherical.tgz
tar xjf processed_p.tar.bz2 -C world_boundaries
tar xjf shoreline_300.tar.bz2 -C world_boundaries
unzip -d world_boundaries
unzip -d world_boundaries
cd world_boundaries
ln -s ne_110m_admin_0_boundary_lines_land.shp 110m_admin_0_boundary_lines_land.shp
ln -s ne_110m_admin_0_boundary_lines_land.dbf 110m_admin_0_boundary_lines_land.dbf
cd ../

Get the default style


 Postgres / PostGIS

Configure / finish setting up PostGIS DB (ref)

sudo apt-get install postgresql-9.1-postgis postgresql-contrib-9.1
sudo -u postgres -i -H
createuser -SdR gisuser
createdb -E UTF8 -O gisuser gis
createlang plpgsql gis
psql -d gis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql
  # to populate the table spatial_ref_sys (mandatory for use with osm2pgsql):
  psql -d gis -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql

# common for all three
psql gis -c "ALTER TABLE geometry_columns OWNER TO gisuser"
psql gis -c "ALTER TABLE spatial_ref_sys OWNER TO gisuser"

To enable easy database login by user gisuser you must change some lines in one of the database configuration files.

sudo pico /etc/postgresql/9.1/main/pg_hba.conf

Near to the bottom of the file you will find these lines:

local   all         all                               ident
host    all         all          md5

Change the words ident and md5 each to trust and close the editor. Now reload the database configuration:

sudo /etc/init.d/postgresql reload

For a short test, login to the database by using the previously created database user gisuser:

psql gis gisuser

Type \d to see a list with the two tables which we have created some minutes ago (geometry_columns and spatial_ref_sys), then logout with: \q


Tuning the PostGIS database (ref)

edit /etc/postgresql/9.1/main/postgresql.conf in four places. These changes help with the large quantities of data that we are using.

shared_buffers = 128MB
checkpoint_segments = 20
maintenance_work_mem = 256MB # 256000 for 8.1 and earlier 
autovacuum = off

Edit kernel parameter shmmax to increase maximum size of shared memory.

sudo sysctl -w kernel.shmmax=268435456
sudo sysctl -p /etc/sysctl.conf 

Restart postgres to enable the changes

sudo /etc/init.d/postgresql restart

It should restart as above.

* Restarting PostgreSQL 8.4 database server


Import the OSM file
 for your country (this will take some time)

sudo -u postgres osm2pgsql -d gis -S --slim -m australia.osm.pbf [file2 ...]


Configure Mapnik Style files

./ --host localhost --user gisuser --dbname gis --symbols ./symbols/ --world_boundaries ./world_boundaries/ --accept-none



sudo apt-get install libagg-dev svn co cd mod_tile make
make install

Errors about APXS2 can be cured by installing:

apt-get install apache2-threaded-dev

Then create a load file for the apache module

pico /etc/apache2/mods-available/tile.load

Insert the following:

LoadModule tile_module /usr/lib/apache2/modules/


Configure mod_tile / renderd

ln -s /home/victor/osm/renderd /var/lib/mod_tile

Download the fonts from and extract the font files (*.ttf) to /usr/local/lib/mapnik/fonts dir

mv dejavu-fonts-ttf-2.33.tar.bz2\?r\=http\\?title\=Download dejavu-fonts.tar.bz2
tar xvf dejavu-fonts.tar.bz2
mv dejavu-fonts-ttf-2.33 /usr/local/lib/mapnik/fonts

Edit /etc/renderd.conf


Create /etc/init.d/renderd with the following contents:

#!/bin/sh -e
# Renderd startup script
#chkconfig: 2345 80 05
#description: Renderd

# Define some variables
# Name of app ( abc / def / blah / etc )
# Name of the user to run as
# Location of application's bin directory

case "$1" in
  # Start command
    echo "Starting $APP"
    /bin/su -m $USER -c "$BIN_DIR/renderd &> /dev/null"
  # Stop command
#    echo "Stopping $APP"
#    echo "$APP stopped successfully"
   # Restart command
        $0 stop
        sleep 5
        $0 start
    echo "Usage: /etc/init.d/$APP {start|restart|stop}"
    exit 1

exit 0


Enable auto-updating of the map server

Leave a Reply