Set INIT_DEST to 0 instead of NO_DATA if it's unset (#3389)

This matches behaviour in GDAL < 3.11 and _intended_ behaviour in 3.11
(which was supposed to warn about this, but still actually fails.)
This commit is contained in:
Elliott Sales de Andrade 2025-09-08 17:39:19 -04:00 committed by GitHub
parent d53df64f3e
commit 347a97e625
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View File

@ -582,7 +582,8 @@ def _reproject(
log.debug("Setting NUM_THREADS option: %d", num_threads)
if init_dest_nodata:
warp_extras = CSLSetNameValue(warp_extras, "INIT_DEST", "NO_DATA")
warp_extras = CSLSetNameValue(warp_extras, "INIT_DEST",
"NO_DATA" if dst_nodata is not None else "0")
# See https://gdal.org/doxygen/structGDALWarpOptions.html#a0ed77f9917bb96c7a9aabd73d4d06e08
# for a list of supported options. Copying unsupported options
@ -1019,7 +1020,7 @@ cdef class WarpedVRTReaderBase(DatasetReaderBase):
self.dst_transform = transform
self.warp_extras = warp_extras.copy()
if init_dest_nodata is True and 'init_dest' not in warp_extras:
self.warp_extras['init_dest'] = 'NO_DATA'
self.warp_extras['init_dest'] = 'NO_DATA' if self.dst_nodata is not None else '0'
cdef GDALDriverH driver = NULL
cdef GDALDatasetH hds = NULL

View File

@ -57,7 +57,7 @@ def test_warped_vrt_nondefault_nodata(path_rgb_byte_tif):
assert vrt.dst_nodata is None
assert vrt.tolerance == 0.125
assert vrt.resampling == Resampling.nearest
assert vrt.warp_extras == {"init_dest": "NO_DATA"}
assert vrt.warp_extras == {"init_dest": "0"}
assert vrt.mask_flag_enums == ([MaskFlags.all_valid],) * 3