def __init__(self, grid, cache, sources, format, locker, image_opts=None, request_format=None, meta_buffer=None, meta_size=None, minimize_meta_requests=False, identifier=None, pre_store_filter=None, concurrent_tile_creators=1, tile_creator_class=None, bulk_meta_tiles=False, rescale_tiles=0, cache_rescaled_tiles=False, ): self.grid = grid self.cache = cache self.locker = locker self.identifier = identifier 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.pre_store_filter = pre_store_filter or [] self.concurrent_tile_creators = concurrent_tile_creators self.tile_creator_class = tile_creator_class or TileCreator self.rescale_tiles = rescale_tiles self.cache_rescaled_tiles = cache_rescaled_tiles 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') elif meta_size and not meta_size == [1, 1] and bulk_meta_tiles: # meta tiles configured but all sources are tiled # use bulk_meta_tile mode that download tiles in parallel self.meta_grid = MetaGrid(grid, meta_size=meta_size, meta_buffer=0) self.tile_creator_class = partial(self.tile_creator_class, bulk_meta_tiles=True)
def test_metatile_non_default_meta_size(self): mgrid = MetaGrid(grid=TileGrid(), meta_size=(4, 2)) meta_tile = mgrid.meta_tile((4, 5, 3)) assert_almost_equal_bbox( meta_tile.bbox, (0.0, 0.0, 20037508.342789244, 10018754.171394622)) eq_(meta_tile.size, (1024, 512)) eq_(meta_tile.grid_size, (4, 2))
def test_metagrid_tiles_w_meta_size(): mgrid = MetaGrid(grid=TileGrid(), meta_size=(4, 2)) assert list(mgrid.meta_tile((1, 2, 2)).tile_patterns) == \ [((0, 3, 2), (0, 0)), ((1, 3, 2), (256, 0)), ((2, 3, 2), (512, 0)), ((3, 3, 2), (768, 0)), ((0, 2, 2), (0, 256)), ((1, 2, 2), (256, 256)), ((2, 2, 2), (512, 256)), ((3, 2, 2), (768, 256))]
def __init__(self, task, worker_pool, handle_stale=False, handle_uncached=False, work_on_metatiles=True, skip_geoms_for_last_levels=0, progress_logger=None): self.tile_mgr = task.tile_manager self.task = task self.worker_pool = worker_pool self.handle_stale = handle_stale self.handle_uncached = handle_uncached self.work_on_metatiles = work_on_metatiles self.skip_geoms_for_last_levels = skip_geoms_for_last_levels self.progress_logger = progress_logger num_seed_levels = len(task.levels) self.report_till_level = task.levels[int(num_seed_levels * 0.8)] meta_size = self.tile_mgr.meta_grid.meta_size if self.tile_mgr.meta_grid else ( 1, 1) self.tiles_per_metatile = meta_size[0] * meta_size[1] self.grid = MetaGrid(self.tile_mgr.grid, meta_size=meta_size, meta_buffer=0) self.progress = 0.0 self.eta = ETA() self.count = 0
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')
def test_metatile_bbox(self): mgrid = MetaGrid(grid=TileGrid(), meta_size=(2, 2)) meta_tile = mgrid.meta_tile((0, 0, 2)) assert meta_tile.bbox == (-20037508.342789244, -20037508.342789244, 0.0, 0.0) meta_tile = mgrid.meta_tile((1, 1, 2)) assert meta_tile.bbox == (-20037508.342789244, -20037508.342789244, 0.0, 0.0) meta_tile = mgrid.meta_tile((4, 5, 3)) assert_almost_equal_bbox(meta_tile.bbox, (0.0, 0.0, 10018754.171394622, 10018754.171394622))
def test_metatile_non_default_meta_size(self): mgrid = MetaGrid(grid=self.grid, meta_size=(4, 2), meta_buffer=0) meta_tile = mgrid.meta_tile((4, 3, 6)) eq_(meta_tile.bbox, (0.0, 0.0, 180.0, 90.0)) eq_(meta_tile.size, (1024, 512)) eq_(meta_tile.grid_size, (4, 2)) eq_(meta_tile.tile_patterns, [((4, 3, 6), (0, 0)), ((5, 3, 6), (256, 0)), ((6, 3, 6), (512, 0)), ((7, 3, 6), (768, 0)), ((4, 2, 6), (0, 256)), ((5, 2, 6), (256, 256)), ((6, 2, 6), (512, 256)), ((7, 2, 6), (768, 256))])
def test_metagrid_tiles(): mgrid = MetaGrid(grid=TileGrid(), meta_size=(2, 2)) assert list(mgrid.meta_tile((0, 0, 0)).tile_patterns) == \ [((0, 0, 0), (0, 0))] assert list(mgrid.meta_tile((0, 1, 1)).tile_patterns) == \ [((0, 1, 1), (0, 0)), ((1, 1, 1), (256, 0)), ((0, 0, 1), (0, 256)), ((1, 0, 1), (256, 256))] assert list(mgrid.meta_tile((1, 2, 2)).tile_patterns) == \ [((0, 3, 2), (0, 0)), ((1, 3, 2), (256, 0)), ((0, 2, 2), (0, 256)), ((1, 2, 2), (256, 256))]
def __init__(self, task, worker_pool, handle_stale=False, handle_uncached=False, work_on_metatiles=True, skip_geoms_for_last_levels=0, progress_logger=None, seed_progress=None): self.tile_mgr = task.tile_manager self.task = task self.worker_pool = worker_pool self.handle_stale = handle_stale self.handle_uncached = handle_uncached self.work_on_metatiles = work_on_metatiles self.skip_geoms_for_last_levels = skip_geoms_for_last_levels self.progress_logger = progress_logger num_seed_levels = len(task.levels) if num_seed_levels >= 4: self.report_till_level = task.levels[num_seed_levels - 2] else: self.report_till_level = task.levels[num_seed_levels - 1] meta_size = self.tile_mgr.meta_grid.meta_size if self.tile_mgr.meta_grid else ( 1, 1) self.tiles_per_metatile = meta_size[0] * meta_size[1] self.grid = MetaGrid(self.tile_mgr.grid, meta_size=meta_size, meta_buffer=0) self.count = 0 self.seed_progress = seed_progress or SeedProgress() # It is possible that we 'walk' through the same tile multiple times # when seeding irregular tile grids[0]. limit_sub_bbox prevents that we # recurse into the same area multiple times, but it is still possible # that a tile is processed multiple times. Locking prevents that a tile # is seeded multiple times, but it is possible that we count the same tile # multiple times (in dry-mode, or while the tile is in the process queue). # Tile counts can be off by 280% with sqrt2 grids. # We keep a small cache of already processed tiles to skip most duplicates. # A simple cache of 64 tile coordinates for each level already brings the # difference down to ~8%, which is good enough and faster than a more # sophisticated FIFO cache with O(1) lookup, or even caching all tiles. # [0] irregular tile grids: where one tile does not have exactly 4 subtiles # Typically when you use res_factor, or a custom res list. self.seeded_tiles = {l: deque(maxlen=64) for l in task.levels}
def test_minimal_tiles_fragmented_ul(self): self.mgrid = MetaGrid(grid=tile_grid('EPSG:4326', origin='ul'), meta_size=(2, 2), meta_buffer=10) sgrid = self.mgrid.minimal_meta_tile( [ (2, 0, 3), (1, 1, 3), (2, 2, 3), ]) eq_(sgrid.grid_size, (2, 3)) eq_(list(sgrid.tile_patterns), [ ((1, 0, 3), (10, 0)), ((2, 0, 3), (266, 0)), ((1, 1, 3), (10, 256)), ((2, 1, 3), (266, 256)), ((1, 2, 3), (10, 512)), ((2, 2, 3), (266, 512)), ] ) eq_(sgrid.bbox, (-136.7578125, -46.7578125, -43.2421875, 90.0))
def __init__(self): self.meta_grid = MetaGrid(TileGrid(is_geodetic=True), meta_size=(2, 2))
def __init__(self): self.meta_grid = MetaGrid(TileGrid(), meta_size=(2, 2))
def setup(self): self.mgrid = MetaGrid(grid=tile_grid('EPSG:4326'), meta_size=(2, 2), meta_buffer=10)
def setup(self): self.grid = tile_grid('EPSG:4326', res_factor='sqrt2') self.mgrid = MetaGrid(grid=self.grid, meta_size=(4, 4), meta_buffer=10)
def setup(self): self.tile_grid = tile_grid('EPSG:4326', origin='ul') self.mgrid = MetaGrid(grid=self.tile_grid, meta_size=(2, 2), meta_buffer=10)