geotiff: preserve transform on 1xN / Nx1 georeferenced writes (#1945)#1953
Merged
Conversation
Contributor
Author
PR Review: geotiff: preserve transform on 1xN / Nx1 georeferenced writes (#1945)Blockers (must fix before merge)
Suggestions (should fix, not blocking)
Nits (optional improvements)
What looks good
Checklist
|
brendancol
added a commit
that referenced
this pull request
May 15, 2026
brendancol
added a commit
that referenced
this pull request
May 15, 2026
Contributor
Author
PR Review: geotiff: preserve transform on 1xN / Nx1 georeferenced writes (#1945) (re-review after rebase)Re-reviewed at head Blockers
Suggestions
Nits
What looks good
Checklist
|
coords_to_transform returned None whenever either spatial coord had length < 2, and the writers fell through and produced a non-georeferenced TIFF. A single-row or single-column DataArray with real x/y coords round-tripped back with integer pixel coords and no transform attribute, silently dropping spatial metadata. Recover the per-axis pixel size from the non-degenerate axis when only one axis is degenerate (1xN / Nx1) and assume square pixels for the degenerate one. For the 1x1 case where no axis carries a step, prefer attrs['transform']; if no explicit transform is supplied, fail closed with a clear ValueError rather than writing a non-georeferenced file. Wire the same fail-closed guard into the eager, dask, GPU, and VRT-tiled writer paths via a new require_transform_for_georeferenced helper. Add round-trip tests covering 1xN, Nx1, and 1x1 across numpy, dask+numpy, GPU (cupy), dask+cupy, and the VRT-tiled writer.
Contributor
Author
|
Rebased onto current main at |
This was referenced May 15, 2026
brendancol
added a commit
that referenced
this pull request
May 15, 2026
…el parity with coords_to_transform) (#1969) PR #1953 added require_transform_for_georeferenced which raises when both spatial dims are in da.coords and the resolved transform is None. PR #1954 made coords_to_transform return None for integer x/y coords as the no-georef sentinel (#1949). Their interaction broke writer calls against int-coord arrays. Mirror the int/uint exemption from coords_to_transform inside the guard so the writer accepts int coords silently. Also fixes the error wording, which previously claimed "both axes are degenerate (1x1)" even when the array was not 1x1. Adds a regression test covering 2D and 3D int-coord round-trips.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1945.
coords_to_transformnow recovers the per-axis pixel size from the non-degenerate axis on 1xN / Nx1 inputs and assumes square pixels for the degenerate one, instead of bailing out and letting the writer produce a non-georeferenced TIFF.attrs['transform']is honoured; if none is supplied, the writer fails closed with aValueErrorrather than silently dropping spatial metadata.require_transform_for_georeferencedhelper enforces the fail-closed rule from each writer entry point:to_geotiffeager,to_geotiffdask,to_geotiffwith a.vrtpath (VRT-tiled), andwrite_geotiff_gpu.Why this is a behaviour change
Before:
After: the coords round-trip back as floats, and
attrs['transform']is populated.A 1x1 DataArray without an explicit
attrs['transform']now raisesValueErrorinstead of silently producing a non-georeferenced file.Test plan
xrspatial/geotiff/tests/test_degenerate_georef_1945.py: 1xN, Nx1, and 1x1 round-trips across numpy, dask+numpy, GPU (cupy), dask+cupy, and the VRT-tiled writer (15 tests).main(unrelatedread_to_arraymonkeypatch and signature-parity tests).