<div dir="ltr"><div>Not sure if this is a bug, or expected behavior, or user error. If I warp one TIF into another, and both have nodata masks, it seems that gdalwarp isn't updating the destination TIF's nodata mask to unmask the new pixels.</div><div><br></div><div>Here's a short script to generate two example TIFs. One has a red box in its upper left corner, the other has a green box in its upper right corner. Both have nodata masks so that only the colored boxes are visible.</div><div><br></div><div><span style="font-family:monospace">---</span></div><div><span style="font-family:monospace">import numpy as np<br>from osgeo import gdal<br><br>gdal.UseExceptions()<br>gdal.SetConfigOption("GDAL_TIFF_INTERNAL_MASK", "YES")<br>drv = gdal.GetDriverByName("GTiff")<br><br>zeros = np.zeros((3, 1024, 1024))<br><br>red = np.copy(zeros)<br>red[0, 100:200, 100:200] = 255<br><br>green = np.copy(zeros)<br>green[1, 100:200, 800:900] = 255<br><br>ds = drv.Create("red.tif", 1024, 1024, 3, gdal.GDT_Byte)<br>ds.SetGeoTransform((0, 1, 0, 0, 0, -1))<br>ds.WriteArray(red)<br>ds.CreateMaskBand(gdal.GMF_PER_DATASET)<br>ds.GetRasterBand(1).GetMaskBand().WriteArray(red[0, :, :])<br>ds = None<br><br>ds = drv.Create("green.tif", 1024, 1024, 3, gdal.GDT_Byte)<br>ds.SetGeoTransform((0, 1, 0, 0, 0, -1))<br>ds.WriteArray(green)<br>ds.CreateMaskBand(gdal.GMF_PER_DATASET)<br>ds.GetRasterBand(1).GetMaskBand().WriteArray(green[1, :, :])<br>ds = None</span></div><div><span style="font-family:monospace">---</span></div><div><span style="font-family:monospace"><br></span></div><div>Then if you copy red.tif to warp.tif, then warp green.tif into warp.tif:</div><div><span style="font-family:monospace">cp red.tif warp.tif</span></div><div><span style="font-family:monospace">gdalwarp green.tif warp.tif</span></div><div><br></div><div>I would expect the result to be a combined image with both the red and green boxes. But when I load this result into QGIS, I only see the red box. If I change the layer in QGIS to ignore the mask band, I do see both boxes (and the remaining image is black, as expected). So the pixel data is there, but the mask didn't get updated.</div><div><br></div><div>Is there a way to get gdalwarp to update the nodata mask automatically? Maybe some hidden setting I'm missing? I can work around this by separately warping the masks, then copying the result into the final TIF's mask band. But it would be nice if the warp took care of this for me.</div><div><br></div><div>Thanks</div></div>