首页 > 其他 > 详细

Mapnik读取PostGIS数据渲染图片

时间:2014-08-12 21:32:04      阅读:561      评论:0      收藏:0      [点我收藏+]
__author__ = ‘Administrator‘
# encoding: utf-8
import sys
import datetime
import mapnik
m = mapnik.Map(256,256,"+proj=latlong +datum=WGS84")
#m.background = mapnik.Color(‘steelblue‘) # set background colour to ‘steelblue‘.

s = mapnik.Style()
r = mapnik.Rule()
polygon_symbolizer = mapnik.PolygonSymbolizer(mapnik.Color(‘pink‘))
r.symbols.append(polygon_symbolizer)
line_symbolizer = mapnik.LineSymbolizer(mapnik.Color(‘rgb(50%,50%,50%)‘),0.1)
r.symbols.append(line_symbolizer)
s.rules.append(r)
m.append_style(‘postgis‘,s)

params = dict(dbname=‘geodb‘,table=‘tbsvrc_metadata_10584‘,user=‘postgres‘,password=‘postgres‘,host="192.98.12.244",port="5432")
params[‘estimate_extent‘] = True
ds=mapnik.PostGIS(**params)
#print(ds.envelope())
lyr = mapnik.Layer(‘PostGIS Layer‘)
lyr.datasource=ds
lyr.styles.append(‘postgis‘)
m.layers.append(lyr)
extext = mapnik.Box2d(116.0, 36, 120, 38)
#m.zoom_all()
m.zoom_to_box(extext)
startTime = datetime.datetime.now()
for i in  range(1,40):
    path = "c:\\mapnik\\bj%s.png"%(i);
    mapnik.render_to_file(m,path, ‘png‘)
    #print("running[%s]..."%(i))

endTime = datetime.datetime.now()
print("数据导入总耗时:%s描述"%((endTime - startTime).seconds))

可以修改Range中的参数来测试渲染的效率,经过测试每秒可以输出10张图片。生成图片如截图:

bubuko.com,布布扣

Mapnik读取PostGIS数据渲染图片,布布扣,bubuko.com

Mapnik读取PostGIS数据渲染图片

原文:http://www.cnblogs.com/likehua/p/3908305.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!