Skip to content
Closed
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
3 changes: 3 additions & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ History

Latest
------
- BUG: Use ``@`` instead of ``*`` for ``Affine`` multiplication to avoid
affine 3.0.1 ``PendingDeprecationWarning`` (issue #937)
- DEP: Add explicit ``affine>=3.0`` dependency (issue #937)

0.23.0
------
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ classifiers = [
]
requires-python = ">=3.12"
dependencies = [
"affine>=3.0",
"packaging",
"rasterio>=1.4.3",
# https://github.com/pydata/xarray/issues/11000
Expand Down
10 changes: 5 additions & 5 deletions rioxarray/_spatial_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ def affine_to_coords(
dict: x and y coordinate arrays.

"""
transform = affine * affine.translation(0.5, 0.5)
transform = affine @ affine.translation(0.5, 0.5)
if affine.is_rectilinear and not _affine_has_rotation(affine):
x_coords, _ = transform * (numpy.arange(width), numpy.zeros(width))
_, y_coords = transform * (numpy.zeros(height), numpy.arange(height))
x_coords, _ = transform @ (numpy.arange(width), numpy.zeros(width))
_, y_coords = transform @ (numpy.zeros(height), numpy.arange(height))
else:
x_coords, y_coords = transform * numpy.meshgrid(
x_coords, y_coords = transform @ numpy.meshgrid(
numpy.arange(width),
numpy.arange(height),
)
return {y_dim: y_coords, x_dim: x_coords}
return {y_dim: numpy.asarray(y_coords), x_dim: numpy.asarray(x_coords)}


def _generate_spatial_coords(
Expand Down
2 changes: 1 addition & 1 deletion rioxarray/rioxarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def transform(self, recalc: bool = False) -> Affine:
src_resolution_x, src_resolution_y = self.resolution(recalc=recalc)
except (DimensionMissingCoordinateError, DimensionError):
return Affine.identity() if transform is None else transform
return Affine.translation(src_left, src_top) * Affine.scale(
return Affine.translation(src_left, src_top) @ Affine.scale(
src_resolution_x, src_resolution_y
)

Expand Down
29 changes: 29 additions & 0 deletions test/integration/test_integration__io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,3 +1612,32 @@ def test_reading_writing_rpcs(tmp_path):
assert (
dst.rpcs is not None
), "Existing RPCs in dst raster (through rpc attribute)"


@pytest.mark.parametrize(
"transform",
[Affine(1, 0, 0, 0, -1, 4), Affine(1, 0.5, 0, 0.5, -1, 4)],
ids=["rectilinear", "rotated"],
)
def test_open_rasterio__no_affine_mul_warning(transform):
# https://github.com/corteva/rioxarray/issues/937
with rasterio.MemoryFile() as memfile:
with memfile.open(
driver="GTiff",
height=4,
width=4,
count=1,
dtype="uint8",
crs="EPSG:4326",
transform=transform,
) as dataset:
dataset.write(numpy.zeros((1, 4, 4), dtype="uint8"))
with warnings.catch_warnings():
warnings.filterwarnings(
"error",
message="Use `@` matmul",
category=PendingDeprecationWarning,
)
with memfile.open() as dataset:
rds = rioxarray.open_rasterio(dataset)
rds.rio.transform(recalc=True)