Postgis数据库和Mapnik之间的连接

时间:2013-03-10 10:19:19

标签: postgis mapnik

您好我正在尝试将我的postgis数据渲染到Mapnik中,但无法做同样的事情,任何人都可以与我共享相同的Python文件,这解释了如何做同样的事情。

Manish Sharma

1 个答案:

答案 0 :(得分:1)

谷歌是你的朋友,但这里有一个使用mapnik 2.1 python和xml样式的快速示例: 这是python:

#!/usr/bin/python
import mapnik
from mapnik import Coord, Box2d

###
# Configuration
###
style = 'style.xml'
output = 'output.png'

width = 800
height = 800

bbox = Box2d(-11823891.0314,4847942.08196,-11774971.3333,4896861.78006)
print "Using mapnik version:", mapnik.mapnik_version()
map = mapnik.Map(width, height)
mapnik.load_map(map, style)

map.zoom_to_box(bbox)
mapnik.render_to_file(map, output)

这是一个使用osm数据的简单style.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>

<Map background-color="#FFF">

<Style name="roads">
  <Rule>
    <LineSymbolizer stroke="red" stroke-width="1" />
  </Rule>
</Style>

<Layer name="roads" status="on">
  <StyleName>roads</StyleName>
  <Datasource>
    <Parameter name="table">
      (select way from osm_line where highway is not null) as road
    </Parameter>
    <Parameter name="type">postgis</Parameter>
    <Parameter name="port">5432</Parameter>
    <Parameter name="user">gisuser</Parameter>
    <Parameter name="dbname">gis</Parameter>
  </Datasource>
</Layer>
</Map>