本文整理汇总了Python中mapnik.render_to_file函数的典型用法代码示例。如果您正苦于以下问题:Python render_to_file函数的具体用法?Python render_to_file怎么用?Python render_to_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render_to_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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'"
开发者ID:RaKl,项目名称:TileGen,代码行数:33,代码来源:rendering.py
示例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
开发者ID:mapzen,项目名称:raster-poc,代码行数:60,代码来源:mapnik_format.py
示例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)
开发者ID:simone-f,项目名称:compare-to-osm,代码行数:7,代码来源:renderer.py
示例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
开发者ID:perrygeo,项目名称:geofu,代码行数:34,代码来源:_layer.py
示例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())
开发者ID:Mappy,项目名称:pycnikr,代码行数:7,代码来源:test_mapnik.py
示例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')
开发者ID:nickcanz,项目名称:mapnik_examples,代码行数:7,代码来源:address.py
示例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])
开发者ID:hitzi,项目名称:nik2img,代码行数:34,代码来源:renderer.py
示例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])
开发者ID:umidev,项目名称:mapnik-utils,代码行数:7,代码来源:renderer.py
示例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')
开发者ID:BartlomiejGrabowski,项目名称:SpatialAnalyserServer,代码行数:27,代码来源:draw_from_shp.py
示例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
开发者ID:JeffHeard,项目名称:terrapyn,代码行数:34,代码来源:rendering.py
示例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)))
开发者ID:perrygeo,项目名称:djmapnik,代码行数:34,代码来源:mapgraphics.py
示例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)
开发者ID:Jiangyangyang,项目名称:mapnik,代码行数:8,代码来源:render.py
示例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")
开发者ID:emfcamp,项目名称:buildmap,代码行数:8,代码来源:static.py
示例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)
开发者ID:Bboatman,项目名称:proceduralMapGeneration,代码行数:8,代码来源:MapStyler.py
示例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])
开发者ID:umidev,项目名称:mapnik-utils,代码行数:9,代码来源:renderer.py
示例16: test_gen_map
def test_gen_map():
mapxmlfile = '../data/good_maps/raster_colorizer.xml'
mapxmloutputfile = 'raster_colorizer_test_save.xml'
outputfile = 'raster_colorizer_test.png'
m = mapnik.Map(800, 600)
mapnik.load_map(m, mapxmlfile)
mapnik.save_map(m, mapxmloutputfile)
m.zoom_all()
mapnik.render_to_file(m, outputfile)
开发者ID:mojodna,项目名称:debian-mapnik,代码行数:10,代码来源:raster_colorizer_test.py
示例17: renderImage
def renderImage(self, map_output, mapfile, imgx, imgy, bbox):
print "renderImage"
m = mapnik.Map(imgx, imgy)
mapnik.load_map(m, mapfile)
#ll = (1321613.269848, 6475998.706584, 1674460.199655, 6743324.6719772)
ll = (1321613.269848, 6475998.706584, 1674460.199655, 6743324.671977)
ll = bbox
bbox = mapnik.Box2d(mapnik.Coord(ll[0], ll[3]), mapnik.Coord(ll[2], ll[1]))
m.zoom_to_box(bbox)
mapnik.render_to_file(m, map_output)
开发者ID:RaKl,项目名称:TileMos,代码行数:10,代码来源:tilemos.py
示例18: test_psql_error_should_give_back_connections_opened_for_lower_layers_to_the_pool
def test_psql_error_should_give_back_connections_opened_for_lower_layers_to_the_pool():
map1 = mapnik.Map(600,300)
s = mapnik.Style()
r = mapnik.Rule()
r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color('#f2eff9')))
s.rules.append(r)
map1.append_style('style',s)
# This layer will fail after a while
buggy_s = mapnik.Style()
buggy_r = mapnik.Rule()
buggy_r.symbols.append(mapnik.PolygonSymbolizer(mapnik.Color('#ff0000')))
buggy_r.filter = mapnik.Filter("[fips] = 'FR'")
buggy_s.rules.append(buggy_r)
map1.append_style('style for buggy layer',buggy_s)
buggy_layer = mapnik.Layer('this layer is buggy at runtime')
# We ensure the query wille be long enough
buggy_layer.datasource = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME,table='(SELECT geom as geom, pg_sleep(0.1), fips::int from world_merc) as failure_tabl',
max_async_connection=2, max_size=2,asynchronous_request = True, geometry_field='geom')
buggy_layer.styles.append('style for buggy layer')
# The query for this layer will be sent, then the previous layer will raise an exception before results are read
forced_canceled_layer = mapnik.Layer('this layer will be canceled when an exception stops map rendering')
forced_canceled_layer.datasource = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME,table='world_merc',
max_async_connection=2, max_size=2, asynchronous_request = True, geometry_field='geom')
forced_canceled_layer.styles.append('style')
map1.layers.append(buggy_layer)
map1.layers.append(forced_canceled_layer)
map1.zoom_all()
map2 = mapnik.Map(600,300)
map2.background = mapnik.Color('steelblue')
s = mapnik.Style()
r = mapnik.Rule()
r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('rgb(50%,50%,50%)'),0.1))
r.symbols.append(mapnik.LineSymbolizer(mapnik.Color('rgb(50%,50%,50%)'),0.1))
s.rules.append(r)
map2.append_style('style',s)
layer1 = mapnik.Layer('layer1')
layer1.datasource = mapnik.PostGIS(dbname=MAPNIK_TEST_DBNAME,table='world_merc',
max_async_connection=2, max_size=2, asynchronous_request = True, geometry_field='geom')
layer1.styles.append('style')
map2.layers.append(layer1)
map2.zoom_all()
# We expect this to trigger a PSQL error
try:
mapnik.render_to_file(map1,'world.png', 'png')
# Test must fail if error was not raised just above
eq_(False,True)
except RuntimeError:
pass
# This used to raise an exception before correction of issue 2042
mapnik.render_to_file(map2,'world2.png', 'png')
开发者ID:FlavioFalcao,项目名称:mapnik,代码行数:54,代码来源:postgis_test.py
示例19: test_render_points
def test_render_points():
if not mapnik.has_cairo(): return
# create and populate point datasource (WGS84 lat-lon coordinates)
ds = mapnik.MemoryDatasource()
context = mapnik.Context()
context.push('Name')
f = mapnik.Feature(context,1)
f['Name'] = 'Westernmost Point'
f.add_geometries_from_wkt('POINT (142.48 -38.38)')
ds.add_feature(f)
f = mapnik.Feature(context,2)
f['Name'] = 'Southernmost Point'
f.add_geometries_from_wkt('POINT (143.10 -38.60)')
ds.add_feature(f)
# create layer/rule/style
s = mapnik.Style()
r = mapnik.Rule()
symb = mapnik.PointSymbolizer()
symb.allow_overlap = True
r.symbols.append(symb)
s.rules.append(r)
lyr = mapnik.Layer('Places','+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')
lyr.datasource = ds
lyr.styles.append('places_labels')
# latlon bounding box corners
ul_lonlat = mapnik.Coord(142.30,-38.20)
lr_lonlat = mapnik.Coord(143.40,-38.80)
# render for different projections
projs = {
'google': '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m [email protected] +wktext +no_defs +over',
'latlon': '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs',
'merc': '+proj=merc +datum=WGS84 +k=1.0 +units=m +over +no_defs',
'utm': '+proj=utm +zone=54 +datum=WGS84'
}
for projdescr in projs.iterkeys():
m = mapnik.Map(1000, 500, projs[projdescr])
m.append_style('places_labels',s)
m.layers.append(lyr)
dest_proj = mapnik.Projection(projs[projdescr])
src_proj = mapnik.Projection('+init=epsg:4326')
tr = mapnik.ProjTransform(src_proj,dest_proj)
m.zoom_to_box(tr.forward(mapnik.Box2d(ul_lonlat,lr_lonlat)))
# Render to SVG so that it can be checked how many points are there with string comparison
svg_file = os.path.join(tempfile.gettempdir(), 'mapnik-render-points-%s.svg' % projdescr)
mapnik.render_to_file(m, svg_file)
num_points_present = len(ds.all_features())
svg = open(svg_file,'r').read()
num_points_rendered = svg.count('<image ')
eq_(num_points_present, num_points_rendered, "Not all points were rendered (%d instead of %d) at projection %s" % (num_points_rendered, num_points_present, projdescr))
开发者ID:avlee,项目名称:mapnik,代码行数:53,代码来源:render_test.py
示例20: show
def show(lyr,sty,width=400,height=300,filename=None,app=None):
m = mapnik.Map(width,height,lyr.srs)
m.background = mapnik.Color('transparent')
lyr.styles.append('style')
m.append_style('style',sty)
m.layers.append(lyr)
m.zoom_all()
if not filename:
(handle, filename) = tempfile.mkstemp('.png', 'django-map-')
os.close(handle)
mapnik.render_to_file(m,str(filename))
open_image(str(filename))
return m
开发者ID:perrygeo,项目名称:djmapnik,代码行数:13,代码来源:utils.py
注:本文中的mapnik.render_to_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论