Skip to content

Commit 37a8017

Browse files
authored
fix: Support reading a single-tile image (#106)
* fix: Support single-tile images * update error * update tile_count docstring
1 parent 1cf793d commit 37a8017

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

‎src/async_geotiff/_geotiff.py‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ def __init__(self, tiff: TIFF) -> None:
9191
object.__setattr__(self, "_gkd", gkd)
9292

9393
for ifd in tiff.ifds:
94-
if ifd.tile_height is None or ifd.tile_width is None:
95-
raise ValueError("Only tiled GeoTIFFs are supported.")
94+
if ifd.strip_byte_counts is not None or ifd.strip_offsets is not None:
95+
raise ValueError("Striped GeoTIFFs are not supported.")
9696

9797
# Separate data IFDs and mask IFDs (skip the primary IFD at index 0)
9898
# Data IFDs are indexed by (width, height) for matching with masks
@@ -334,16 +334,14 @@ def shape(self) -> tuple[int, int]:
334334
@property
335335
def tile_height(self) -> int:
336336
"""The height in pixels per tile of the image."""
337-
tile_height = self._ifd.tile_height
338-
assert tile_height is not None, "Constructor validated that images are tiled" # noqa: S101
339-
return tile_height
337+
# A TIFF with a single tile can omit tile_height
338+
return self._ifd.tile_height or self._ifd.image_height
340339

341340
@property
342341
def tile_width(self) -> int:
343342
"""The width in pixels per tile of the image."""
344-
tile_width = self._ifd.tile_width
345-
assert tile_width is not None, "Constructor validated that images are tiled" # noqa: S101
346-
return tile_width
343+
# A TIFF with a single tile can omit tile_width
344+
return self._ifd.tile_width or self._ifd.image_width
347345

348346
@property
349347
def transform(self) -> Affine:

‎src/async_geotiff/_tile.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def width(self) -> int:
4949
class TiledMixin:
5050
@property
5151
def tile_count(self: IsTiled) -> tuple[int, int]:
52-
"""The number of tiles in the x and y directions, if the image is tiled."""
52+
"""The number of tiles in the x and y directions."""
5353
return (
5454
math.ceil(self.width / self.tile_width),
5555
math.ceil(self.height / self.tile_height),

0 commit comments

Comments
 (0)