Repository navigation
fix(geotiff): read projection origin from all equivalent GeoKeys - #671
Merged
Merged
Conversation
Each projection method read its origin, scale factor and false easting/northing from a single hand-picked GeoKey. Writers disagree on which of the equivalent keys they use: GDAL writes ProjNatOrigin* for Oblique Stereographic, but we read ProjCenter*, so a user-defined New Brunswick Stereographic COG got an origin of (0, 0) and rendered near Null Island (source-cooperative/cog-viewer#40). Resolve each parameter the way libgeotiff's GTIFFetchProjParms does: from the first of its equivalent keys that is present. This also fixes the Stereographic scale factor, which GDAL writes to ProjScaleAtNatOrigin. Albers and LCC 2SP keep checking their false-origin keys first. Bumps geotiff-test-data for the O2308000_7586000_cog.tif fixture. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
the GeoKey parsing to PROJJSON is already vibe coded, so we continue to let claude vibe code it with more and more test files
This should hopefully fix source-cooperative/cog-viewer#40
Validated in the dev app that it's now rendering in the right place:
Note
Written by Claude (Claude Code) on behalf of @kylebarron, not by @kylebarron.
Fixes source-cooperative/cog-viewer#40
Bug
O2308000_7586000_cog.tifuses New Brunswick Stereographic (equivalent to EPSG:2953), stored as a user-defined CRS withProjCoordTransGeoKey = CT_ObliqueStereographic. GDAL wrote the origin intoProjNatOriginLatGeoKey/ProjNatOriginLongGeoKey/ProjScaleAtNatOriginGeoKey, butcrsFromGeoKeysreadProjCenter*/ProjScaleAtCenterfor this method. Those keys were missing, so the origin fell back to (0, 0) with scale 1, and the image rendered near Null Island.Fix
Each projection method read its origin, scale factor and false easting/northing from a single hand-picked key. libgeotiff instead takes each one from the first of several equivalent keys that is present:
ProjNatOriginLat→ProjFalseOriginLat→ProjCenterLatProjNatOriginLong→ProjFalseOriginLong→ProjCenterLongProjScaleAtNatOrigin→ProjScaleAtCenterProjFalseEasting→ProjCenterEasting→ProjFalseOriginEastingProjFalseNorthing→ProjCenterNorthing→ProjFalseOriginNorthing_buildConversionnow does the same for every method. When the key a method used to read is present, it still gets the same value. Albers and LCC 2SP keep checking their false-origin keys first.This also fixes Stereographic: GDAL writes its scale factor to
ProjScaleAtNatOrigin, which we didn't read, so it was always 1.Tests
parseWktand proj4. pyproj gives the same point (EPSG:2953 → EPSG:4617) to within 2e-11°.Not fixed here
CT_ObliqueMercator(3) as variant A, but we emit variant B. We also take the "Angle from Rectified to Skew Grid" fromProjAzimuthAngleGeoKeyrather thanProjRectifiedGridAngleGeoKey.🤖 Written by Claude Code