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:
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):
(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:
Thanks for your help! asked 02 Aug '13, 12:37 Fractal |
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! answered 02 Aug '13, 18:07 Andy Allan |
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. answered 02 Aug '13, 16:35 Frederik Ramm ♦ |
There is a detailed description on TopoMapCreator about How to render OSM data with TileMill on Windows. answered 01 Nov '14, 10:09 kaki007 |