pycnik 1.3.2.1

Tool for generating Mapnik's stylesheets from python code
pycnik is a simple Translator from Python code (with coding conventions) to Mapnik XML stylesheet.

Install Pycnik

 git clone https://github.com/ldgeo/pycnik
 cd pycnik
 python setup.py install


Testing

To run the tests:

  python -m unittest discover -s test/

Getting started

Pycnik use dynamic variable declaration, so you have to use the same keywords as the xml declaration syntax.

example.py:

from pycnik.model import *

BACKGROUND_COLOR = 'rgb(255,255,220)'

NATURAL_RASTER = {
 "type": "gdal",
 "file": "natural_earth.tif"
}

DATABASE_PARAM = {
 "dbname": "database",
 "estimate_extent": "true",
 "host": "0.0.0.0",
 "password": "******",
 "port": "5432",
 "type": "postgis",
 "user": "mapuser",
 "srid": "4326",
}

################
# MAP DEFINITION
################
Map.background_color = BACKGROUND_COLOR
Map.srs = "+init=epsg:4326"
Map.minimum_version = "2.0"
Map.font_directory = "fonts"
Map.buffer_size = 128

########
# LAYERS
########
natural_earth = Layer("natural_earth")
natural_earth.datasource = NATURAL_RASTER

bnd = Layer("country boundaries")
bnd.datasource = DATABASE_PARAM
bnd.table = "schema.boundaries"

########
# STYLES
########
natural_earth.style()[:3] = {
 RASTER: {
 'scaling': 'bilinear'
 }
}

bnd.style("blue")[0:19] = {
 LINE: {
 'fill': 'rgb(255,0,0)',
 'stroke-width': '4'
 },
 'filter': "[countrycode]='ESP'"
}

bnd.style("blue")[10:15] = {
 LINE: {
 'stroke-width': '12'
 }
 # inheritance, the filter is conserved
}


Generate mapnik XML

 pycnik example.py -o example.xml

Main features:

  • allow using exotic number of zoom levels and tile sizes (computes scales denominators)
  • provides a mechanism for inheritance
  • automatic add cache-feature attribute when using more than 2 styles

last updated on:
September 12th, 2012, 9:25 GMT
price:
FREE!
developed by:
Ludovic Delaune
homepage:
github.com
license type:
GPL v3 
category:
ROOT \ Utilities

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Rate it!

Add your review!

SUBMIT