I’m posting this for anyone who’s had a hard time getting Mapnik installed
along with some handy utilities on Ubuntu 9.04. Here we go.
Mapnik from Source
Update the package listing and then upgrade all packages:
apt-get update apt-get upgrade
After that install the dependencies:
sudo apt-get install g++ cpp \ libboost1.35-dev libboost-filesystem1.35-dev \ libboost-iostreams1.35-dev libboost-program-options1.35-dev \ libboost-python1.35-dev libboost-regex1.35-dev \ libboost-thread1.35-dev \ libxml2 libxml2-dev \ libfreetype6 libfreetype6-dev \ libjpeg62 libjpeg62-dev \ libltdl7 libltdl7-dev \ libpng12-0 libpng12-dev \ libgeotiff-dev libtiff4 libtiff4-dev \ libcairo2 libcairo2-dev python-cairo python-cairo-dev \ libcairomm-1.0-1 libcairomm-1.0-dev \ ttf-dejavu ttf-dejavu-core ttf-dejavu-extra \ libgdal1-dev python-gdal \ postgresql-8.3-postgis postgresql-8.3 \ postgresql-server-dev-8.3 postgresql-contrib-8.3 \ libsqlite3-dev \ subversion build-essential
Now we need to get the Mapnik source from the repository:
mkdir -v ~/src cd ~/src svn co http://svn.mapnik.org/trunk mapnik cd mapnik
After that we can configure and build Mapnik:
python scons/scons.py configure INPUT_PLUGINS=all \ OPTIMIZATION=3 \ SYSTEM_FONTS=/usr/share/fonts/truetype/ttf-dejavu/ python scons/scons.py sudo python scons/scons.py install sudo ldconfig
Now we’ll do a quick test to see if Mapnik installed correctly:
python # will start the python interpreter >>> import mapnik >>> exit()
If the import mapnik line didn’t spit out any errors, everything is probably ok.
Setting Up the Database
First we need to tweak some configuration files. Open
/etc/postgresql/8.3/main/postgresql.conf with your favourite
text edit and modify the following lines:
shared_buffers = 128MB
checkpoint_segments = 20
maintenance_work_mem = 256MB
autovacuum = offNext edit /etc/sysctl.conf and add the following at the end:
kernel.shmmax=268435456Now to avoid a reboot, we’ll update the kernel like this:
sudo sh -c 'echo 268435456 >/proc/sys/kernel/shmmax'
Then restart the PostgreSQL server:
sudo /etc/init.d/postgresql-8.3 restart
The next thing we need to do is create the database. Substitute
“your_user” below with your user name. Note: If your user name is ‘user’ you might get an error from the commands below, I did when I tried.
sudo -u postgres -i createuser -s your_user createdb -E UTF8 -O your_user gis createlang plpgsql gis exit
Now setup PostGIS on our database:
psql -d gis -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql
And then change some permissions on the database:
echo "ALTER TABLE geometry_columns OWNER TO your_user; ALTER TABLE spatial_ref_sys OWNER TO your_user;" | psql -d gis
Now we’ll enable the intarray module:
psql gis < /usr/share/postgresql/8.3/contrib/_int.sql
Installing Some Extra Tools
The tools we’ll be installing here are useful for working with OpenStreetMap
data and also to facilitate generating maps with Mapnik.
OSM2PGSQL
This utility will import OpenStreetMap data files into the PostGIS database. First we’ll install some dependencies:
sudo apt-get install build-essential libxml2-dev libgeos-dev libpq-dev libbz2-dev proj
And then checkout the latest version from the repository:
cd ~/src svn co http://svn.openstreetmap.org/applications/utils/export/osm2pgsql/ cd osm2pgsql make
Mapnik-Tools
We’re going to put this right in our home directory:
cd ~ svn co http://svn.openstreetmap.org/applications/rendering/mapnik/
Setting up the World
Now we’re going to grab some boundaries data for the world.
cd ~/mapnik wget http://tile.openstreetmap.org/world_boundaries-spherical.tgz wget http://tile.openstreetmap.org/processed_p.tar.bz2 wget http://tile.openstreetmap.org/shoreline_300.tar.bz2
We’ll extract them each into ~/mapnik/world_boundaries:
tar xfv world_boundaries-spherical.tgz rm -v world_boundaries-spherical.tgz mv -v processed_p.tar.bz2 shoreline_300.tar.bz2 world_boundaries/ cd world_boundaries tar xfv processed_p.tar.bz2 tar xfv shoreline_300.tar.bz2 rm -v processed_p.tar.bz2 shoreline_300.tar.bz2
Importing Some Data
The last thing we’re going to do is put some OpenStreetMap data into our database. You can either import the whole planet:
cd ~ wget http://ftp.heanet.ie/mirrors/openstreetmap.org/planet-latest.osm.bz2
But it’s a HUGE file, so if you just want to have a smaller part of the world,
you can use extracts. To create your own extracts, read this tutorial. Otherwise
grab an extract for your area of interest from somewhere (ex.CloudMade). You’ll want to download the file ending in .osm.bz2. In my example I’ll be using british_columbia.osm.bz2.
cd ~ wget http://downloads.cloudmade.com/north_america/canada/british_columbia/british_columbia.osm.bz2
We just need to import the data into the database now, for this we’ll use osm2pgsql which we installed earlier.
cd ~/src/osm2pgsql ./osm2pgsql --slim -d gis ~/british_columbia.osm.bz2
And there you have it. If you want to test this out from the command line, you
can use the last portion of this tutorial, or to use python, try the examples here.
Resources
Most of this tutorial was ripped directly off from the following sites:

October 30th, 2009 at 12:45 am
This error occured on the svn fetch:
mkdir -v ~/src
cd ~/src
svn co http://svn.mapnik.org/trunk mapnik
svn: REPORT of ‘/!svn/vcc/default’: Could not read response body: connection was closed by server (http://svn.mapnik.org)
cd mapnik
This disturbs me.
December 22nd, 2009 at 10:29 pm
I tried this installation method with a fresh install of Ubuntu 9.04. The installation stops at the configuration of mapnik.
The python script tells me that boost 1.41 is required.
January 9th, 2010 at 8:32 am
Sorry it took me so long to respond. I’ve been preoccupied lately and I didn’t notice your valid comments in the sea of robo-spam.
@Bruce Johnson
I just tried the SVN checkout command on my machine, it worked properly. I’m not sure what the problem could be, I don’t know that much about SVN.
@Bikeman200
It looks like Mapnik changed it’s dependencies to a newer version of the Boost stuff. According to ‘http://trac.mapnik.org/wiki/UbuntuInstallation’ they use ‘libboost-*1.40-dev’ packages now.
January 20th, 2010 at 9:41 pm
I already postet this in the OSM forum and somebody told me a working solution checking out the mapnik branch 0.7
http://forum.openstreetmap.org/viewtopic.php?id=5797
May 10th, 2010 at 6:07 pm
Hey, thank you very much for this!
May 23rd, 2010 at 9:22 pm
iam having fedora 10 core so can u help me how to build toolchain for arm processor or systametic steps for building toolchain of arm processor on…
May 23rd, 2010 at 9:30 pm
fedora,
I’ve not built anything for ARM processors, but I believe the excellent BuildRoot scripts/system will be helpful in getting a toolchain setup. I’ve used it for x86 and it worked quite well. It can use the small uClibc or the regular GNU libc.
Here’s the address: http://buildroot.uclibc.org/