Installing Mapnik And OSM Bright

Installing Mapnik And OSM Bright

Mapnik is an open source mapping toolkit for desktop- and server-based map rendering, written in C++.

One of its many users is the OpenStreetMap project (OSM), which uses it in combination with an Apache Web Server module (mod_tile) to render tiles that make up the OSM ‘Slippy Map’ Layer.

For handling common software tasks such as memory management, file system access, regular expressions, and XML parsing, Mapnik utilizes the Boost C++ libraries.

Mapnik runs on Linux, OS X, Windows, and BSD systems.

There is also an osm2pgsql utility,[4] that converts OpenStreetMap data into a format that can be loaded into PostgreSQL. Mapnik can then be used to render the OSM data into maps with the appearance the user wants.

Install Mapnik library

Wait! Wait! Don’t insert the following commands blindly in the terminal.

Next, we need to install the Mapnik library. Mapnik is used to render the OpenStreetMap data into the tiles used for an OpenLayers web map.

Build the Mapnik library from source:

I insert the following commands as it is.

cd ~/src
git clone git://
cd mapnik
git branch 2.2 origin/2.2.x
git checkout 2.2


python scons/ configure INPUT_PLUGINS=all OPTIMIZATION=3 SYSTEM_FONTS=/usr/share/fonts/truetype/


What is SCons?

SCons is a software construction tool—that is, a superior alternative to the classic “Make” build tool that we all know and love.

SCons is implemented as a Python script and set of modules, and SCons “configuration files” are actually executed as Python scripts. This gives SCons many powerful capabilities not found in other software build tools.


Verify that Mapnik has been installed correctly:

>>> import mapnik


If python replies with the second chevron prompt >>> and without errors, then Mapnik library was found by Python. Congratulations! You can leave Python with this command:

>> quit()

But, the command “import mapnik” was giving me the import error as shown below.

So, after travelling most of the streets of the map of my brain I installed mapnik through the following commands. 😉

sudo apt-get install pip


sudo apt-get install python-pip

pip install mapnik

sudo apt-get install libmapnik-dev libmapnik3.0 mapnik-utils mapnik-vector-tile python-mapnik python3-mapnik

pip is a package management system used to install and manage software packages written in Python. Many packages can be found in the Python Package Index (PyPI)

Congratulations! if you have installed it.

Install mod_tile and renderd


mod_tile – A custom Apache module which is responsible for serving tiles and requests the rendering of tiles if they aren’t already available in cache or if they have changed since.

mod_tile uses Mapnik as a rendering backend.


Compile the mod_tile source code:

cd ~/src
git clone git://
cd mod_tile
sudo chmod 777 -R mod_tile
sudo make install
sudo make install-mod_tile
sudo ldconfig

Download OSM Bright


OSM Bright is a sensible starting point for quickly making beautiful maps based on an OpenStreetMap database. It is written in the Carto styling language and can be opened as a project in TileMill.

The style is still a work in progress and you are encouraged to use the issue tracker to note missing features or problems with the current implementation.

OSM Bright depends on two large shapefiles. You will need to download and extract them before continuing.

Download them to the shp directory in the osm-bright folder. You can do this with wget like:

To begin with, we need to download both the OSM Bright stylesheet, and also the additional data resources it uses (for coastlines and the like).  Again, substitute your username for username in the “chown” command below.

sudo mkdir -p /usr/local/share/maps/style
sudo chown username /usr/local/share/maps/style
cd /usr/local/share/maps/style
mkdir ne_10m_populated_places_simple
cd ne_10m_populated_places_simple
cd ..

We then move the downloaded data into the osm-bright-master project directory:

unzip '*.zip'
mkdir osm-bright-master/shp
mv land-polygons-split-3857 osm-bright-master/shp/
mv simplified-land-polygons-complete-3857 osm-bright-master/shp/
mv ne_10m_populated_places_simple osm-bright-master/shp/


To improve performance, we create index files for the larger shapefiles:

cd osm-bright-master/shp/land-polygons-split-3857
shapeindex land_polygons.shp
cd ../simplified-land-polygons-complete-3857/
shapeindex simplified_land_polygons.shp
cd ../..

Configuring OSM Bright

The OSM Bright stylesheet now needs to be adjusted to include the location of our data files. Edit the file osm-bright/osm-bright.osm2pgsql.mml in your favourite text editor, for example:

gedit osm-bright/osm-bright.osm2pgsql.mml

Find the lines with URLs pointing to shapefiles (ending .zip) and replace each one with these appropriate pairs of lines:

"file": "/usr/local/share/maps/style/osm-bright-master/shp/land-polygons-split-3857/land_polygons.shp", 
"type": "shape"
"file": "/usr/local/share/maps/style/osm-bright-master/shp/simplified-land-polygons-complete-3857/simplified_land_polygons.shp", 
"type": "shape",
"file": "/usr/local/share/maps/style/osm-bright-master/shp/ne_10m_populated_places_simple/ne_10m_populated_places_simple.shp", 
"type": "shape"

Note that we are also adding “type”: “shape” to each one. (If you’re using nano, to save, now press ctrl-X and Y.)

Finally, in the section dealing with “ne_places”, replace the “srs” and “srs-name” lines with this one line:

"srs": "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"

You have configured OSM Bright.

Stay tuned. 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s