本文整理汇总了Python中mapproxy.grid.MetaGrid.main_tile方法的典型用法代码示例。如果您正苦于以下问题:Python MetaGrid.main_tile方法的具体用法?Python MetaGrid.main_tile怎么用?Python MetaGrid.main_tile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapproxy.grid.MetaGrid
的用法示例。
在下文中一共展示了MetaGrid.main_tile方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TileManager
# 需要导入模块: from mapproxy.grid import MetaGrid [as 别名]
# 或者: from mapproxy.grid.MetaGrid import main_tile [as 别名]
class TileManager(object):
"""
Manages tiles for a single grid.
Loads tiles from the cache, creates new tiles from sources and stores them
into the cache, or removes tiles.
:param pre_store_filter: a list with filter. each filter will be called
with a tile before it will be stored to disc. the filter should
return this or a new tile object.
"""
def __init__(self, grid, cache, sources, format, image_opts=None, request_format=None,
meta_buffer=None, meta_size=None, minimize_meta_requests=False,
pre_store_filter=None, concurrent_tile_creators=1,max_age=None):
self.grid = grid
self.cache = cache
self.meta_grid = None
self.format = format
self.image_opts = image_opts
self.request_format = request_format or format
self.sources = sources
self.minimize_meta_requests = minimize_meta_requests
self._max_age = max_age
self._expire_timestamp = None
self.transparent = self.sources[0].transparent
self.pre_store_filter = pre_store_filter or []
self.concurrent_tile_creators = concurrent_tile_creators
if meta_buffer or (meta_size and not meta_size == [1, 1]):
if all(source.supports_meta_tiles for source in sources):
self.meta_grid = MetaGrid(grid, meta_size=meta_size, meta_buffer=meta_buffer)
elif any(source.supports_meta_tiles for source in sources):
raise ValueError('meta tiling configured but not supported by all sources')
@contextmanager
def session(self):
"""
Context manager for access to the cache. Cleans up after usage
for connection based caches.
>>> with tile_manager.session(): #doctest: +SKIP
... tile_manager.load_tile_coords(tile_coords)
"""
yield
self.cleanup()
def cleanup(self):
if hasattr(self.cache, 'cleanup'):
self.cache.cleanup()
def load_tile_coord(self, tile_coord, with_metadata=False):
tile = Tile(tile_coord)
self.cache.load_tile(tile, with_metadata)
if tile.coord is not None and not self.is_cached(tile):
# missing or staled
creator = self.creator()
created_tiles = creator.create_tiles([tile])
for created_tile in created_tiles:
if created_tile.coord == tile_coord:
return created_tile
return tile
def load_tile_coords(self, tile_coords, with_metadata=False):
tiles = TileCollection(tile_coords)
uncached_tiles = []
# load all in batch
self.cache.load_tiles(tiles, with_metadata)
for tile in tiles:
if tile.coord is not None and not self.is_cached(tile):
# missing or staled
uncached_tiles.append(tile)
if uncached_tiles:
creator = self.creator()
created_tiles = creator.create_tiles(uncached_tiles)
for created_tile in created_tiles:
if created_tile.coord in tiles:
tiles[created_tile.coord].source = created_tile.source
return tiles
def remove_tile_coords(self, tile_coords):
tiles = TileCollection(tile_coords)
self.cache.remove_tiles(tiles)
def creator(self):
return TileCreator(self.cache, self.sources, self.grid, self.meta_grid, self)
def lock(self, tile):
if self.meta_grid:
tile = Tile(self.meta_grid.main_tile(tile.coord))
return self.cache.lock(tile)
def is_cached(self, tile):
"""
Return True if the tile is cached.
#.........这里部分代码省略.........
示例2: TileManager
# 需要导入模块: from mapproxy.grid import MetaGrid [as 别名]
# 或者: from mapproxy.grid.MetaGrid import main_tile [as 别名]
class TileManager(object):
"""
Manages tiles for a single grid.
Loads tiles from the cache, creates new tiles from sources and stores them
into the cache, or removes tiles.
:param pre_store_filter: a list with filter. each filter will be called
with a tile before it will be stored to disc. the filter should
return this or a new tile object.
"""
def __init__(self, grid, cache, sources, format, image_opts=None, request_format=None,
meta_buffer=None, meta_size=None, minimize_meta_requests=False,
pre_store_filter=None, concurrent_tile_creators=1):
self.grid = grid
self.cache = cache
self.meta_grid = None
self.format = format
self.image_opts = image_opts
self.request_format = request_format or format
self.sources = sources
self.minimize_meta_requests = minimize_meta_requests
self._expire_timestamp = None
self.transparent = self.sources[0].transparent
self.pre_store_filter = pre_store_filter or []
self.concurrent_tile_creators = concurrent_tile_creators
if meta_buffer or (meta_size and not meta_size == [1, 1]):
if all(source.supports_meta_tiles for source in sources):
self.meta_grid = MetaGrid(grid, meta_size=meta_size, meta_buffer=meta_buffer)
elif any(source.supports_meta_tiles for source in sources):
raise ValueError('meta tiling configured but not supported by all sources')
@contextmanager
def session(self):
"""
Context manager for access to the cache. Cleans up after usage
for connection based caches.
>>> with tile_manager.session(): #doctest: +SKIP
... tile_manager.load_tile_coords(tile_coords)
"""
yield
self.cleanup()
def cleanup(self):
if hasattr(self.cache, 'cleanup'):
self.cache.cleanup()
def load_tile_coord(self, tile_coord, dimensions=None, with_metadata=False):
tile = Tile(tile_coord)
self.cache.load_tile(tile, with_metadata)
if tile.coord is not None and not self.is_cached(tile, dimensions=dimensions):
# missing or staled
creator = self.creator(dimensions=dimensions)
created_tiles = creator.create_tiles([tile])
for created_tile in created_tiles:
if created_tile.coord == tile_coord:
return created_tile
return tile
def load_tile_coords(self, tile_coords, dimensions=None, with_metadata=False):
tiles = TileCollection(tile_coords)
uncached_tiles = []
# load all in batch
self.cache.load_tiles(tiles, with_metadata)
for tile in tiles:
if tile.coord is not None and not self.is_cached(tile, dimensions=dimensions):
# missing or staled
uncached_tiles.append(tile)
if uncached_tiles:
creator = self.creator(dimensions=dimensions)
created_tiles = creator.create_tiles(uncached_tiles)
for created_tile in created_tiles:
if created_tile.coord in tiles:
tiles[created_tile.coord].source = created_tile.source
return tiles
def remove_tile_coords(self, tile_coords, dimensions=None):
tiles = TileCollection(tile_coords)
self.cache.remove_tiles(tiles)
def creator(self, dimensions=None):
return TileCreator(self.cache, self.sources, self.grid, self.meta_grid,
self, dimensions=dimensions)
def lock(self, tile):
if self.meta_grid:
tile = Tile(self.meta_grid.main_tile(tile.coord))
return self.cache.lock(tile)
def is_cached(self, tile, dimensions=None):
"""
Return True if the tile is cached.
#.........这里部分代码省略.........