NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum


Hi there, I am following tutorials to learn about OSM and how to make some maps. Currently I am using this one, but in the instructions it uses shapefiles as a datasource just in a normal file directory. I don’t want to do that, I want the file source to be from my database in PostGIS, where I have stored my OSM data. What do I need to do to make it do that? I tried:

lyr = Layer('Geometry from PostGIS') lyr.datasource = PostGIS(host='localhost',user='postgres',password='',dbname='your_postgis_database',table='your_table')

which I copied off one of the wiki pages. Obviously I amended details as appropriate, but it just said layer not recognised. I wondered if there way something I had to do or tell it to do to get into the database?

In the literature I have read, it says that using PostGIS is one of the most common ways of doing what I want to do, but I cannot seem to find any code to use! Thanks in Advance, Tracey

This question is marked "community wiki".

asked 20 Feb '12, 13:09

lgxtlm's gravatar image

accept rate: 0%

Do you have solve your problem?

(01 Mar '12, 10:12) NicolasDumoulin

Please, give us more of your code. Here is one of my script that was working with mapnik two years ago:

def addLayer(m, name, dbname, table, symbolizer):
  # style creation
  s = mapnik.Style()
  r = mapnik.Rule()
  # layer creation
  layer = mapnik.Layer(name, "+proj=latlong +datum=WGS84")
  layer.datasource = mapnik.PostGIS(host='localhost',port='5434',user='mapnik',password='mapnik',dbname=dbname,table=table)
  return layer
# usage sample
m = mapnik.Map(1000,1500)
m.background = mapnik.Color('white')
projection = "+proj=latlong +datum=WGS84"
addLayer(m, name='data', dbname='osm',
  table='(select way from planet_osm_line) as roads',
permanent link

answered 27 Feb '12, 10:47

NicolasDumoulin's gravatar image

accept rate: 13%

An important choice you're also faced with initially is... Do you want to get the default OpenStreetMap stylesheets working with Mapnik? We have a lot of documentation about how to do this. Unfortunately it's a little more fiddly than some of the basic "Getting started" Mapnik tutorials, and you are more restricted as to which Mapnik version you work with and what your data source types are.

To get the OSM default stylesheet running you must work with PostGIS (as well as some shapefiles for zoomed out world boundaries and coastline), and you must populate the database using osm2pgsql which is also governed by a matching style configuration file. Hopefully a good guide to all this is the Mapnik wiki page. Having done the database loading, there's some python scripts provided: and Playing around with these, you'll get some control within python, but it's not quite the same as the from-scratch tutorial you link to.

...but maybe there's a better half-way-house tutorial involving osm2pgsql and building style rules in python. (Anyone know?)

permanent link

answered 27 Feb '12, 15:59

Harry%20Wood's gravatar image

Harry Wood
accept rate: 14%

edited 27 Feb '12, 16:00

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 20 Feb '12, 13:09

question was seen: 9,522 times

last updated: 01 Mar '12, 10:12

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum