Skip to content

Commit d53166c

Browse files
authored
feat: Add .res property to Overview (#90)
1 parent bd22c2b commit d53166c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/async_geotiff/_geotiff.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import math
43
from dataclasses import dataclass, field
54
from functools import cached_property
65
from typing import TYPE_CHECKING, Self
@@ -351,16 +350,6 @@ def photometric(self) -> PhotometricInterpretation | None: # noqa: PLR0911
351350

352351
return None
353352

354-
@property
355-
def res(self) -> tuple[float, float]:
356-
"""Return the (width, height) of pixels in the units of its CRS."""
357-
transform = self.transform
358-
# For rotated images, resolution is the magnitude of the pixel size
359-
# calculated from the transform matrix components
360-
res_x = math.sqrt(transform.a**2 + transform.d**2)
361-
res_y = math.sqrt(transform.b**2 + transform.e**2)
362-
return (res_x, res_y)
363-
364353
@property
365354
def shape(self) -> tuple[int, int]:
366355
"""Get the shape (height, width) of the full image."""

src/async_geotiff/_transform.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import math
56
from math import floor
67
from typing import TYPE_CHECKING, Literal, Protocol
78

@@ -48,6 +49,18 @@ def index(
4849

4950
return (op(row_frac), op(col_frac))
5051

52+
@property
53+
def res(self: HasTransform) -> tuple[float, float]:
54+
"""Return the (width, height) of pixels in the units of its CRS."""
55+
transform = self.transform
56+
57+
# For rotated images, resolution is the magnitude of the pixel size
58+
# calculated from the transform matrix components
59+
res_x = math.sqrt(transform.a**2 + transform.d**2)
60+
res_y = math.sqrt(transform.b**2 + transform.e**2)
61+
62+
return (res_x, res_y)
63+
5164
def xy(
5265
self: HasTransform,
5366
row: int,

0 commit comments

Comments
 (0)