Keep the pixel registration of grids written through GDAL (#8633) - #9147
Merged
Conversation
Fixes #8633 (grdsample) and #8988 (grdmath): a pixel registered grid saved with =gd came back gridline registered, its region pulled in by half a cell, so in practice only gridline registered grids could be written that way. The raster itself was written correctly; what was missing was the tag that says whether the values are cell centres or whole cells: * gmt_gdalwrite set AREA_OR_POINT for GTiff output only, and then only when the grid was geographic or carried a WKT, and only when the user had passed no +c<options> - the call sat inside the "add default compression" block. Plain Cartesian grids, which is what both reports used, got no tag at all. * Even unconditionally, AREA_OR_POINT is not enough: GDAL never records it when it is "Area", that being the implicit default, and the GeoTIFF driver writes no keys whatsoever for a raster with no referencing. So the registration of a Cartesian grid cannot be recovered from AREA_OR_POINT alone. AREA_OR_POINT is now set for every driver except the picture-only ones (PNG, JPEG, GIF, BMP, WEBP), which have nowhere to keep it and would only gain a .aux.xml sidecar for it, and a GMT_REGISTRATION item is stored beside it stating the registration outright. GeoTIFF and netCDF keep both in the file; the drivers that need PAM for this already write a .aux.xml for their band statistics, so no new sidecar appears anywhere. gmt_gdalread consults GMT_REGISTRATION and, when present, prefers it to its own data-type guess; files without it - everything written before this change, and everything from other software - are read exactly as before. Every GMT grid format now preserves pixel registration on output except the three whose headers hold node coordinates only: Surfer 6, Surfer 7 and AGC, plus GDAL's GSBG driver. AGC already said so; Surfer now warns as well instead of silently shifting the region. Also add the missing break at the end of grdsample's -Q case, which fell through into -T and set T.active for anyone using the deprecated option. test/gdal/gdal_registration.sh covers the round trip both ways, through the GeoTIFF and AAIGrid drivers, referenced and not, with and without +c<options>. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Esteban82
approved these changes
Aug 26, 2026
Esteban82
left a comment
Member
There was a problem hiding this comment.
I ran the test and it worked fine. No messages appeared on the terminal.
Member
|
The CI reports a few new failures due to this PR. |
Contributor
|
Excellent work. Hopefully the next time I need to make grids, I won't be so confused by this grid vs pixel registration thing. |
Member
Author
|
The 3 failures are The transp_mix must be one that Claude committed without authorization from my disk and fails because the basemap PS is missing. The other two are strange. They also failed for me locally but pass when I run them individually. |
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.
Let grdsample and grdmath save pixel registered grids.
Fixes #8633 (grdsample) and #8988 (grdmath): a pixel registered grid saved with =gd came back gridline registered, its region pulled in by half a cell, so in practice only gridline registered grids could be written that way.
A new test
gdal_registration.shtests this issue.Assisted by: GPT Terra and revised/corrected by Claude Opus 5.0