Ticket #2255: mapnik_demo.py

File mapnik_demo.py, 818 bytes (added by astrid_emde, 4 years ago)
Line 
1#!/usr/bin/env python3
2import sys
3from os import path
4import mapnik
5m = mapnik.Map(600,300)
6m.background = mapnik.Color('steelblue')
7s = mapnik.Style()
8r = mapnik.Rule()
9polygon_symbolizer = mapnik.PolygonSymbolizer()
10polygon_symbolizer.fill = mapnik.Color('#f2eff9')
11r.symbols.append(polygon_symbolizer)
12
13line_symbolizer = mapnik.LineSymbolizer()
14line_symbolizer.stroke = mapnik.Color('rgb(50%,50%,50%)')
15line_symbolizer.stroke_width = 0.1
16
17r.symbols.append(line_symbolizer)
18s.rules.append(r)
19m.append_style('My Style',s)
20ds = mapnik.Shapefile(file='/home/user/data/natural_earth2/ne_10m_admin_0_countries.shp')
21layer = mapnik.Layer('world')
22layer.datasource = ds
23layer.styles.append('My Style')
24m.layers.append(layer)
25m.zoom_all()
26mapnik.render_to_file(m,'world.png', 'png')
27#
28print ("rendered image to world.png")
29