def _get_tiles_paths( self, tile_directory_zoom=None, fallback_to_higher_zoom=False, matching_method="gdal", matching_precision=8, matching_max_zoom=None, ): # determine tile bounds in TileDirectory CRS td_bounds = reproject_geometry( self.tile.bbox, src_crs=self.tile.tp.crs, dst_crs=self._td_pyramid.crs ).bounds # find target zoom level if tile_directory_zoom is None: zoom = tile_to_zoom_level( self.tile, dst_pyramid=self._td_pyramid, matching_method=matching_method, precision=matching_precision ) if matching_max_zoom is not None: zoom = min([zoom, matching_max_zoom]) else: zoom = tile_directory_zoom if fallback_to_higher_zoom: tiles_paths = [] # check if tiles exist otherwise try higher zoom level while len(tiles_paths) == 0 and zoom >= 0: tiles_paths = _get_tiles_paths( basepath=self._basepath, ext=self._ext, pyramid=self._td_pyramid, bounds=td_bounds, zoom=zoom ) logger.debug("%s existing tiles found at zoom %s", len(tiles_paths), zoom) zoom -= 1 else: tiles_paths = _get_tiles_paths( basepath=self._basepath, ext=self._ext, pyramid=self._td_pyramid, bounds=td_bounds, zoom=zoom ) logger.debug("%s existing tiles found at zoom %s", len(tiles_paths), zoom) return tiles_paths
def test_tile_to_zoom_level(): tp_merc = BufferedTilePyramid("mercator") tp_geod = BufferedTilePyramid("geodetic") zoom = 9 col = 0 # mercator from geodetic # at Northern boundary assert tile_to_zoom_level(tp_merc.tile(zoom, 0, col), tp_geod) == 9 assert tile_to_zoom_level(tp_merc.tile(zoom, 0, col), tp_geod, matching_method="min") == 12 # at Equator assert tile_to_zoom_level( tp_merc.tile(zoom, tp_merc.matrix_height(zoom) // 2, col), tp_geod) == 9 assert tile_to_zoom_level(tp_merc.tile(zoom, tp_merc.matrix_height(zoom) // 2, col), tp_geod, matching_method="min") == 9 # at Southern boundary assert tile_to_zoom_level( tp_merc.tile(zoom, tp_merc.matrix_height(zoom) - 1, col), tp_geod) == 9 assert tile_to_zoom_level(tp_merc.tile(zoom, tp_merc.matrix_height(zoom) - 1, col), tp_geod, matching_method="min") == 12 assert tile_to_zoom_level(BufferedTilePyramid("mercator", metatiling=2, pixelbuffer=20).tile( 4, 0, 7), BufferedTilePyramid("geodetic", metatiling=8, pixelbuffer=20), matching_method="gdal") == 4 # geodetic from mercator # at Northern boundary assert tile_to_zoom_level(tp_geod.tile(zoom, 0, col), tp_merc) == 2 with pytest.raises(TopologicalError): tile_to_zoom_level(tp_geod.tile(zoom, 0, col), tp_merc, matching_method="min") # at Equator assert tile_to_zoom_level( tp_geod.tile(zoom, tp_geod.matrix_height(zoom) // 2, col), tp_merc) == 10 assert tile_to_zoom_level(tp_geod.tile(zoom, tp_geod.matrix_height(zoom) // 2, col), tp_merc, matching_method="min") == 10 # at Southern boundary assert tile_to_zoom_level( tp_geod.tile(zoom, tp_geod.matrix_height(zoom) - 1, col), tp_merc) == 2 with pytest.raises(TopologicalError): tile_to_zoom_level(tp_geod.tile(zoom, tp_geod.matrix_height(zoom) - 1, col), tp_merc, matching_method="min") # check wrong method with pytest.raises(ValueError): tile_to_zoom_level(tp_geod.tile(zoom, tp_geod.matrix_height(zoom) - 1, col), tp_merc, matching_method="invalid_method")