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

I’m trying to render a map using Mapnik and PostGIS, I feel I’m close but it doesn’t work yet. Here is what I’ve done so far (it’s the first time I work with a database, so it’s likely that there are stupid mistakes due to the fact that I don’t know how databases work).

I’m working in Arch Linux with Mapnik 2.2.0, PostgreSQL 9.2.4, PostGIS 2.0.3 and osm2pgsql-git 20130512.

I downloaded the montpellier.osm.pbf file from http://metro.teczno.com/#montpellier (I didn’t download any coastline file, for now I’m just trying to render some part in the middle of a city). I created a database with PostGIS enabled and imported the pbf file (using osm2pgsql), using various instructions on the Wiki. I don’t fully understand the various usernames needed for a PostgreSQL database, but I think the main PostgreSQL username is "postgres" and the other username (not sure what this one is for) is my Unix login ("fractal"). Anyway, the import seems to have done something (it took something like an hour to complete) and I have the following:

$ psql --username=postgres --dbname=osm --command="\d+"
                           List of relations
 Schema |        Name        | Type  |  Owner   |  Size   | Description 
--------+--------------------+-------+----------+---------+-------------
 public | geography_columns  | view  | postgres | 0 bytes | 
 public | geometry_columns   | view  | postgres | 0 bytes | 
 public | planet_osm_line    | table | postgres | 32 kB   | 
 public | planet_osm_nodes   | table | postgres | 104 kB  | 
 public | planet_osm_point   | table | postgres | 24 kB   | 
 public | planet_osm_polygon | table | postgres | 24 kB   | 
 public | planet_osm_rels    | table | postgres | 2184 kB | 
 public | planet_osm_roads   | table | postgres | 16 kB   | 
 public | planet_osm_ways    | table | postgres | 141 MB  | 
 public | spatial_ref_sys    | table | postgres | 3216 kB | 
(10 rows)

So it seems that the database has been populated with stuff.

Then I tried to adapt the tutorial at http://wiki.openstreetmap.org/wiki/Mapnik:_Rendering_OSM_XML_data_directly. I downloaded the style file there, made it compatible with Mapnik 2, changed various details, and tried to change the datasource from XML to PostGIS. What I have now is the following (in the file test.xml):

http://pastebin.archlinux.fr/467464

(I looked at the OSM style files to see what kind of parameters are needed for postgis)

Then I have the following Python script (adapted from the other tutorial):

!/usr/bin/env python2

from mapnik import *

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

m = Map(4*1024,4*1024)
load_map(m, mapfile)
bbox=(Envelope( 3.873,43.603,3.878,43.606 ))

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

(the bounding box is supposed to be a place with several roads)

When I run the script, there are no error and the mymap.png file is created, but it’s completely yellow (the background color in the style file) with no road. Maybe that’s because there is a problem with the connection to the database, but I don’t know how to fix it. I also tried with planet_osm_line instead of planet_osm_roads (I’m not sure where the highways are supposed to be) but it’s the same, and I tried with planet_osm_ways but it failed with the error:

RuntimeError: PostGIS: geometry name lookup failed for table 'planet_osm_ways'. Please manually provide the 'geometry_field' parameter or add an entry in the geometry_columns for 'planet_osm_ways'.

Thanks for your help!

asked 02 Aug '13, 12:37

Fractal's gravatar image

Fractal
76336
accept rate: 0%


Don't try to use the approach described in http://wiki.openstreetmap.org/wiki/Mapnik:_Rendering_OSM_XML_data_directly . It reads the OSM XML file directly using a broken, unsupported and likely-to-be-removed input plugin for Mapnik. The first steps, where you use osm2pgsql to load the OSM data into postgresql, are the correct steps.

When you have the data loaded in your database, there are two general approaches.

1) Use command-line tools. nik2img.py is the swiss army knife of command-line mapnik image generation, and is basically a fully-working version of the script you'd start writing yourself. You need a stylesheet to go with it, and I'd suggest openstreetmap-carto.

2) Use a graphical interface. Tilemill is the best approach. When you have that installed, you can either create your own stylesheet and add your layers from postgis, or use a pre-created stylesheet. I'd again suggest openstreetmap-carto or osm-bright, which are both Tilemill-compatible stylesheets for OSM data which has been loaded into postgis.

But overall, avoid the osm input plugin and anything related to it - it's a dead-end!

permanent link

answered 02 Aug '13, 18:07

Andy%20Allan's gravatar image

Andy Allan
12.5k23128153
accept rate: 28%

planet_osm_ways is a table without geometry so the error is not a surprise. planet_osm_line should work for your purpose. Your error is probably that your import has generated a database with projected coordinates, but in your script you're requesting an unprojected area. Compare your script to http://svn.openstreetmap.org/applications/rendering/mapnik/generate_image.py and make sure to reproject your coordinates before using m.zoom_to_box like it is done there.

permanent link

answered 02 Aug '13, 16:35

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

-1

There is a detailed description on TopoMapCreator about How to render OSM data with TileMill on Windows.

permanent link

answered 01 Nov '14, 10:09

kaki007's gravatar image

kaki007
(suspended)
accept rate: 0%

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:

×440
×341
×134

question asked: 02 Aug '13, 12:37

question was seen: 16,186 times

last updated: 01 Nov '14, 10:09

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