I have chunks of rasters that I need to remove the no-data values so I can visualize them together and that they fit and do not overlap. I was using gdal_translate command

for %i in (*.tif) do gdal_translate -a_nodata -999 %i %~ni_NODATA2.tif

gbefore I check the black background in QGIS and the value is -999 and it worked great on some rasters like two pictures below show - before and after.

enter image description here

enter image description here

But in case of where the raster in not rectangular in the start, I am having problems and the command above does not seem to work correctly. It either happens that the black background stays the same and the raster is completely white or that the whole raster becomes black. Below there is also an image attached of this. I would like to get some help how can I work around this and remove only the black no-data like in the other rasters.

enter image description here

enter image description here

2 Answers 2


There are, in fact, two problems: visualization (setting some values to transparent) and filling nodata values:

  1. Sometimes, nodata values are assigned a certain value like -999. You can simply go to Layer Styling > Transparency Tab and click with the tool Add values from display on one of the pixels with containing the value you want to make transparent. Adapt From and To values if needed - see screenshot.

  2. Use Menu Processing > Toolbox > Fill NoData cells (see documentation) and set the value you want to use to fill nodata cells with. Make sure to use the same value used for other nodata cells (if there are any).

    There is also the similar GDAL Fill nodata Tool.

enter image description here


There may be two different nodata values being used in the raster.

The current nodata value used in the header for each band can be found by calling

gdalinfo in.tif

Remaining nodata values can be found by loading the problematic raster into qgis and sampling the values in the white and black areas.

For any nodata values that were not caught by your first step you could do the following:

set curNdVal=actual_nodata_value
set newNdVal=problematic_nodata_value

rem Set the header record for the ND value to the problematic ND value
gdalwarp -a_nodata %newNdVal% in.tif in_step1.tif
rem Convert the problematic ND values in cells to the actual ND values
gdalwarp -dstnodata %curNdVal% in_step1.tif in_step2.tif
rem Reset the header record
gdalwarp -a_nodata %curNdVal% in_step2.tif in_step3.tif

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.