Skip to content

Fix three accuracy bugs in open_geotiff/to_geotiff#1082

Merged
brendancol merged 1 commit intomasterfrom
issue-1081
Mar 29, 2026
Merged

Fix three accuracy bugs in open_geotiff/to_geotiff#1082
brendancol merged 1 commit intomasterfrom
issue-1081

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

@brendancol brendancol commented Mar 29, 2026

Closes #1081.

Summary

  • Windowed reads of PixelIsPoint files were getting a half-pixel coordinate shift (~15m for 1-arc-second DEMs). The non-windowed path already checked raster_type correctly, but the windowed override at line 216 always added the 0.5 offset. Fixed by adding the same check.
  • Custom CRS without EPSG codes (local grids, compound CRS) were silently dropped on write because write() only accepted crs_epsg: int. Added crs_wkt pass-through to build_geo_tags, which stores the WKT in GeoAsciiParamsTag and sets the CRS GeoKey to 32767 (user-defined).
  • open_geotiff converts nodata sentinels to NaN, but to_geotiff wasn't converting them back. The written file would have NaN pixels but a GDAL_NODATA tag still pointing at the original sentinel (e.g. -9999). Fixed by restoring sentinel values from NaN before writing.

Test plan

  • 10 new tests in test_accuracy_1081.py covering all three bugs
  • 344 existing geotiff tests still pass (0 failures)
  • Verify windowed read coords match full-read slice for both PixelIsArea and PixelIsPoint
  • Verify GeoAsciiParamsTag written for non-EPSG WKT CRS
  • Verify raw pixel data has sentinel values (not NaN) after round-trip

1. Windowed reads now respect PixelIsPoint raster type instead of
   unconditionally applying the half-pixel coordinate offset.

2. Custom CRS without EPSG codes are written to GeoAsciiParamsTag
   so they survive round-trips (previously silently dropped).

3. NaN pixels are converted back to the nodata sentinel value
   before writing, so the GDAL_NODATA tag matches the actual data.
@brendancol brendancol added bug Something isn't working high-priority labels Mar 29, 2026
@github-actions github-actions bot added the performance PR touches performance-sensitive code label Mar 29, 2026
@brendancol brendancol merged commit 7d25252 into master Mar 29, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working high-priority performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix three accuracy bugs in open_geotiff/to_geotiff round-trips

1 participant