Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Test mapnik with gdal driver using the GDAL_WMS driver with the TMS mini driver. On OS X this works correctly, on linux the background is always greyscale.
<Service name="TMS">
#!/usr/bin/env python
import mapnik
m = mapnik.Map(500, 500)
#m.srs = '+init=epsg:3857'
#add a background
background_style = mapnik.Style()
background_rule = mapnik.Rule()
m.append_style('background style', background_style)
tile_layer = mapnik.Layer('background')
tile_layer.srs = '+init=epsg:3857'
tile_layer.datasource = mapnik.Gdal(base=".", file="background.xml")
tile_layer.styles.append('background style')
#add a colored line
style = mapnik.Style()
line_rule = mapnik.Rule()
line_symbolizer = mapnik.LineSymbolizer(mapnik.Color("red"), 2)
m.append_style('line style', style)
line_layer = mapnik.Layer('line layer')
wkt = "LINESTRING(-111 45, -110 45, -110 44)"
line_layer.datasource = mapnik.CSV(inline='name, wkt\n' + 'name,"' + wkt + '"')
line_layer.styles.append('line style')
#set extent
extent = mapnik.Box2d(-112, 40, -109, 46)
#render to a png
mapnik.render_to_file(m, "out.png", 'png')

This comment has been minimized.

Copy link
Owner Author

JesseCrocker commented Feb 18, 2014

to verify that this works correctly with gdal render the same file(and bounds) with gdal_translate
gdal_translate -projwin -12467782 5780349 -12133824 4865942 -outsize 500 500 background.xml -of png out.png

This generates a color image on OS X and linux

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.