Repository navigation
fix(geotiff): decode NaN pixels in LERC tiles as NaN - #790
Merged
Merged
Conversation
LERC stores NaN as an invalid pixel in its mask rather than as a value. `lerc.ts` returned the decoded pixels and dropped the mask, and the `lerc` package leaves invalid pixels at 0, so NaN pixels read as 0. libtiff fills invalid float pixels with NaN, so GDAL reads NaN there. For F32 and F64 data, set the pixels the mask marks invalid to NaN. Use each band's own mask when the blob has one per band (GDAL writes that when a pixel-interleaved pixel is NaN in only some samples), and set every depth value of an invalid pixel. This runs before `decode()` swaps samples from big endian files, as in libtiff, so big endian files read the same as in GDAL too. Integer data is unchanged, as in libtiff, which leaves invalid integer pixels at 0. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kylebarron
enabled auto-merge (squash)
November 3, 2026 00:00
kylebarron
disabled auto-merge
November 3, 2026 00:01
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.
Note
This PR was written by Claude (Claude Code), not by @kylebarron.
LERC stores NaN as an invalid pixel in its mask rather than as a value.
lerc.tsreturned the decoded pixels and dropped the mask, and thelercpackage leaves invalid pixels at 0, so NaN pixels in float LERC tiles read as 0. libtiff fills invalid float pixels with NaN (tif_lerc.c), so GDAL reads NaN there.lerc.tsnow sets those pixels to NaN.Changes
F32andF64LERC data,lerc.tssets every pixel the LERC mask marks invalid to NaN, as libtiff does.bandMasks), each band uses its own mask. GDAL writes that when a pixel-interleaved pixel is NaN in only some samples. The combinedmaskwould mark the pixel invalid in every band.depthCount > 1), every value of an invalid pixel becomes NaN.decode()swaps samples from big endian files, as in libtiff, so big endian files match GDAL too. That includes the values GDAL loses in such files (GDAL loses some float values in big endian LERC files #707), which now read as the same byte-swapped NaN.Tests
decode.test.tsdecode tiny real LERC blobs embedded as base64: 4x4 strips written by GDAL 3.12.1 withCOMPRESS=LERCandMAX_Z_ERROR=0. They cover float32 and float64, one mask shared by two samples, one mask per band, an all-NaN tile, and the big endian ordering. All six fail onmain.GeoTIFF.fromArrayBuffer().fetchTile():maindiffers from GDAL in 35 pixels, this branch in none, for little endian, big endian and 3-band files.Notes
toPixelInterleavedthrowsBand count mismatchon them. Their NaN values are now correct; splitting them into bands is a separate fix.Closes #706
🤖 Written by Claude Code