跳转到主要内容

从Python代码生成Mapnik样式的工具

项目描述

pycnik

https://secure.travis-ci.org/Mappy/pycnik.png https://pypip.in/v/pycnik/badge.png https://pypip.in/d/pycnik/badge.png Bitdeli badge

一个简单的从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 声明语法相同的关键字。

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 (10.8 kB 查看哈希)

上传时间

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面