本文整理汇总了Python中mapnik.render_to_file函数的典型用法代码示例。如果您正苦于以下问题:Python render_to_file函数的具体用法?Python render_to_file怎么用?Python render_to_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_to_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: qickTest
def qickTest():
m = mapnik.Map(600,300)
m.background = mapnik.Color('steelblue')
s = mapnik.Style()
r = mapnik.Rule()
#polygon_symbolizer = mapnik.PolygonSymbolizer(mapnik.Color('#ff00ff'))
#r.symbols.append(polygon_symbolizer)
line_symbolizer = mapnik.LineSymbolizer(mapnik.Color('rgb(100%,100%,100%)'),0.1)
r.symbols.append(line_symbolizer)
s.rules.append(r)
m.append_style('My Style',s)
line_symbolizer = mapnik.LineSymbolizer(mapnik.Color('rgb(100%,0%,100%)'),0.5)
r.symbols.append(line_symbolizer)
s.rules.append(r)
m.append_style('My New Style',s)
ds = mapnik.Shapefile(file = '/home/klammer/Software/Quickly/tilegen/data/media/testdaten/mercator_polygon/lines-vgtl-27-01-12.shp')
layer = mapnik.Layer('world')
layer.datasource = ds
layer.styles.append('My Style')
m.layers.append(layer)
lyr = mapnik.Layer('Generalized geometry from PostGIS')
lyr.datasource = mapnik.PostGIS(host='localhost',user='gisadmin',password='tinitus',dbname='meingis',table='generalized_line_cache')
lyr.srs = layer.srs
lyr.styles.append('My New Style')
m.layers.append(lyr)
m.zoom_all()
mapnik.render_to_file(m,'world.png', 'png')
print "rendered image to 'world.png'"
示例2: __call__
def __call__(self, feature_layers):
# take the feature_layers dict and generate a gif response
# this just puts all the features across all layers into a
# single one, and then just renders them all with a very
# simple style as a proof of concept
# we probably want to do this per layer with a separate style
# for each
features = feature_layers_to_features_list(feature_layers)
layer = mapnik.Layer('tile')
memds = mapnik.MemoryDatasource()
ctx = mapnik.Context()
for feature in features:
wkb, properties, fid = feature
for key in properties.keys():
ctx.push(key.encode('utf-8'))
i = 1
for feature in features:
wkb, properties, fid = feature
mf = mapnik.Feature(ctx, i)
i += 1
mf.add_geometries_from_wkb(wkb)
for k, v in properties.items():
mf[k.encode('utf-8')] = str(v)
memds.add_feature(mf)
layer.datasource = memds
m = mapnik.Map(256, 256)
m.background = mapnik.Color('blue')
s = mapnik.Style()
r = mapnik.Rule()
polygon_symbolizer = mapnik.PolygonSymbolizer(mapnik.Color('#f2eff9'))
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('my style', s)
layer.styles.append('my style')
m.layers.append(layer)
m.zoom_all()
# from mapnik import Image
# im = Image(m.width, m.height)
# mapnik.render(m, im)
# png_contents = im.tostring()
# this was just the easiest way for me to get this to work
import tempfile
tmpfile = tempfile.NamedTemporaryFile()
with tmpfile.file as fp:
mapnik.render_to_file(m, tmpfile.name, 'png')
fp.seek(0)
png_contents = fp.read()
return png_contents
示例3: generate_img
def generate_img(self):
print "\n- Render image"
m = mapnik.Map(600, 300)
mapnik.load_map(m, self.stylesheet)
m.zoom_all()
mapnik.render_to_file(m, self.image)
print "rendered image to '{0}'".format(self.image)
示例4: render_png
def render_png(self, show=True):
import mapnik
#TODO scale dimensions to aspect ratio of data
m = mapnik.Map(800, 400)
m.background = mapnik.Color('white')
s = mapnik.Style()
r = mapnik.Rule()
if "point" in self.collection().schema['geometry'].lower():
point_symbolizer = mapnik.PointSymbolizer()
r.symbols.append(point_symbolizer)
else:
polygon_symbolizer = mapnik.PolygonSymbolizer(
mapnik.Color('#f2eff9'))
r.symbols.append(polygon_symbolizer)
line_symbolizer = mapnik.LineSymbolizer(
mapnik.Color('rgb(50%,50%,50%)'), 0.8)
r.symbols.append(line_symbolizer)
s.rules.append(r)
m.append_style('My Style', s)
ds = mapnik.Shapefile(file=self.path)
layer = mapnik.Layer('world')
layer.datasource = ds
layer.styles.append('My Style')
m.layers.append(layer)
m.zoom_all()
outfile = '/tmp/world.png'
mapnik.render_to_file(m, outfile, 'png')
if show:
im = Image.open(outfile)
im.show()
return outfile
示例5: test_mapnik
def test_mapnik(self):
m = mapnik.Map(600, 300)
mapnik.load_map(m, 'style_sheet.xml')
m.zoom_all()
mapnik.render_to_file(m, actual_image)
with open(actual_image) as actual, open(expected_image) as expected:
self.assertEquals(actual.read(), expected.read())
示例6: make_map
def make_map(shpfile, img_name):
lyr = mapnik.Layer('world', "+proj=latlong +datum=NAD83")
lyr.datasource = mapnik.Shapefile(file=shpfile)
lyr.styles.append('My Style')
m.layers.append(lyr)
m.zoom_to_box(lyr.envelope())
mapnik.render_to_file(m, img_name, 'png')
示例7: render_to_file
def render_to_file(self,*args):
"""
Routine to render the requested AGG format.
"""
format = args[2]
if format in ('tif','tiff'):
self.timer()
(handle, png_tmp) = tempfile.mkstemp('.png', 'nik2img-tmp')
os.close(handle)
self.world_file_ext = 'wld'
self.write_wld(png_tmp)
im = mapnik.Image(args[0].width,self.m.height)
if self.scale_factor:
mapnik.render(args[0],im,self.scale_factor)
else:
mapnik.render(args[0],im)
im.save(png_tmp,'png')
# todo - figure out more reasonable defaults
opts = ' -ot Byte -co COMPRESS=JPEG -co JPEG_QUALITY=100'
base_cmd = 'gdal_translate %s %s -a_srs "%s" %s'
cmd = base_cmd % (png_tmp,args[1],args[0].srs,opts)
#print call(cmd,fail=True)
os.system(cmd)
self.stop()
else:
self.timer()
if self.scale_factor:
args = args + (self.scale_factor,)
mapnik.render_to_file(*args)
if self.world_file_ext:
self.write_wld(args[1])
self.stop()
if self.zip_compress:
self.zip_up(args[1])
示例8: render_agg
def render_agg(self, *args):
"""
Routine to render the requested AGG format.
"""
mapnik.render_to_file(*args)
if self.world_file_ext:
self.write_wld(args[1])
示例9: drawSHPFile
def drawSHPFile(self):
#Loop thru related files list.
for fileName in self.relatedFiles:
self.downloadFile(self.confSHPDownloadsLoc, fileName)
#Create a map with a given width and height in pixels.
# Map
m = mapnik.Map(600,300,'+proj=latlong +datum=WGS84')
m.background = mapnik.Color('steelblue')
# Styles
poly = mapnik.PolygonSymbolizer(mapnik.Color('lavender'))
line = mapnik.LineSymbolizer(mapnik.Color('slategray'),.3)
s,r = mapnik.Style(),mapnik.Rule()
r.symbols.extend([poly,line])
s.rules.append(r)
m.append_style('My Style',s)
# Layer
lyr = mapnik.Layer('world')
lyr.datasource = mapnik.Shapefile(file=self.confSHPDownloadsLoc+'ne_110m_admin_0_countries')
lyr.srs = '+proj=latlong +datum=WGS84'
lyr.styles.append('My Style')
m.layers.append(lyr)
# Render
m.zoom_to_box(lyr.envelope())
mapnik.render_to_file(m, 'hello_world_in_pure_python.png')
示例10: render
def render(self, fmt, width, height, bbox, srs, styles, layers, **kwargs):
"""Render a WMS request or a tile. TODO - create an SQLite cache for this as well, based on hashed filename."""
_log.debug('render called for {0}'.format(layers))
if srs.lower().startswith('epsg'):
if srs.endswith("900913") or srs.endswith("3857"):
srs = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m [email protected]"
else:
srs = "+init=" + srs.lower()
name = self.prepare_wms(layers, srs, styles, **kwargs)
filename = "{name}.{bbox}.{width}x{height}.{fmt}".format(
name=name,
bbox='_'.join(str(b) for b in bbox),
width=width,
height=height,
fmt=fmt
)
_log.debug('waiting on lock')
while os.path.exists(name + ".lock"):
time.sleep(0.05)
_log.debug('rendering {0}x{1} tile'.format(width, height))
m = mapnik.Map(width, height)
mapnik.load_map(m, (name + '.xml').encode('ascii'))
m.zoom_to_box(mapnik.Box2d(*bbox))
mapnik.render_to_file(m, filename, fmt)
with open(filename) as tiledata:
tile = buffer(tiledata.read())
os.unlink(filename)
return filename, tile
示例11: render
def render(qs,options):
kwargs = {}
if options:
if ';' in options:
for item in options.split(';'):
if ':' in item:
k,v = item.split(':')
kwargs[k] = v
width = int(kwargs.get('width',600))
height = int(kwargs.get('height',600))
#field = kwargs.get('field',None)
if hasattr(qs,'_meta'):
# it looks like a model
qs = qs.objects.all()
m = mapnik.Map(width,height)
m.aspect_fix_mode = mapnik.aspect_fix_mode.GROW_CANVAS
adapter = PostgisLayer(qs)
lyr = adapter.to_mapnik()
sty = adapter.get_default_style()
lyr.styles.append('style')
m.append_style('style',sty)
#m.background = mapnik.Color('green')
m.srs = lyr.srs
m.layers.append(lyr)
m.zoom_all()
#print mapnik.save_map_to_string(m)
mod = qs.query.get_meta().module_name
# TODO - need way to properly cache vs. always overwriting...
name = '%s_%s_%s_%s.png' % (mod,width,height,random())
map_graphic = os.path.join(graphics,name)
mapnik.render_to_file(m,str(map_graphic))
url = os.path.join(settings.MEDIA_URL,'mapgraphics',name)
return mark_safe(force_unicode('<img src="%s" />' % smart_str(url)))
示例12: render
def render(input_file, output_file, width=800, height=800, bbox=None):
m = mapnik.Map(width, height)
mapnik.load_map(m, input_file, False)
if bbox is not None:
m.zoom_to_box(bbox)
else:
m.zoom_all()
mapnik.render_to_file(m, output_file)
示例13: export
def export(self, mapnik_xml, output_file):
self.log.info("Exporting %s to %s. Mapnik version %s", mapnik_xml, output_file,
mapnik.mapnik_version_string())
mapnik_map = mapnik.Map(2000, 2000)
mapnik.load_map(mapnik_map, mapnik_xml.encode('utf-8'))
mapnik_map.zoom_all()
mapnik.render_to_file(mapnik_map, output_file, b"pdf")
示例14: saveImage
def saveImage(self, mapFilename, imgFilename):
if self.m is None:
self.m = mapnik.Map(self.width, self.height)
mapnik.load_map(self.m, mapFilename)
# extent = mapnik.Box2d(-300, -180.0, 90.0, 90.0)
# self.m.zoom_to_box(self.extents)
self.m.zoom_all()
mapnik.render_to_file(self.m, imgFilename)
示例15: render_to_file
def render_to_file(self,*args):
"""
Routine to render the requested AGG format.
"""
self.timer()
mapnik.render_to_file(*args)
self.stop()
if self.world_file_ext:
self.write_wld(args[1])