从Python代码生成Mapnik样式的工具
项目描述
pycnik
一个简单的从Python代码(带有编码约定)到Mapnik XML样式的翻译器。
- 功能
允许使用不同数量的缩放级别和瓦片大小(计算比例分母)
提供继承机制
当使用超过2种样式时自动添加cache-feature属性
安装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 声明语法相同的关键字。
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'" } # 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 的 compute_scales
1.3.2 (2012-12-05)
允许 layer 标签具有任何属性
1.3.1 (2012-10-25)
更新文档
1.3 (2012-10-04)
移除 tag scaledenominator 中的“zoom”注释(对于 mapnik 2.1)
更多测试
1.2 (2012-09-11)
添加 copy_style() 辅助函数
1.1 (2012-09-10)
在规则中支持具有相同类型的多个符号化器
更多测试
1.0 (2012-08-07)
初始版本
项目详情
关闭
pycnik-1.4.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 6a49bcc5fe4268046682de73f017c0d83a68f3a679b92478d001ce172e0f67f3 |
|
MD5 | 0c2db7776933c49b1613e87c9c88dd4d |
|
BLAKE2b-256 | 2a7d1c085a6baadde2f008b732033622329154e41509eb28d5ba7c53e69de3ac |