Skip to content

Update y/x coords for mirror-flip TIFF orientations (#1537)#1539

Open
brendancol wants to merge 2 commits intomainfrom
issue-1537
Open

Update y/x coords for mirror-flip TIFF orientations (#1537)#1539
brendancol wants to merge 2 commits intomainfrom
issue-1537

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • Update y/x coords for mirror-flip orientations 2/3/4 in read_to_array so xarray label lookups land on the right pixel for georeferenced files.
  • Cover both PixelIsArea (origin shifts by N * step) and PixelIsPoint (shifts by (N-1) * step).
  • Leave ungeoreferenced files on the integer pixel coords they already use.

Context

PR #1521 added the buffer remap for the Orientation tag (274). The 5-8 axis-swap branch already updates the transform (and warns). The 2/3/4 mirror branch was never wired up, so _reader.py flipped the array but kept the un-flipped origin and pixel-scale signs. da.sel(x=..., y=...) against the result returned whatever pixel originally lived at those coords -- not the pixel actually displayed there. See #1537 for a full reproducer.

Test plan

  • pytest xrspatial/geotiff/tests/test_orientation.py -q (was 36, now 46 -- new tests cover sel-fidelity for orient 2/3/4 under PixelIsArea and PixelIsPoint, the coord-array first-element values, and the no-georef passthrough).
  • pytest xrspatial/geotiff/tests/ -q --no-header --deselect xrspatial/geotiff/tests/test_features.py::TestPalette (942 passed; the deselected test failures are unrelated -- a Python 3.14 / matplotlib deepcopy regression).
  • GPU tests: pytest xrspatial/geotiff/tests/test_planar_multiband.py xrspatial/geotiff/tests/test_lerc_valid_mask_gpu.py xrspatial/geotiff/tests/test_predictor2_big_endian_gpu_1517.py xrspatial/geotiff/tests/test_gpu_byteswap_1508.py xrspatial/geotiff/tests/test_gpu_strict_fallback_1516.py xrspatial/geotiff/tests/test_gpu_stripped_multiband.py -q (91 passed; CPU-only change, GPU path unaffected).

Closes #1537.

Orientations 2/3/4 in the TIFF Orientation tag (274) flip the array
horizontally, both axes, or vertically. PR #1521 applied the buffer
remap but left the y/x coord arrays computed from the un-flipped
transform, so xarray label lookups against a georeferenced file
returned the wrong pixel under any of those orientations.

The fix updates the geo_info transform after the array remap so a
displayed pixel and its geographic label point to the same location
on the ground. PixelIsArea and PixelIsPoint both work; the
unrotated transform is still preserved for ungeoreferenced files
(coords stay on integer pixel indices).
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GeoTIFF reader: orientations 2/3/4 leave y/x coords un-flipped on georeferenced files

1 participant