本文整理汇总了Python中mapnik.load_map_from_string函数的典型用法代码示例。如果您正苦于以下问题:Python load_map_from_string函数的具体用法?Python load_map_from_string怎么用?Python load_map_from_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_map_from_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: test_can_parse_xml_with_deprecated_properties
def test_can_parse_xml_with_deprecated_properties():
default_logging_severity = mapnik.logger.get_severity()
mapnik.logger.set_severity(getattr(mapnik.severity_type, "None"))
files_with_deprecated_props = glob.glob("../data/deprecated_maps/*.xml")
failures = []
for filename in files_with_deprecated_props:
try:
m = mapnik.Map(512, 512)
strict = True
mapnik.load_map(m, filename, strict)
base_path = os.path.dirname(filename)
mapnik.load_map_from_string(
m,
open(
filename,
'rb').read(),
strict,
base_path)
except RuntimeError as e:
# only test datasources that we have installed
if not 'Could not create datasource' in str(e) \
and not 'could not connect' in str(e):
failures.append(
'Failed to load valid map %s (%s)' %
(filename, e))
eq_(len(failures), 0, '\n' + '\n'.join(failures))
mapnik.logger.set_severity(default_logging_severity)
示例4: test_adding_datasource_to_layer
def test_adding_datasource_to_layer():
map_string = """<?xml version="1.0" encoding="utf-8"?>
<Map>
<Layer name="world_borders">
<StyleName>world_borders_style</StyleName>
<StyleName>point_style</StyleName>
<!-- leave datasource empty -->
<!--
<Datasource>
<Parameter name="file">../data/shp/world_merc.shp</Parameter>
<Parameter name="type">shape</Parameter>
</Datasource>
-->
</Layer>
</Map>
"""
m = mapnik.Map(256, 256)
try:
mapnik.load_map_from_string(m, map_string)
# validate it loaded fine
eq_(m.layers[0].styles[0], "world_borders_style")
eq_(m.layers[0].styles[1], "point_style")
eq_(len(m.layers), 1)
# also assign a variable reference to that layer
# below we will test that this variable references
# the same object that is attached to the map
lyr = m.layers[0]
# ensure that there was no datasource for the layer...
eq_(m.layers[0].datasource, None)
eq_(lyr.datasource, None)
# also note that since the srs was black it defaulted to wgs84
eq_(m.layers[0].srs, "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
eq_(lyr.srs, "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
# now add a datasource one...
ds = mapnik.Shapefile(file="../data/shp/world_merc.shp")
m.layers[0].datasource = ds
# now ensure it is attached
eq_(m.layers[0].datasource.describe()["name"], "shape")
eq_(lyr.datasource.describe()["name"], "shape")
# and since we have now added a shapefile in spherical mercator, adjust the projection
lyr.srs = "+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
# test that assignment
eq_(m.layers[0].srs, "+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
eq_(lyr.srs, "+proj=merc +lon_0=0 +lat_ts=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
except RuntimeError, e:
# only test datasources that we have installed
if not "Could not create datasource" in str(e):
raise RuntimeError(e)
示例5: setMapXML_
def setMapXML_(self, xml):
map = mapnik.Map(256,256)
mapnik.load_map_from_string(map, xml)
self.projectionString = map.srs
self.projection = mapnik.Projection(self.projectionString)
self.cache = dict()
self.render_thread.loadMapString_(xml)
示例6: 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)
示例7: loadMapString_
def loadMapString_(self, xml):
self.cancelTiles()
self.map_lock.lock()
self.map = mapnik.Map(256,256)
self.map.buffer_size = 128
mapnik.load_map_from_string(self.map, xml)
self.prj = mapnik.Projection(self.map.srs)
self.map_lock.unlock()
示例8: assert_loads_successfully
def assert_loads_successfully(file):
m = mapnik.Map(512, 512)
strict = True
mapnik.load_map(m, file, strict)
# libxml2 is not smart about paths, and clips the last directory off
# of a path if it does not end in a trailing slash
base_path = os.path.dirname(file) + '/'
mapnik.load_map_from_string(m,open(file,'rb').read(),strict,base_path)
示例9: create_thumbnail
def create_thumbnail(xmlmap, filepath):
shape = (230, 200)
m = mapnik.Map(*shape)
mapnik.load_map_from_string(m, xmlmap)
box = m.layers[0].envelope()
prj = mapnik.Projection(m.srs)
prj_box = box.forward(prj)
m.zoom_to_box(prj_box)
im = mapnik.Image(*shape)
mapnik.render(m, im)
im.save(filepath, 'png256')
示例10: test_filter_init
def test_filter_init():
m = mapnik.Map(1, 1)
mapnik.load_map_from_string(m, map_)
filters = []
filters.append(mapnik.Filter("([region]>=0) and ([region]<=50)"))
filters.append(mapnik.Filter("(([region]>=0) and ([region]<=50))"))
filters.append(mapnik.Filter("((([region]>=0) and ([region]<=50)))"))
filters.append(mapnik.Filter("((([region]>=0) and ([region]<=50)))"))
filters.append(mapnik.Filter("""((([region]>=0) and ([region]<=50)))"""))
filters.append(
mapnik.Filter(
"""
((([region]>=0)
and
([region]<=50)))
"""
)
)
filters.append(
mapnik.Filter(
"""
([region]>=0)
and
([region]<=50)
"""
)
)
filters.append(
mapnik.Filter(
"""
([region]
>=
0)
and
([region]
<=
50)
"""
)
)
s = m.find_style("s")
for r in s.rules:
filters.append(r.filter)
first = filters[0]
for f in filters:
eq_(str(first), str(f))
s = m.find_style("s2")
eq_(s.filter_mode, mapnik.filter_mode.FIRST)
示例11: render_png
def render_png(tile, zoom, xml, overscan):
map_tile_size = TILE_SIZE + (overscan * 2)
# mapnik is installed in a non-standard way.
# It confuses pylint.
# pylint: disable=no-member
"""
Render the tile for the given zoom
"""
logger = get_logger()
ctx = mapnik.Context()
map_tile = mapnik.Map(map_tile_size, map_tile_size)
# scale_denom = 1 << (BASE_ZOOM - int(zoom or 1))
# scale_factor = scale_denom / map_tile.scale_denominator()
# map_tile.zoom(scale_factor) # Is overriden by zoom_to_box.
mapnik.load_map_from_string(map_tile, xml)
box_min = -overscan
box_max = TILE_SIZE + overscan - 1
map_tile.zoom_to_box(mapnik.Box2d(box_min, box_min, box_max, box_max))
for (name, features) in tile.items():
name = name.encode('ascii', 'ignore')
source = mapnik.MemoryDatasource()
map_layer = mapnik.Layer(name)
map_layer.datasource = source
for feature in features:
feat = mapnik.Feature(ctx, 0)
try:
feat.add_geometries_from_wkb(feature)
except RuntimeError:
from mapnik import Path # pylint: disable=no-name-in-module
try:
wkt = Path.from_wkb(feature).to_wkt()
logger.error('Invalid feature: %s', wkt)
except RuntimeError:
logger.error('Corrupt feature: %s', feature.encode('hex'))
source.add_feature(feat)
map_layer.styles.append(name)
map_tile.layers.append(map_layer)
image = mapnik.Image(TILE_SIZE, TILE_SIZE)
# tile, image, scale, offset_x, offset_y
mapnik.render(map_tile, image, 1, overscan, overscan)
return image.tostring('png')
示例12: assert_loads_successfully
def assert_loads_successfully(file):
m = mapnik.Map(512, 512)
try:
strict = True
mapnik.load_map(m, file, strict)
# libxml2 is not smart about paths, and clips the last directory off
# of a path if it does not end in a trailing slash
base_path = os.path.dirname(file) + '/'
mapnik.load_map_from_string(m,open(file,'rb').read(),strict,base_path)
except RuntimeError, e:
# only test datasources that we have installed
if not 'Could not create datasource' in str(e):
raise RuntimeError(e)
示例13: test_good_files
def test_good_files():
good_files = glob.glob("../data/good_maps/*.xml")
failures = [];
for filename in good_files:
try:
m = mapnik.Map(512, 512)
strict = True
mapnik.load_map(m, filename, strict)
base_path = os.path.dirname(filename)
mapnik.load_map_from_string(m,open(filename,'rb').read(),strict,base_path)
except RuntimeError, e:
# only test datasources that we have installed
if not 'Could not create datasource' in str(e):
failures.append('Failed to load valid map (%s)!' % filename)
示例14: 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
示例15: __init__
def __init__(self, tile_dir, xmlmap, q, printLock, maxZoom, fields=None, layer_id=None):
self.tile_dir = tile_dir
self.q = q
self.render_size = 256
self.m = mapnik.Map(self.render_size, self.render_size)
self.g = mapnik.Grid(self.render_size, self.render_size)
self.printLock = printLock
# Load style XML
mapnik.load_map_from_string(self.m, xmlmap)
# Obtain <Map> projection
self.prj = mapnik.Projection(self.m.srs)
# Projects between tile pixel co-ordinates and LatLong (EPSG:4326)
self.tileproj = GoogleProjection(maxZoom+1)
self.layer_id = layer_id
self.fields = fields or []