Mapnik Python example


SUBMITTED BY: Guest

DATE: Dec. 5, 2013, 10:31 p.m.

FORMAT: Python

SIZE: 1.2 kB

HITS: 727

  1. import mapnik
  2. from mapnik import DatasourceCache as c
  3. 'raster' in c.plugin_names()
  4. geoTiffFile = "out.tiff"
  5. map = mapnik.Map(600,300)
  6. #print "Map projection is :" + map.srs
  7. map.background = mapnik.Color('white')
  8. style = mapnik.Style()
  9. rule = mapnik.Rule()
  10. #RasterSymb = mapnik.RasterSymbolizer(mapnik.Color('#f2eff9')) # to fill a polygon we create a PolygonSymbolizer
  11. #rule.symbols.append(RasterSymb)
  12. style.rules.append(rule)
  13. map.append_style('Map Style',style)
  14. ### To create datasource
  15. for_area = mapnik.Gdal(base='/',file='out.tiff')
  16. area=for_area.envelope()
  17. print area
  18. raster = mapnik.Raster(base='/',file='out.tiff',lox=area[0],loy=area[3],hix=area[1],hiy=area[2])
  19. ## To create layer: Mapnik Layers are basically containers around datasources
  20. layer = mapnik.Layer('raster')
  21. layer.datasource = raster
  22. #print "Layer projection is : " + layer.srs
  23. map.set_srs = layer.srs
  24. #print "Map projection is :" + map.srs
  25. layer.styles.append('Map Style')
  26. map.layers.append(layer)
  27. map.zoom_all()
  28. mapnik.render_to_file(map,'/map.png', 'png')
  29. print "image rendered ...!!"

comments powered by Disqus