当前位置: 首页>>代码示例>>Python>>正文


Python mapnik2.load_map函数代码示例

本文整理汇总了Python中mapnik2.load_map函数的典型用法代码示例。如果您正苦于以下问题:Python load_map函数的具体用法?Python load_map怎么用?Python load_map使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了load_map函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(
            self, tilegrid, mapfile, data_buffer=128, image_buffer=0, output_format='png256', resolution=2,
            layers_fields={}, drop_empty_utfgrid=False, proj4_literal=None, **kwargs):
        """
        Constructs a MapnikTileStore

        :param tilegrid: the tilegrid.
        :param mapfile: the file used to render the tiles.
        :param buffer_size: the image buffer size default is 128.
        :param output_format: the output format,
            possible values 'jpeg', 'png', 'png256', 'grid',
            default is 'png256'
        :param layers: the layers and fields used in the grid generation,
            example: { 'my_layer': ['my_first_field', 'my_segonf_field']},
            default is {}.
        :param **kwargs: for extended class.
        """

        TileStore.__init__(self, **kwargs)
        self.tilegrid = tilegrid
        self.buffer = image_buffer
        self.output_format = output_format
        self.resolution = resolution
        self.layers_fields = layers_fields
        self.drop_empty_utfgrid = drop_empty_utfgrid

        self.mapnik = mapnik.Map(tilegrid.tile_size, tilegrid.tile_size)
        mapnik.load_map(self.mapnik, mapfile, True)
        self.mapnik.buffer_size = data_buffer
        if proj4_literal is not None:
            self.mapnik.srs = proj4_literal
开发者ID:Bobfrat,项目名称:tilecloud,代码行数:31,代码来源:mapnik_.py

示例2: render_legend

def render_legend(mapfile, tile_uri):
    m = mapnik.Map(1024, 2048)
    # Load style XML
    mapnik.load_map(m, mapfile, True)
    # Obtain <Map> projection
    prj = mapnik.Projection(m.srs)
    # Projects between tile pixel co-ordinates and LatLong (EPSG:4326)
    tileproj = GoogleProjection(20)

    # Convert to map projection (e.g. mercator co-ords EPSG:900913)
    c0 = prj.forward(mapnik.Coord(14.4503,50.0673))
    c1 = prj.forward(mapnik.Coord(14.457,50.0678))

    # Bounding box for the tile
    if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800:
        bbox = mapnik.Box2d(c0.x,c0.y, c1.x,c1.y)
    else:
        bbox = mapnik.Envelope(c0.x,c0.y, c1.x,c1.y)
    render_size_x = 1024
    render_size_y = 1500
    m.resize(render_size_x, render_size_y)
    m.zoom_to_box(bbox)
    m.buffer_size = 128

    # Render image with default Agg renderer
    im = mapnik.Image(render_size_x, render_size_y)
    mapnik.render(m, im)
    im.save(tile_uri, 'png256')

    surface = cairo.SVGSurface('legend.svg', render_size_x, render_size_y)
    mapnik.render(m, surface)
    surface.finish()
开发者ID:auto-mat,项目名称:rendering-PNK-ZM,代码行数:32,代码来源:generate_legend.py

示例3: test_hit_grid

def test_hit_grid():
    import os
    from itertools import groupby

    def rle_encode(l):
        """ encode a list of strings with run-length compression """
        return ["%d:%s" % (len(list(group)), name) for name, group in groupby(l)]

    m = mapnik2.Map(256,256);
    mapnik2.load_map(m,'../data/good_maps/agg_poly_gamma_map.xml');
    m.zoom_all()
    join_field = 'NAME'
    fg = [] # feature grid
    for y in range(0, 256, 4):
        for x in range(0, 256, 4):
            featureset = m.query_map_point(0,x,y)
            added = False
            for feature in featureset.features:
                fg.append(feature[join_field])
                added = True
            if not added:
                fg.append('')
    hit_list = '|'.join(rle_encode(fg))
    eq_(hit_list[:16],'730:|2:Greenland')
    eq_(hit_list[-12:],'1:Chile|812:')
开发者ID:dpaleino,项目名称:mapnik,代码行数:25,代码来源:datasource_test.py

示例4: serialize

def serialize(xml, options):
    try:
        try:
            import mapnik2 as mapnik
        except ImportError:
            import mapnik
    except ImportError:
        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:cuu508,项目名称:mapnik-stylesheets,代码行数:25,代码来源:generate_xml.py

示例5: renderArea

    def renderArea(self, width, height, srs, xmin, ymin, xmax, ymax, zoom):
        """
        """
        if self.mapnik is None:
            self.mapnik = mapnik.Map(0, 0)

            if exists(self.mapfile):
                mapnik.load_map(self.mapnik, str(self.mapfile))

            else:
                handle, filename = mkstemp()
                os.write(handle, urlopen(self.mapfile).read())
                os.close(handle)

                mapnik.load_map(self.mapnik, filename)
                os.unlink(filename)

        self.mapnik.width = width
        self.mapnik.height = height
        self.mapnik.zoom_to_box(mapnik.Envelope(xmin, ymin, xmax, ymax))

        img = mapnik.Image(width, height)
        mapnik.render(self.mapnik, img)

        img = Image.fromstring("RGBA", (width, height), img.tostring())

        return img
开发者ID:ricebeans,项目名称:TileStache,代码行数:27,代码来源:Providers.py

示例6: loop

    def loop(self, nb):
        self.m = mapnik.Map(TILES_SIZE, TILES_SIZE)
        # Load style XML
        mapnik.load_map(self.m, self.mapfile, True)
        # Obtain <Map> projection
        self.prj = mapnik.Projection(self.m.srs)
        # Projects between tile pixel co-ordinates and LatLong (EPSG:4326)
        self.tileproj = GoogleProjection(self.maxZoom + 1)

        while True:
            #Fetch a tile from the queue and render it
            r = self.q.get()
            if (r == None):
                self.q.task_done()
                break
            else:
                (name, tile_uri, x, y, z) = r

            exists = ""
            if os.path.isfile(tile_uri + '.' + FILE_EXTENSION):
                exists = "exists"
            else:
                self.render_tile(tile_uri, x, y, z)

            self.printLock.acquire()
            print name, ":", z, x, y, exists
            self.printLock.release()
            self.q.task_done()
开发者ID:sbrunner,项目名称:map,代码行数:28,代码来源:generate_tiles_1024.py

示例7: run

    def run(self):
        self.mapnik_map = mapnik2.Map(self.width, self.height)
        mapnik2.load_map(self.mapnik_map, self.config, True)

        self.map_projection = mapnik2.Projection(self.mapnik_map.srs)
        self.tile_projection = projections.GoogleProjection()  

        while True:
            tile_parameters = None

            # Try to fetch a tile from any queue
            for tile_queue in self.tile_queues:
                try:
                    tile_parameters = tile_queue.get_nowait()
                    break 
                except Queue.Empty:
                    pass

            # Couldn't get tile parameters from any queue--all done
            if not tile_parameters:
                return

            # Skip rendering existing tiles
            if self.skip_existing:
                filename = tile_parameters[0]

                if os.path.exists(filename):
                    print 'Skipping %s' % (filename)
                    tile_queue.task_done()

                    continue

            self.render(*tile_parameters)
            tile_queue.task_done()
开发者ID:seanlee928,项目名称:invar,代码行数:34,代码来源:renderer.py

示例8: renderTile

    def renderTile(self, width, height, srs, coord):
        """
        """
        if self.mapnik is None:
            self.mapnik = mapnik.Map(0, 0)
            mapnik.load_map(self.mapnik, str(self.mapfile))

        # buffer as fraction of tile size
        buffer = float(self.buffer) / 256

        nw = self.layer.projection.coordinateLocation(coord.left(buffer).up(buffer))
        se = self.layer.projection.coordinateLocation(coord.right(1 + buffer).down(1 + buffer))
        ul = self.mercator.locationProj(nw)
        lr = self.mercator.locationProj(se)

        self.mapnik.width = width + 2 * self.buffer
        self.mapnik.height = height + 2 * self.buffer
        self.mapnik.zoom_to_box(mapnik.Box2d(ul.x, ul.y, lr.x, lr.y))

        # create grid as same size as map/image
        grid = mapnik.Grid(width + 2 * self.buffer, height + 2 * self.buffer)
        # render a layer to that grid array
        mapnik.render_layer(self.mapnik, grid, layer=self.layer_index, fields=self.fields)
        # extract a gridview excluding the buffer
        grid_view = grid.view(self.buffer, self.buffer, width, height)
        # then encode the grid array as utf, resample to 1/scale the size, and dump features
        grid_utf = grid_view.encode('utf', resolution=self.scale, add_features=True)

        if self.wrapper is None:
            return SaveableResponse(json.dumps(grid_utf))
        else:
            return SaveableResponse(self.wrapper + '(' + json.dumps(grid_utf) + ')')
开发者ID:cybertoast,项目名称:TileStache,代码行数:32,代码来源:MapnikGrid.py

示例9: loop

    def loop(self):
        
        self.m = mapnik.Map(256, 256)
        # Load style XML
        mapnik.load_map(self.m, self.mapfile, True)
        # Obtain <Map> projection
        self.prj = mapnik.Projection(self.m.srs)
        # Projects between tile pixel co-ordinates and LatLong (EPSG:4326)
        self.tileproj = GoogleProjection(self.maxZoom+1)
                
        while True:
            #Fetch a tile from the queue and render it
            r = self.q.get()
            if (r == None):
                self.q.task_done()
                break
            else:
                (name, tile_uri, x, y, z) = r

            exists= ""
            if os.path.isfile(tile_uri):
                exists= "exists"
            else:
                self.render_tile(tile_uri, x, y, z)
            bytes=os.stat(tile_uri)[6]
            empty= ''
            if bytes == 103:
                empty = " Empty Tile "
            self.printLock.acquire()
            print name, ":", z, x, y, exists, empty
            self.printLock.release()
            self.q.task_done()
开发者ID:zachatrocity,项目名称:mapnik-fork,代码行数:32,代码来源:generate_tiles_multiprocess.py

示例10: renderTile

    def renderTile(self, width, height, srs, coord):
        """
        """
        if self.mapnik is None:
            self.mapnik = mapnik.Map(0, 0)
            mapnik.load_map(self.mapnik, str(self.mapfile))

        nw = self.layer.projection.coordinateLocation(coord)
        se = self.layer.projection.coordinateLocation(coord.right().down())
        ul = self.mercator.locationProj(nw)
        lr = self.mercator.locationProj(se)

        self.mapnik.width = width
        self.mapnik.height = height
        self.mapnik.zoom_to_box(mapnik.Box2d(ul.x, ul.y, lr.x, lr.y))

        # create grid as same size as map/image
        grid = mapnik.Grid(width, height)
        # render a layer to that grid array
        mapnik.render_layer(self.mapnik, grid, layer=self.layer_index, fields=self.fields)
        # then encode the grid array as utf, resample to 1/scale the size, and dump features
        grid_utf = grid.encode("utf", resolution=self.scale, features=True)

        if self.wrapper is None:
            return SaveableResponse(json.dumps(grid_utf))
        else:
            return SaveableResponse(self.wrapper + "(" + json.dumps(grid_utf) + ")")
开发者ID:ricebeans,项目名称:TileStache,代码行数:27,代码来源:MapnikGrid.py

示例11: renderToPdf

def renderToPdf(envLL, filename, sizex, sizey):
    """Renders the specified Box2d and zoom level as a PDF"""
    basefilename = os.path.splitext(filename)[0]
    mergedpdf = None
    for mapname in MAPNIK_LAYERS:
        print 'Rendering', mapname
        # Render layer PDF.
        localfilename = basefilename + '_' + mapname + '.pdf';
        file = open(localfilename, 'wb')
        surface = cairo.PDFSurface(file.name, sizex, sizey) 
        envMerc = LLToMerc(envLL)
        map = mapnik.Map(sizex, sizey)
        mapnik.load_map(map, mapname + ".xml")
        map.zoom_to_box(envMerc)
        mapnik.render(map, surface)
        surface.finish()
        file.close()
        # Merge with master.
        if not mergedpdf:            
            mergedpdf = PdfFileWriter()
            localpdf = PdfFileReader(open(localfilename, "rb"))
            page = localpdf.getPage(0)
            mergedpdf.addPage(page)
        else:
            localpdf = PdfFileReader(open(localfilename, "rb"))
            page.mergePage(localpdf.getPage(0))
    output = open(filename, 'wb')
    mergedpdf.write(output)
    output.close()
开发者ID:calvinmetcalf,项目名称:TopOSM,代码行数:29,代码来源:toposm.py

示例12: drawTile_bbox

    def drawTile_bbox(self,bbox,imgx,imgy,fname):
        """Call Mapnik to draw a map image for data in
        bounding box bbox.  The image size is imgx by imgy pixels, and
        the output filename is fname.

        29sep2009  GJ  ORIGINAL VERSION, based on generate_image.py
        06jan2010  GJ  Renamed to drawTile_bbox from drawTile
        """
        mapfile = str(self.preferences_list['mapfile'])
        map_uri = str(fname)
        print ("mapfile=%s" % mapfile)

        # png image
        m = mapnik.Map(imgx,imgy)
        mapnik.load_map(m,mapfile)
        m.zoom_to_box(bbox)
        im = mapnik.Image(imgx,imgy)

        if HAS_MAPNIK2:
            # We apply the scale factor to the map
            print 'using scale factors from mapnik2'
            scale_factor = float( self.preferences_list['dpi'] ) / 72
            print "Scale factor is: ", scale_factor, "================="
            mapnik.render(m, im, scale_factor)
        else:
            print 'NOT using scale_factors'
            mapnik.render(m, im)
            
        view = im.view(0,0,imgx,imgy) # x,y,width,height
        view.save(map_uri,'png')
开发者ID:hixi,项目名称:townguide,代码行数:30,代码来源:townguide.py

示例13: init_zoomlevel

 def init_zoomlevel(self, z):
     self.currentz = z
     self.tilesize = getTileSize(NTILES[z], True)
     self.maps = {}
     for mapName in MAPNIK_LAYERS:
         console.debugMessage('Loading mapnik.Map: ' + mapName)
         self.maps[mapName] = mapnik.Map(self.tilesize, self.tilesize)
         mapnik.load_map(self.maps[mapName], mapName + ".xml")
开发者ID:calvinmetcalf,项目名称:TopOSM,代码行数:8,代码来源:toposm.py

示例14: compile

 def compile(self, url, compile_callback):
     """ retrieve and compile a mapnik xml file. only called when the map
     is not already in static cache. calls compile_callback when  """
     self.mapnik_maps[url] = mapnik.Map(self.tilesize, self.tilesize)
     open("%s_compiled.xml" % self.filecache(url), 'w').write(
         cascadenik.compile(self.filecache(url), urlcache=True))
     mapnik.load_map(self.mapnik_maps[url], "%s_compiled.xml" % self.filecache(url))
     compile_callback(self.mapnik_maps[url])
开发者ID:Open-Source-GIS,项目名称:TileLive,代码行数:8,代码来源:cache.py

示例15: test_load_save_map

def test_load_save_map():
    map = mapnik2.Map(256,256)
    in_map = "../data/good_maps/raster_symbolizer.xml"
    mapnik2.load_map(map, in_map)

    out_map = mapnik2.save_map_to_string(map)
    assert 'RasterSymbolizer' in out_map
    assert 'RasterColorizer' in out_map
    assert 'stop' in out_map
开发者ID:BenMoores,项目名称:mapnik-trunk,代码行数:9,代码来源:raster_symbolizer_test.py


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