本文整理汇总了Python中mapnik.save_map_to_string函数的典型用法代码示例。如果您正苦于以下问题:Python save_map_to_string函数的具体用法?Python save_map_to_string怎么用?Python save_map_to_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了save_map_to_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_arbitrary_parameters_attached_to_map
def test_arbitrary_parameters_attached_to_map():
m = mapnik.Map(256,256)
mapnik.load_map(m,'../data/good_maps/extra_arbitary_map_parameters.xml')
eq_(len(m.parameters),5)
eq_(m.parameters['key'],'value2')
eq_(m.parameters['key3'],'value3')
eq_(m.parameters['unicode'],u'iván')
eq_(m.parameters['integer'],10)
eq_(m.parameters['decimal'],.999)
m2 = mapnik.Map(256,256)
for k,v in m.parameters:
m2.parameters.append(mapnik.Parameter(k,v))
eq_(len(m2.parameters),5)
eq_(m2.parameters['key'],'value2')
eq_(m2.parameters['key3'],'value3')
eq_(m2.parameters['unicode'],u'iván')
eq_(m2.parameters['integer'],10)
eq_(m2.parameters['decimal'],.999)
map_string = mapnik.save_map_to_string(m)
m3 = mapnik.Map(256,256)
mapnik.load_map_from_string(m3,map_string)
eq_(len(m3.parameters),5)
eq_(m3.parameters['key'],'value2')
eq_(m3.parameters['key3'],'value3')
eq_(m3.parameters['unicode'],u'iván')
eq_(m3.parameters['integer'],10)
eq_(m3.parameters['decimal'],.999)
示例2: test_arbitrary_parameters_attached_to_map
def test_arbitrary_parameters_attached_to_map():
m = mapnik.Map(256, 256)
mapnik.load_map(m, "../data/good_maps/extra_arbitary_map_parameters.xml")
eq_(len(m.parameters), 5)
eq_(m.parameters["key"], "value2")
eq_(m.parameters["key3"], "value3")
eq_(m.parameters["unicode"], u"iván")
eq_(m.parameters["integer"], 10)
eq_(m.parameters["decimal"], 0.999)
m2 = mapnik.Map(256, 256)
for k, v in m.parameters:
m2.parameters.append(mapnik.Parameter(k, v))
eq_(len(m2.parameters), 5)
eq_(m2.parameters["key"], "value2")
eq_(m2.parameters["key3"], "value3")
eq_(m2.parameters["unicode"], u"iván")
eq_(m2.parameters["integer"], 10)
eq_(m2.parameters["decimal"], 0.999)
map_string = mapnik.save_map_to_string(m)
m3 = mapnik.Map(256, 256)
mapnik.load_map_from_string(m3, map_string)
eq_(len(m3.parameters), 5)
eq_(m3.parameters["key"], "value2")
eq_(m3.parameters["key3"], "value3")
eq_(m3.parameters["unicode"], u"iván")
eq_(m3.parameters["integer"], 10)
eq_(m3.parameters["decimal"], 0.999)
示例3: serialize
def serialize(xml,options):
try:
import mapnik
except:
sys.exit(color_text(1,'Error: saving xml requires Mapnik python bindings to be installed'))
m = mapnik.Map(1,1)
if options.from_string:
mapnik.load_map_from_string(m,xml,True)
else:
mapnik.load_map(m,xml,True)
if options.output:
mapnik.save_map(m,options.output)
else:
if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 700:
print mapnik.save_map_to_string(m)
else:
sys.exit(color_text(1,'Minor error: printing XML to stdout requires Mapnik >=0.7.0, please provide a second argument to save the output to a file'))
示例4: test_serializing_arbitrary_parameters
def test_serializing_arbitrary_parameters():
m = mapnik.Map(256,256)
m.parameters.append(mapnik.Parameter('width',m.width))
m.parameters.append(mapnik.Parameter('height',m.height))
m2 = mapnik.Map(1,1)
mapnik.load_map_from_string(m2,mapnik.save_map_to_string(m))
eq_(m2.parameters['width'],m.width)
eq_(m2.parameters['height'],m.height)
示例5: test_load_save_map
def test_load_save_map():
map = mapnik.Map(256,256)
in_map = "../data/good_maps/raster_symbolizer.xml"
mapnik.load_map(map, in_map)
out_map = mapnik.save_map_to_string(map)
assert 'RasterSymbolizer' in out_map
assert 'RasterColorizer' in out_map
assert 'stop' in out_map
示例6: render_on_demand_as_loop
def render_on_demand_as_loop(self, tile_uri, zoom, zentral_tile):
rendered_tiles = []
tileBunch = new_object.getTileBunch(zentral_tile)
for tile in tileBunch:
if not os.path.isdir(tile_uri + '/' + str(tile[0])):
os.mkdir(tile_uri + '/' + str(tile[0]))
uri = tile_uri + '/' + str(tile[0]) + '/' + str(tile[1]) + '.png'
arg = (tile_dir, mapnik.save_map_to_string(self.mapnik_map), maxZoom, uri,tile[0], tile[1], zoom)
scale = rendering.pure_tile_rendering(arg)
rendered_tiles.append(uri)
return rendered_tiles, scale
示例7: on_btn_ok_clicked
def on_btn_ok_clicked(self, widget, data=None):
"""The user has elected to save the changes.
Called before the dialog returns Gtk.ResponseType.OK from run().
"""
logs = os.getenv("HOME") + '/TileGen/log-files/'
wobj = open(logs+'TileGen-last-mapfile.xml', 'w')
wobj.write(mapnik.save_map_to_string(self.mapnik_map))
wobj.close
func.writeToLog('Deleted tile_dir! %s' %os.system(' rm -rf '+ tile_dir),logs)
pass
示例8: test_load_save_map
def test_load_save_map():
map = mapnik.Map(256, 256)
in_map = "../visual_tests/styles/raster_symbolizer.xml"
try:
mapnik.load_map(map, in_map)
out_map = mapnik.save_map_to_string(map)
assert "RasterSymbolizer" in out_map
assert "RasterColorizer" in out_map
assert "stop" in out_map
except RuntimeError, e:
# only test datasources that we have installed
if not "Could not create datasource" in str(e):
raise RuntimeError(str(e))
示例9: test_load_save_map
def test_load_save_map():
map = mapnik.Map(256, 256)
in_map = "../data/good_maps/raster_symbolizer.xml"
try:
mapnik.load_map(map, in_map)
out_map = mapnik.save_map_to_string(map)
assert 'RasterSymbolizer' in out_map
assert 'RasterColorizer' in out_map
assert 'stop' in out_map
except RuntimeError as e:
# only test datasources that we have installed
if not 'Could not create datasource' in str(e):
raise RuntimeError(str(e))
示例10: test_load_save_load_map
def test_load_save_load_map():
map = mapnik.Map(256,256)
in_map = "../data/good_maps/glyph_symbolizer.xml"
mapnik.load_map(map, in_map)
style = map.find_style('arrows')
sym = style.rules[0].symbols[0]
assert isinstance(sym, mapnik.GlyphSymbolizer)
assert sym.angle_mode == mapnik.angle_mode.AZIMUTH
out_map = mapnik.save_map_to_string(map).decode('utf8')
map = mapnik.Map(256,256)
mapnik.load_map_from_string(map, out_map.encode('utf8'))
assert 'GlyphSymbolizer' in out_map
# make sure non-ascii characters are well supported since most interesting
# glyphs for symbology are usually in that range
assert u'í' in out_map, out_map
示例11: compare_map
def compare_map(xml):
m = mapnik.Map(256, 256)
absolute_base = os.path.abspath(os.path.dirname(xml))
mapnik.load_map(m, xml, False, absolute_base)
(handle, test_map) = tempfile.mkstemp(suffix='.xml', prefix='mapnik-temp-map1-')
os.close(handle)
(handle, test_map2) = tempfile.mkstemp(suffix='.xml', prefix='mapnik-temp-map2-')
os.close(handle)
if os.path.exists(test_map):
os.remove(test_map)
mapnik.save_map(m, test_map)
new_map = mapnik.Map(256, 256)
mapnik.load_map(new_map, test_map,False,absolute_base)
open(test_map2,'w').write(mapnik.save_map_to_string(new_map))
diff = ' diff %s %s' % (os.path.abspath(test_map),os.path.abspath(test_map2))
try:
eq_(open(test_map).read(),open(test_map2).read())
except AssertionError, e:
raise AssertionError('serialized map "%s" not the same after being reloaded, \ncompare with command:\n\n$%s' % (xml,diff))
示例12: render_on_demand_as_loop
def render_on_demand_as_loop(self, tile_uri, zoom, central_tile):
rendered_tiles = []
tileBunch = self.TileCalcs.getTileBunch(central_tile)
for tile in tileBunch:
if not os.path.isdir(tile_uri + "/" + str(tile[0])):
os.mkdir(tile_uri + "/" + str(tile[0]))
uri = tile_uri + "/" + str(tile[0]) + "/" + str(tile[1]) + ".png"
arg = (
self.params.getTilesHome(),
mapnik.save_map_to_string(self.tileParams.getMapnikMap()),
self.tileParams.getMaxZoom(),
uri,
tile[0],
tile[1],
zoom,
)
scale = rendering.pure_tile_rendering(arg)
rendered_tiles.append(uri)
return rendered_tiles, scale
示例13: on_comboboxtext_layer_changed
def on_comboboxtext_layer_changed(self, widget, data=None):
self.ui.comboboxtext_style.remove_all()
chosen_layer = self.ui.comboboxtext_layer.get_active_text()
self.mapnik_styles = []
#find the chosen layer
for layer in self.mapnik_map.layers.__iter__():
if chosen_layer == layer.name:
source_params = xmlFunc.getDatasourceFromString(mapnik.save_map_to_string(self.mapnik_map),chosen_layer)
type = source_params['type']
#print type
if type == 'shape' or type == 'postgis':
self.datasource = (source_params['type'], layer.datasource, source_params)
self.layerSRS = layer.srs
for style in layer.styles:
self.mapnik_styles.append(style)
self.ui.comboboxtext_style.append_text(style)
else:
print 'Please implement the missing type: %s' %type
self.ui.comboboxtext_style.append_text('Layer type: %s ... it is not implemented yet!' %type)
示例14: test_loading_fontset_from_python
def test_loading_fontset_from_python():
m = mapnik.Map(256,256)
fset = mapnik.FontSet('foo')
fset.add_face_name('Comic Sans')
fset.add_face_name('Papyrus')
eq_(fset.name,'foo')
fset.name = 'my-set'
eq_(fset.name,'my-set')
m.append_fontset('my-set', fset)
sty = mapnik.Style()
rule = mapnik.Rule()
tsym = mapnik.TextSymbolizer()
eq_(tsym.fontset,None)
tsym.fontset = fset
rule.symbols.append(tsym)
sty.rules.append(rule)
m.append_style('Style',sty)
serialized_map = mapnik.save_map_to_string(m)
eq_('fontset-name="my-set"' in serialized_map,True)
示例15: test_load_save_load_map
def test_load_save_load_map():
map = mapnik.Map(256, 256)
in_map = "../data/good_maps/glyph_symbolizer.xml"
try:
mapnik.load_map(map, in_map)
style = map.find_style("arrows")
sym = style.rules[0].symbols[0]
assert isinstance(sym, mapnik.GlyphSymbolizer)
assert sym.angle_mode == mapnik.angle_mode.AZIMUTH
out_map = mapnik.save_map_to_string(map).decode("utf8")
map = mapnik.Map(256, 256)
mapnik.load_map_from_string(map, out_map.encode("utf8"))
assert "GlyphSymbolizer" in out_map
# make sure non-ascii characters are well supported since most interesting
# glyphs for symbology are usually in that range
assert u"í" in out_map, out_map
except RuntimeError, e:
# only test datasources that we have installed
if not "Could not create datasource" in str(e):
raise RuntimeError(e)