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

Hi,

I'm struggling for 2 weeks now to render a map using mapnik, mapnik-python, postigs and carto. I'm able to render a map from a local .osm file and I've compiled and installed the latest mapnik library and python bidings.

I've exported a .osm file to a local postgis DB using osm2pgsql and using QGIS Browser (a windows postgis client) I can validate that the export was successful. In order to render a map from this DB I generated a .xml stylesheet using carto -a "3.0.0" ../openstreetmap-carto/project.mml > mapnik2.xml and I modified project.mml and added my DB credentials like this:

  osm2pgsql: &osm2pgsql
  type: "postgis"
  dbname: "gis"
  port: "5432"
host: "localhost"
user: "maps"
password: "asdfe"
key_field: ""
geometry_field: "way"
extent: "-20037508,-20037508,20037508,20037508"

I checked the generated mapnik2.xml file and all DB queries now have information about my DB credentials and it looks like this (snapshot from mapnik2.xml):

</Style>
<Layer name="cliffs"
maximum-scale-denominator="100000"
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
<StyleName>cliffs</StyleName>
<StyleName>cliffs-man_made</StyleName>
<Datasource>
<Parameter name="type"><![CDATA[postgis]]></Parameter>
<Parameter name="dbname"><![CDATA[gis]]></Parameter>
<Parameter name="port"><![CDATA[5432]]></Parameter>
<Parameter name="host"><![CDATA[localhost]]></Parameter>
<Parameter name="user"><![CDATA[maps]]></Parameter>
<Parameter name="password"><![CDATA[asdfe]]></Parameter>
<Parameter name="key_field"><![CDATA[]]></Parameter>
<Parameter name="geometry_field"><![CDATA[way]]></Parameter>
<Parameter name="extent"><![CDATA[-20037508,-20037508,20037508,20037508]]></Parameter>
<Parameter name="table"><![CDATA[(SELECT
way, "natural", man_made
FROM planet_osm_line
WHERE "natural" = 'cliff' OR man_made = 'embankment'
) AS cliffs]]></Parameter>
</Datasource>
</Layer>

This is the python script: #!/usr/bin/env python

import mapnik
from mapnik import *

mapnik.logger.set_severity(mapnik.severity_type.Debug)

mapfile = 'mapnik2.xml'
map_output = 'mymap33.png'

m = Map(1024, 1024)
load_map(m, mapfile)
bbox=(Box2d(-6.5, 49.5, 2.1, 59))

m.zoom_to_box(bbox) 
render_to_file(m, map_output)

The output image is always blank and I see no errors in the logs. I also tried to use nik4.py with the same result, blank image. Is this because mapnik can't connect to my local postgis DB? Did I miss a step ?

asked 10 Feb '17, 12:11

biliuta's gravatar image

biliuta
36113
accept rate: 100%

edited 10 Feb '17, 12:19

Switch statement logging on for your PostgresQL server & you can see if the statements are getting executed.

(10 Feb '17, 14:05) SK53 ♦

I've enabled the logs for postgresql and it seems the queries are executed with the correct user but the image is still blank.

(10 Feb '17, 15:05) biliuta

Is there a way to see more detailed logs from mapnik library? I've compiled mapnik for debuging but I can't see any errors in the logs.

The logs look something like this and it repeats this pattern a lot of times (from mapnik lib when running python script):

Mapnik LOG> 2017-02-10 06:46:28: agg_renderer: Start processing style

Mapnik LOG> 2017-02-10 06:46:28: agg_renderer: End processing style

Mapnik LOG> 2017-02-10 06:46:28: agg_renderer: Start processing style

Mapnik LOG> 2017-02-10 06:46:28: agg_renderer: End processing style

Mapnik LOG> 2017-02-10 06:46:28: agg_renderer: End layer processing

Mapnik LOG> 2017-02-10 06:46:28: agg_renderer: Start processing layer=paths-text-name

Mapnik LOG> 2017-02-10 06:46:28: agg_renderer: -- datasource=0x2cae640

Mapnik LOG> 2017-02-10 06:46:28: agg_renderer: - query_extent=box2d(-6.9500000000000002,49.5000000000000000,2.5499999999999998,59.0000000000000000)

At the end of the log this is what it prints out:

Mapnik LOG> 2017-02-10 06:46:28: agg_renderer: End map processing

Mapnik LOG> 2017-02-10 06:46:28: stroker: Destroy stroker=0x3b87680

Mapnik LOG> 2017-02-10 06:46:28: postgis_connection: postgresql connection closed - 0x2ccd430

(13 Feb '17, 09:05) biliuta

Also I have some doubts about the box that I'm trying to use in my python script:

bbox=(Box2d(-6.5, 49.5, 2.1, 59))

Can someone please explain a bit on how to use this Box2d and what parameters do I need to set? Maybe the params that I'm giving do not represent a zone of the map that I've exported to my postgisDB. I only exported the map of Bucharest not the entire world.

(13 Feb '17, 10:22) biliuta

I figured out the mistake. The map was exported in ESPG:4326 and I wasn't converting the box to this type of coordinates. I used mapnik.ProjTransform and now it works fine.

permanent link

answered 13 Feb '17, 15:12

biliuta's gravatar image

biliuta
36113
accept rate: 100%

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:

×362
×341
×134
×78
×23

question asked: 10 Feb '17, 12:11

question was seen: 6,720 times

last updated: 13 Feb '17, 15:12

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