1
1

Hi there, I am following tutorials to learn about OSM and how to make some maps. Currently I am using this one, https://github.com/mapnik/mapnik/wiki/GettingStartedInPython 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

lgxtlm
11113
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()
  r.symbols.append(symbolizer)
  s.rules.append(r)
  m.append_style(name,s)
  # 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)
  layer.styles.append(name)
  m.layers.append(layer)
  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',
  symbolizer=mapnik.LineSymbolizer(mapnik.Color('rgb(0,0,0)'),2))
permanent link

answered 27 Feb '12, 10:47

NicolasDumoulin's gravatar image

NicolasDumoulin
3.2k42256
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: generate_image.py and generate_tiles.py 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
9.2k2486126
accept rate: 13%

edited 27 Feb '12, 16:00

Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×308
×190
×141
×117
×23

question asked: 20 Feb '12, 13:09

question was seen: 6,295 times

last updated: 01 Mar '12, 10:12

powered by OSQA