You have mapnik installed and a running python installation on your computer. The next step is to gather the data from OSM.

You can export data directly from manually:

  1.  Go to
  2.  Search your location or the area you wish to export.
  3.  Click on export on top left corner of your screen.
  4.  Select area manually.
  5.  Click on export.

NOTE: while exporting data manually you have to change longitudes and latitudes in file you will create later.

If you want to download large data easily then, go to or

I have Downloaded Ludhiana map manually from with ( min longitude, min latitude, max longitude, min latitude) value : (75.0833,30.4866,76.4182,31.3935)

Create the main xml file which contains instructions for mapnik about the contents of the map and how to render them. Create the file mapnik_style.xml with the following content:

<?xml version="1.0" encoding="utf-8"?>
<Map background-color="#f2efe9" srs="+proj=latlong +datum=WGS84">
 <FontSet name="book-fonts">
 <Font face-name="DejaVu Sans Book" />
 <Style name="highways">
 <Filter>[highway] &lt;&gt;''</Filter>
 <LineSymbolizer stroke="#808080" stroke-width="2" stroke-linejoin="round"
 stroke-linecap="round" />

 <Filter>[highway] &lt;&gt;''</Filter>
 <TextSymbolizer name="[name]" fontset-name="book-fonts" size="9" fill="#0000" halo-radius="1" placement="line" />
 <Layer name="highways" status="on" srs="+proj=latlong +datum=WGS84">
 <Parameter name="type">osm</Parameter>
 <Parameter name="file">ldh.osm</Parameter>

Finally, we have to tell mapnik to render the map using the style file. Create a python script with following content:

#!/usr/bin/env python2

from mapnik import *

mapfile = 'mapnik_style.xml'
map_output = 'mymap.png'

m = Map(4*1024,4*1024)
load_map(m, mapfile)
bbox=(Envelope( 75.0833,30.4866,76.4182,31.3935 ))

print "Scale = " , m.scale()
render_to_file(m, map_output)

NOTE: while exporting data manually you have to change longitudes and latitudes in file.

Now run command: python

Problems faced:

The rendered image turned out to be blank.


Latitudes and longitudes has to be changed when you change datasource. In bbox=(Envelope( 75.0833,30.4866,76.4182,31.3935 )) the format (min long, min lat, max long, max lat) should be followed.



Data exported from manually. Map area is ludhiana.


To add details to image edit xml file. Replace LineSymbolizer with following:

<TextSymbolizer face-name="DejaVu Sans Book" size="16" placement="point" dy="8" fill="blue" placement-type="list">[name]
    <Placement size="10" dy="-8" fill="red"/><!-- Reduces text size and changes offset -->
    <Placement fill="green">[abbreviated_name]</Placement> <!-- size="10", dy="-8", fill="green", shorter text -->
    <Placement fill="orange" dy="8">[nr]</Placement> <!-- size="10", dy="8", fill="orange", shortest text -->

This change will give Output:


Zooming the above image we can see names of different locations.


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