0

I'm just starting with Mapnik. I followed an example found online to dump an input datasource into a small output image. So far, so good.

Now I want to read a 16384x12800 PNG file I have. It's a mercator projection of a fictional planet. I created a .wld sidecar file:

0.021972656
0.0
0.0
-0.013290624
-179.9890116
85.0533511

The resulting .envelope() of the mapnik.Gdal(...) object is:

Box2d(-179.999997928,-85.059990788,179.999997976,85.059996412)

I'm using a layer SRS of +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs.

With all this, the output file is blank (background color).

What should the layer's SRS be for this kind of conversion? Or is it something else I'm doing wrong?

Here's the Python code:

#! /usr/bin/python3
import mapnik

m = mapnik.Map(600,300)
m.background = mapnik.Color('steelblue')

s = mapnik.Style()
r = mapnik.Rule()
polygon_symbolizer = mapnik.PolygonSymbolizer()
polygon_symbolizer.fill = mapnik.Color('#f2eff9')
r.symbols.append(polygon_symbolizer)

line_symbolizer = mapnik.LineSymbolizer()
line_symbolizer.stroke = mapnik.Color('rgb(50%,50%,50%)')
line_symbolizer.stroke_width = 0.1
r.symbols.append(line_symbolizer)
s.rules.append(r)
m.append_style('My Style',s)

ds = mapnik.Gdal(base='./maptest', file='world.png')
print(ds.envelope())

layer = mapnik.Layer('world')
layer.datasource = ds
layer.srs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
layer.styles.append('My Style')
print(layer.srs)

m.layers.append(layer)
m.zoom_all()

mapnik.render_to_file(m, 'small.png', 'png')

(The eventual intent is to break this big map up into tiles suitable for viewing on a slippy-map.)

1 Answer 1

1

It was "something else".

When changing from a polygon input to a raster file, it's necessary to create a RasterSymbolizer and append it to the rule symbols before adding that to the style rules.

...
line_symbolizer = mapnik.LineSymbolizer()
line_symbolizer.stroke = mapnik.Color('rgb(50%,50%,50%)')
line_symbolizer.stroke_width = 0.1
r.symbols.append(line_symbolizer)

raster_symbolizer = mapnik.RasterSymbolizer()
r.symbols.append(raster_symbolizer)

s.rules.append(r)
m.append_style('My Style',s)
...

As for the answer to the actual question... A layer.srs of

+proj=merc

was sufficient but this also worked:

+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 +wktext +no_defs +over

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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