从python代码生成mapnik样式表的工具
pycnik的Python项目详细描述
Pycnik
从python代码(带有编码约定)到 Mapnik XML样式表。
- 功能:
- 允许使用不同数量的缩放级别和平铺大小(计算比例分母)
- 提供继承机制
- 使用两种以上的样式时自动添加缓存功能属性
- 注意事项:
安装pycnik
$ git clone https://github.com/Mappy/pycnik.git $ cd pycnik $ python setup.py install
或通过PIP:
$ pip install pycnik
依赖关系:
- python-mapnik (mapnik >= 2.x)
- lxml
测试
依赖关系:
$ pip install -r requirements/test.pip
使用nose运行测试:
$ nosetests -v
开始
pycnik使用动态变量声明, 因此,必须使用与xml声明语法相同的关键字。
示例.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'" } # change the stroke width from level 10 to 15 # the `filter` and `fill` attributes are preserved bnd.style("blue")[10:15] = { LINE: {'stroke-width': '12'}}
您可以在test/resources目录中看到更多示例。
生成mapnik xml
$ pycnik example.py -o example.xml
更改日志
1.4(2015-02-23)
- 修正WGS84的计算比例
1.3.2(2012-12-05)
- 允许图层标记的任何属性
1.3.1(2012-10-25)
- 更新的文档
1.3(2012-10-04)
- 删除了标记scaledenominator中的“zoom”注释(适用于mapnik 2.1)
- 更多测试
1.2(2012-09-11)
- 添加了copy_style()helper
1.1(2012-09-10)
- 支持规则中具有相同类型的多个符号符
- 更多测试
1.0(2012-08-07)
- 初始版本