From Python code I can get Mapnik to render this PNG image:

enter image description here

And this one:

enter image description here

But if I try to render both these layers (to render the dots on top of the basemap), then I get only this PNG - which is all transparent; but showing a "half dot" at the bottom. Almost is if the image is rendered but the clipping is wrong:

enter image description here

There are no error messages or other clues. What can I be doing wrong? I sense something fuzzy with unaligned projections; but I am not sure.

The Python code looks like this:

import mapnik

# Base map
map = mapnik.Map(1600, 1200)

# Create raster and point symbolizers
raster = mapnik.RasterSymbolizer()

point = mapnik.PointSymbolizer()
point.file = 'dot.png'
point.allow_overlap = True

# Create new rules and add the symbolizers
raster_rule = mapnik.Rule()

point_rule = mapnik.Rule()

# Create new styles and add the rules
raster_style = mapnik.Style()

point_style = mapnik.Style()

# Add the styles to the map
map.append_style('Raster style', raster_style)
map.append_style('Point style', point_style)

# Specify our data sources
raster_datasource = mapnik.Gdal(file='K100_2017_1_20_612_62.tif')
point_datasource = mapnik.Datasource(type='csv',file='stats.csv')

# Create new layers for the map, add the data sources and styles to those layers.
raster_layer = mapnik.Layer('Raster')
raster_layer.datasource = raster_datasource
raster_layer.srs = '+proj=longlat +datum=WGS84 +units=m +no_defs +over'
raster_layer.styles.append('Raster style')

point_layer = mapnik.Layer('Point')
point_layer.datasource = point_datasource
point_layer.srs = '+proj=longlat +datum=WGS84 +units=m +no_defs +over'
point_layer.styles.append('Point style')

# Add the layers to the map

# If both of these two lines are active - a blank image is rendered?
# If just one of them (any) - and image is rendered fine?

map.srs = '+proj=longlat +datum=WGS84 +units=m +no_defs +over'
mapnik.render_to_file(map, 'K100_2017_1_20_612_62-base-pos.png', 'png32:z=1')

I finally figured it out. Using gdalsrsinfo I discovered the srs of the basemap to be +proj=utm +zone=32 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs.

So changing the right-hand-side of this line fixed the issue:

raster_layer.srs = '+proj=utm +zone=32 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'

I can now render this:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.