Hi all,<br><br>I've been trying to put together my own rendering environment for kicks recently and it's gone reasonably well however I've hit a snag when trying to render with Mapnik from a PostGIS datasource.<br>
<br>My (simple) code is as follows:<br><br><span style="font-family: courier new,monospace;">#!/usr/bin/env python</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">import mapnik</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">mapfile = 'pimlico.xml'</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">map_output = 'pimlico.png'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">m = mapnik.Map(600, 300)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">mapnik.load_map(m, mapfile)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">mapnik.render_to_file(m, map_output)</span><br><br>and the XML config it uses is:<br><br><span style="font-family: courier new,monospace;"><Map bgcolor="#ffffff" srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs -tl -r"></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <Style name="line style 2"></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <Rule></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <LineSymbolizer></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <CssParameter name="stroke">#000000</CssParameter></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <CssParameter name="stroke-width">3.0</CssParameter></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </LineSymbolizer></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </Rule></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </Style></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <Layer name="layer 4" srs="+proj=latlong +ellps=WGS84 +datum=WGS84 +no_defs" status="on"></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <StyleName>line style 2</StyleName></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <Datasource></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <Parameter name="type">postgis</Parameter></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <Parameter name="host">localhost</Parameter></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <Parameter name="user">postgres</Parameter></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <Parameter name="dbname">gis</Parameter></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> <Parameter name="estimate_extent">true</Parameter></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> <Parameter name="table">planet_osm_roads</Parameter></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> </Datasource></span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </Layer></span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"></Map></span><br><br>Unfortunately the output is simply a blank 'map' image with no roads drawn at all. I turned on the postgres query log to see what's happening there and this is the output I get:<br>
<br><span style="font-family: courier new,monospace;">2010-01-12 23:38:31 GMT LOG: statement: select f_geometry_column,srid,type from geometry_columns where f_table_name='planet_osm_roads'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">2010-01-12 23:38:31 GMT LOG: statement: select * from planet_osm_roads limit 0</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">2010-01-12 23:38:31 GMT LOG: statement: select xmin(ext),ymin(ext),xmax(ext),ymax(ext) from (select estimated_extent('planet_osm_roads','way') as ext) as tmp</span><br style="font-family: courier new,monospace;">
<br>So it all seems fine but for some reason doesn't actually query the table to fetch the data to render. Each of those queries succeeds when run individually via psql and the extents query at the end returns a valid result for the data that's in the table.<br>
<br>The planet_osm_roads contains a small subset of OSM data for a part of London that I downloaded via the export function on the <a href="http://openstreetmap.org">openstreetmap.org</a> site. I've checked the database and it's populated correctly. In fact, I used Qgis to load in the data to check it, then exported that as a shapefile, changed the above XML to use the shapefile datasource instead and it rendered the map correctly so there seems to be no problem with the data...<br>
<br>So I'm a bit stumped, what am I missing? Has anyone got any suggestions?<br><br>Many thanks,<br>Colm<br>