[gdal-dev] Advice on `GDALCreateAndReprojectImage` and destination no-data value.
Fitch, Simeon
fitch at astraea.io
Fri Nov 3 13:36:51 PDT 2023
Hi,
I'm one of the maintainers at the `georust/gdal` bindings project. 👋
I'm currently working on exposing some of the GDAL Warp functionality in
Rust, starting with a simple wrapper around `GDALCreateAndReprojectImage`.
I'm having trouble getting the output file to include a no-data value in
the band's metadata, despite the Warp operation properly respecting no-data
values specified in `GDALWarpOptions`.
My C++ skills are very "rusty", so I'm hoping I can get away with
explaining my problem with some Rust code that is pretty close to being 1:1
with the C API. My suspicion is I'm missing a step in the `GDALWarpOptions`
setup.
This is the CLI operation I'm trying to replicate:
gdalwarp -t_srs EPSG:4269 -dstnodata 255 -r near input.tif output.tif
Here's the bare-bones Rust bindgen version:
<https://gist.github.com/metasim/d2a288d5b6126438aaa84b9e95707aff>
The single band in `input.tif` is described by `gdalinfo` like this:
Band 1 Block=186x44 Type=Byte, ColorInterp=Gray
NoData Value=255
Metadata:
CLASSES=3
After running the Rust code, the results are correct (including Warp
numerically respecting source and destination no-data values) _except_
`output.tif` does not have a no-data value in the band metadata. Here's
what `gdalinfo` on `output.tif` shows:
Band 1 Block=210x39 Type=Byte, ColorInterp=Gray
The only way I've been able to get the behavior I need is to open the
written dataset from the filesystem and set the no-data value explicitly in
the band, which is inefficient and awkward. Given the CLI version does the
right thing, it's obviously possible. I've spent several hours visually
inspecting the C++ source code, but the CLI version doesn't call
`GDALCreateAndReprojectImage` directly; rather it constructs the Warp
pipeline itself.
Anyone have tips that might help me run this down? Am I missing a no-data
handling step required when working with Warp routines? Could
`GDALCreateAndReprojectImage` have a bug?
Thanks,
Simeon
--
Simeon Fitch
Co-founder & CTO
Astraea, Inc.
--
The content of this email is intended for the person or entity to which it
is addressed only. This email may contain confidential information. If you
are not the person to whom this message is addressed, be aware that any
use, reproduction, or distribution of this message is strictly prohibited.
If you received this in error, please contact the sender and immediately
delete this email and any attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20231103/a04b51dd/attachment.htm>
More information about the gdal-dev
mailing list