diff --git a/docs/getting_started/crs_management.ipynb b/docs/getting_started/crs_management.ipynb index 51daa965..9b3a68c8 100644 --- a/docs/getting_started/crs_management.ipynb +++ b/docs/getting_started/crs_management.ipynb @@ -1082,9 +1082,9 @@ "source": [ "## Setting the transform of the dataset\n", "\n", - "The transform can be calculated from the coordinates of your data.\n", - "This method is useful if your netCDF file does not have coordinates present.\n", - "Use the `rio.write_transform` method to set the transform on your `xarray.Dataset` or `xarray.DataArray`.\n", + "Use `rio.write_transform()` to store an affine transform on an `xarray.Dataset` or `xarray.DataArray`. This is useful for rasters without explicit spatial coordinates.\n", + "\n", + "For an axis-aligned raster with one-dimensional `x` and `y` coordinates, `rio.transform()` derives the origin from the pixel centers. To change the georeferencing, update the coordinates to match the intended transform as well as writing the transform metadata.\n", "\n", "- [rio.write_transform()](../rioxarray.rst#rioxarray.rioxarray.XRasterBase.write_transform)\n", "- [rio.transform()](../rioxarray.rst#rioxarray.rioxarray.XRasterBase.transform)" diff --git a/docs/history.rst b/docs/history.rst index 53a07622..8de76689 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -3,6 +3,7 @@ History Latest ------ +- DOC: Clarify how ``rio.write_transform()`` metadata and spatial coordinates affect ``rio.transform()`` (#698) 0.25.1 ------ diff --git a/rioxarray/rioxarray.py b/rioxarray/rioxarray.py index b0f9084b..4c74dfb1 100644 --- a/rioxarray/rioxarray.py +++ b/rioxarray/rioxarray.py @@ -387,6 +387,11 @@ def write_transform( For CF convention, this writes the GeoTransform to the dataset where GDAL can read it in. https://gdal.org/drivers/raster/netcdf.html#georeference + To change the georeferencing of an axis-aligned grid with explicit x and y + coordinates, update the pixel centers to match the intended transform as + well. See :meth:`transform` for how the accessor derives the origin and + resolution. + Parameters ---------- transform: affine.Affine, optional @@ -426,11 +431,18 @@ def write_transform( def transform(self, recalc: bool = False) -> Affine: """ + Return the affine transform of the raster. + + For an axis-aligned grid with one-dimensional spatial coordinates, the origin is + derived from the x and y pixel centers. By default the stored transform, + when available, supplies the resolution. Grids without spatial coordinates + use the stored transform when available. + Parameters ---------- recalc: bool, optional - If True, it will re-calculate the transform instead of using - the cached transform. + If True, calculate the resolution from the spatial coordinates when + possible. Rotated or non-rectilinear grids use their stored transform. Returns -------