Skip to content

NoData mask bands: Incorrect RasterIO result with mode resampling #12220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dbaston opened this issue Apr 28, 2025 · 1 comment
Open

NoData mask bands: Incorrect RasterIO result with mode resampling #12220

dbaston opened this issue Apr 28, 2025 · 1 comment

Comments

@dbaston
Copy link
Member

dbaston commented Apr 28, 2025

(Pdb) band.GetMaskBand().ReadAsArray()
array([[  0, 255],
       [  0,   0]], dtype=uint8)
(Pdb) band.GetMaskBand().ReadAsArray(buf_xsize=1, buf_ysize=1, resample_alg=gdal.GRIORA_Mode)
array([[255]], dtype=uint8)

Originally posted by @dbaston in #12172 (comment)

Some discussion in the linked PR.

@dbaston
Copy link
Member Author

dbaston commented Apr 28, 2025

I had been thinking of having GDALNoDataMaskBand read the requested window into a memory dataset at full resolution, reclassify the values to 0 or 255, and then read from the in-memory dataset to the appropriate buffer size. This requires reading the entire window into memory at full resolution, which may be undesirable.

Alternatively, I've been thinking for a while about how it would be useful to have a VRT that easily does reclassification. (I guess this is possible as a VRT expression, but I'm thinking of something specific to this purpose.) Supposing such a VRT existed, it seems straightforward to for GDALNoDataMaskBand to construct a VRT that reads from its parent band, reclassifying the NoData value as 0 and everything else as 255. We could then read from this band into the appropriate buffer size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant