首页 > 代码库 > Mapnik读取PostGIS数据渲染图片
Mapnik读取PostGIS数据渲染图片
__author__ = ‘Administrator‘# encoding: utf-8import sysimport datetimeimport mapnikm = 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‘] = Trueds=mapnik.PostGIS(**params)#print(ds.envelope())lyr = mapnik.Layer(‘PostGIS Layer‘)lyr.datasource=dslyr.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张图片。生成图片如截图:
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。