Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/async_geotiff/_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ def _create(

return instance

@property
def count(self) -> int:
"""The number of bands in the overview."""
return self._geotiff.count

@property
def crs(self) -> CRS:
"""The coordinate reference system of the overview."""
Expand Down
11 changes: 11 additions & 0 deletions src/async_geotiff/_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,19 @@ def width(self) -> int:
"""The width of the image in pixels."""
...

@property
def count(self) -> int:
"""The number of bands."""
...


class TiledMixin:
@property
def block_shapes(self: IsTiled) -> tuple[tuple[int, int], ...]:
"""Block shapes for each band. Each shape is (height, width)."""
shape = (self.tile_height, self.tile_width)
return (shape,) * self.count

@property
def tile_count(self: IsTiled) -> tuple[int, int]:
"""The number of tiles in the x and y directions."""
Expand Down
1 change: 1 addition & 0 deletions tests/test_geotiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ async def test_ifd_info(

with load_rasterio(file_name, variant=variant) as rasterio_ds:
assert rasterio_ds.bounds == geotiff.bounds
assert geotiff.block_shapes == tuple(rasterio_ds.block_shapes)
assert rasterio_ds.count == geotiff.count
assert rasterio_ds.dtypes[0] == geotiff.dtype
assert rasterio_ds.height == geotiff.height
Expand Down
21 changes: 21 additions & 0 deletions tests/test_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import pytest
from affine import Affine

from .image_list import ALL_COG_IMAGES

if TYPE_CHECKING:
from .conftest import LoadGeoTIFF, LoadRasterio

Expand All @@ -27,3 +29,22 @@ async def test_overview_transform(
decimated_transform = rasterio_ds.transform * Affine.scale(overview_level)

assert ovr.transform == decimated_transform


@pytest.mark.asyncio
@pytest.mark.parametrize(
("variant", "file_name"),
ALL_COG_IMAGES,
)
async def test_block_shapes_overview(
load_geotiff: LoadGeoTIFF,
load_rasterio: LoadRasterio,
variant: str,
file_name: str,
) -> None:
"""Overview block_shapes matches rasterio's block_shapes at overview level 0."""
geotiff = await load_geotiff(file_name, variant=variant)
overview = geotiff.overviews[0]

with load_rasterio(file_name, variant=variant, OVERVIEW_LEVEL=0) as rasterio_ds:
assert overview.block_shapes == tuple(rasterio_ds.block_shapes)