[GIS] Impossible to sum rasters because of nodata pixels

gdalqgis-2raster

I have a set of rasters (.vrt) with daily soil moisture data. I want to sum the pixels of all rasters in order to have a measure by month. However, the whole world is not covered each day, which results in nodata values at places where measures exist for the other days.

What I want to do, is sum the values of each raster. However, it seems that each time a nodata pixel is in the sum, the resulting pixel is directly categorized as nodata. I would like to have the opposite: ignoring all nodata values and summing the rest.

I thought of 2 ways of solving the problem:

  1. summing rasters ignoring nodata values
  2. converting nodata pixels to value 0, then sum all the rasters

enter image description here

Unfortunately, I can't find any tool to do this.

Can anyone help me?

Best Answer

Firstly, you can use gdal_calc.py to change all -9999 to 0 and set the NoData value to 0.

For instance:

gdal_calc.py -A input.tif --outfile=input_with_NoData.tif --calc="A+9999*(A==-9999)" --NoDataValue=0

Then, you can ignore NoData value using gdal_translate with the -a_nodata option followed by none.

-a_nodata value:

Assign a specified nodata value to output bands. Starting with GDAL 1.8.0, can be set to none to avoid setting a nodata value to the output file if one exists for the source file

Example:

gdal_translate -a_nodata none input_with_NoData.tif output_without_NoData.tif