• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python mapnik.load_map_from_string函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:1060460048,项目名称:mapnik,代码行数:27,代码来源:extra_map_props_test.py


示例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)
开发者ID:kiivihal,项目名称:python-mapnik,代码行数:27,代码来源:extra_map_props_test.py


示例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)
开发者ID:cbenz,项目名称:python-mapnik,代码行数:28,代码来源:load_map_test.py


示例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)
开发者ID:Nobis99,项目名称:openstreetmap-tiles-docker,代码行数:59,代码来源:layer_modification_test.py


示例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)
开发者ID:Ericsonwong,项目名称:maps4mac,代码行数:8,代码来源:TiledMapnikLayer.py


示例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)
开发者ID:Blaxxun,项目名称:mapnik,代码行数:9,代码来源:extra_map_props_test.py


示例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()
开发者ID:Ericsonwong,项目名称:maps4mac,代码行数:9,代码来源:MapnikRenderThread.py


示例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)
开发者ID:mojodna,项目名称:debian-mapnik,代码行数:10,代码来源:load_map_test.py


示例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')
开发者ID:RouxRC,项目名称:nosfinanceslocales,代码行数:11,代码来源:generate_thumbnails.py


示例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)
开发者ID:novldp,项目名称:mapnik,代码行数:53,代码来源:filter_test.py


示例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')
开发者ID:socrata-platform,项目名称:carto-renderer,代码行数:51,代码来源:service.py


示例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)
开发者ID:ClaudioFloreani,项目名称:mapnik,代码行数:15,代码来源:load_map_test.py


示例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)
开发者ID:Blaxxun,项目名称:mapnik,代码行数:15,代码来源:load_map_test.py


示例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
开发者ID:mojodna,项目名称:debian-mapnik,代码行数:16,代码来源:glyph_symbolizer_test.py


示例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 []
开发者ID:RouxRC,项目名称:nosfinanceslocales,代码行数:16,代码来源:mapnik_render.py


示例16: 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)
            # 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(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)
开发者ID:mazl123321,项目名称:mapnik,代码行数:17,代码来源:load_map_test.py


示例17: init_mapnik

    def init_mapnik(self):
        style = file(options.style).read()
        style = style.replace('"dbname": "gis"', '"dbname": "%s"' % options.db_name)
        style = style.replace('"dbname"><![CDATA[gis]]>', '"dbname"><![CDATA[%s]]>' % options.db_name)
        for type in ('point', 'line', 'roads', 'polygon'):
            style = style.replace('planet_osm_%s' % type,
                                  self.viewprefix + '_' + type)


        m = mapnik.Map(tile_size, tile_size)
        m.buffer_size = 128
        # mapnik takes 700ms in db init
        mapnik.load_map_from_string(m, style, True, '/zdata/osm/openstreetmap-carto')

        m.resize(tile_size, tile_size)

        self.m = m
开发者ID:OsmHackTW,项目名称:osm-history,代码行数:17,代码来源:history_tile.py


示例18: 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'))
开发者ID:ParveenArora,项目名称:MeraMap,代码行数:17,代码来源:generate_xml.py


示例19: define_map

 def define_map(self, map):
     
     subquery = self.get_subqueries()
     schema = self.get_stylesheet()
     
     mapnik.load_map_from_string(map, schema)
     connection_params = dict(dbname=DB_NAME, user=DB_USER, host=DB_HOST, password=DB_PASSWORD, port=DB_PORT, )
     ds = mapnik.PostGIS(table='mtlocation_cityborder', **connection_params)
     map.layers[0].datasource = ds
     ds = mapnik.PostGIS(table=subquery[1], geometry_table="mtlocation_region", geometry_field='area', **connection_params)
     map.layers[1].datasource = ds
     ds = mapnik.PostGIS(table=subquery[2],  geometry_table="mtlocation_location", geometry_field='point', **connection_params)
     map.layers[2].datasource = ds
     ds = mapnik.PostGIS(table='mtlocation_ctaraillines', **connection_params)
     map.layers[3].datasource = ds
     ds = mapnik.PostGIS(table=subquery[4], geometry_table="mtlocation_location", geometry_field='point', **connection_params)
     map.layers[4].datasource = ds        
     self.map = map
开发者ID:JoeJasinski,项目名称:WindyTransit,代码行数:18,代码来源:cta_heatmap.py


示例20: pure_tile_rendering

def pure_tile_rendering(args):
    
        tile_dir = args[0] 
        mapfile = args[1]
        maxZoom = args[2]
        tile_uri = args[3]
        x = args[4]
        y = args[5]
        z = args[6]

        #not needed anymore, as the mapnik.map is sent directly to the function
        m = mapnik.Map(256, 256)
        # Load style XML
        mapnik.load_map_from_string(m, mapfile)
        # Obtain <Map> projection
        prj = mapnik.Projection(m.srs)
        # Projects between tile pixel co-ordinates and LatLong (EPSG:4326)
        tileproj = GoogleProjection(maxZoom+1)

        tile = (x,y)
        #print 'Tile: ', tile
        # Calculate pixel positions of bottom-left & top-right
        p0 = (tile[0] * 256, (tile[1] + 1) * 256)
        p1 = ((tile[0] + 1) * 256, tile[1] * 256)
        # Convert to LatLong (EPSG:4326)
        l0 = tileproj.fromPixelToLL(p0, z)
        l1 = tileproj.fromPixelToLL(p1, z)
        # Convert to map projection (e.g. mercator co-ords EPSG:900913)
        c0 = prj.forward(mapnik.Coord(l0[0],l0[1]))
        c1 = prj.forward(mapnik.Coord(l1[0],l1[1]))

        #c0, c1 = calcTileCoordinates(tile, z)
        tile_extent = (c0.x,c0.y, c1.x,c1.y)
        
        # Bounding box for the tile
        bbox = mapnik.Envelope(c0.x,c0.y, c1.x,c1.y)
        m.zoom_to_box(bbox)

        # Render image with default Agg renderer
        im = mapnik.Image(m.height, m.width)
        mapnik.render(m, im)
        im.save(tile_uri, 'png256') 
        return m.scale()/0.00028
开发者ID:RaKl,项目名称:TileGen,代码行数:43,代码来源:rendering.py



注:本文中的mapnik.load_map_from_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mapnik.mapnik_version函数代码示例发布时间:2022-05-27
下一篇:
Python mapnik.load_map函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap