Skip to content

Instantly share code, notes, and snippets.

Embed
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.
<GDAL_WMS>
<Service name="TMS">
<ServerUrl>http://otile1.mqcdn.com/tiles/1.0.0/sat/${z}/${x}/${y}.png</ServerUrl>
</Service>
<DataWindow>
<UpperLeftX>-20037508.34</UpperLeftX>
<UpperLeftY>20037508.34</UpperLeftY>
<LowerRightX>20037508.34</LowerRightX>
<LowerRightY>-20037508.34</LowerRightY>
<TileLevel>18</TileLevel>
<TileCountX>1</TileCountX>
<TileCountY>1</TileCountY>
<YOrigin>top</YOrigin>
</DataWindow>
<Projection>EPSG:3857</Projection>
<BlockSizeX>256</BlockSizeX>
<BlockSizeY>256</BlockSizeY>
<BandsCount>3</BandsCount>
<AdviseRead>false</AdviseRead>
<VerifyAdviseRead>false</VerifyAdviseRead>
</GDAL_WMS>
#!/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()
background_rule.symbols.append(mapnik.RasterSymbolizer())
background_style.rules.append(background_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')
m.layers.append(tile_layer)
#add a colored line
style = mapnik.Style()
line_rule = mapnik.Rule()
line_symbolizer = mapnik.LineSymbolizer(mapnik.Color("red"), 2)
line_rule.symbols.append(line_symbolizer)
style.rules.append(line_rule)
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')
m.layers.append(line_layer)
#set extent
extent = mapnik.Box2d(-112, 40, -109, 46)
m.zoom_to_box(extent)
#render to a png
mapnik.render_to_file(m, "out.png", 'png')
@JesseCrocker

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.