Describe the bug
_coords_to_transform (xrspatial/geotiff/init.py:296-303) reads x[1] - x[0] and y[1] - y[0] as the pixel sizes for the affine transform. There is no check that the rest of the spacing matches.
GeoTIFF (in this writer) only supports an affine transform, so non-uniform coords cannot be expressed faithfully. Today the writer silently picks the spacing between the first two samples and lets the resulting file claim that spacing for every pixel, which produces a wrong georeference downstream.
Expected behavior
_coords_to_transform validates that np.diff(x) and np.diff(y) are constant within a small relative tolerance (e.g. 1e-6 of the median step). If not, raise a ValueError with a clear message rather than emitting a silently-wrong transform.
Proposed fix
Add the regularity check to _coords_to_transform. Failing the check raises ValueError. Add a test that covers a DataArray with non-uniform x and y coords and asserts the writer raises.
Describe the bug
_coords_to_transform(xrspatial/geotiff/init.py:296-303) readsx[1] - x[0]andy[1] - y[0]as the pixel sizes for the affine transform. There is no check that the rest of the spacing matches.GeoTIFF (in this writer) only supports an affine transform, so non-uniform coords cannot be expressed faithfully. Today the writer silently picks the spacing between the first two samples and lets the resulting file claim that spacing for every pixel, which produces a wrong georeference downstream.
Expected behavior
_coords_to_transformvalidates thatnp.diff(x)andnp.diff(y)are constant within a small relative tolerance (e.g.1e-6of the median step). If not, raise aValueErrorwith a clear message rather than emitting a silently-wrong transform.Proposed fix
Add the regularity check to
_coords_to_transform. Failing the check raisesValueError. Add a test that covers a DataArray with non-uniform x and y coords and asserts the writer raises.