From 994050125d4d23dde040b8eb3f44ee1c1a869382 Mon Sep 17 00:00:00 2001 From: Alexander Kalinovsky Date: Sat, 28 Feb 2026 14:08:35 +0100 Subject: [PATCH 1/2] feat: add block_shapes property to GeoTIFF and Overview Add block_shapes property similar to rasterio's API. Returns an ordered list of block shapes for each band, with each shape as (height, width). - Extend IsTiled protocol with count property - Add block_shapes to TiledMixin - Add count property to Overview for block_shapes compatibility Closes #101 --- src/async_geotiff/_overview.py | 5 +++++ src/async_geotiff/_tile.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/async_geotiff/_overview.py b/src/async_geotiff/_overview.py index 71c018b..f35d250 100644 --- a/src/async_geotiff/_overview.py +++ b/src/async_geotiff/_overview.py @@ -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.""" diff --git a/src/async_geotiff/_tile.py b/src/async_geotiff/_tile.py index f8780fe..4aef1ba 100644 --- a/src/async_geotiff/_tile.py +++ b/src/async_geotiff/_tile.py @@ -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.""" From bcd3fab4f0e2762176c1bb5270529b188b5da602 Mon Sep 17 00:00:00 2001 From: Alexander Kalinovsky Date: Sat, 28 Feb 2026 14:08:38 +0100 Subject: [PATCH 2/2] test: add block_shapes assertions for GeoTIFF and Overview - Add block_shapes check to test_ifd_info for all test images - Add test_block_shapes_overview for COG overview levels --- tests/test_geotiff.py | 1 + tests/test_overview.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/tests/test_geotiff.py b/tests/test_geotiff.py index 4627cab..db655a9 100644 --- a/tests/test_geotiff.py +++ b/tests/test_geotiff.py @@ -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 diff --git a/tests/test_overview.py b/tests/test_overview.py index 8b20634..cffbb64 100644 --- a/tests/test_overview.py +++ b/tests/test_overview.py @@ -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 @@ -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)