5

I have two raster (raster1 and raster2) from the same area. I would like to make the sum between the two (raster3 = raster1 + raster2) in QGIS, so that the Digital Number (DN) of raster 3 is the sum between them. However, raster2 has some pixels like "nodata" or "null" without data. When I add them together, the "nodata" pixels do not add up.

For example: raster1 = 2 and raster2 = nodata. When I add these, the result is nodata (2 + nodata = nodata), but I expected it to be = 2, that is, (2 + nodata = 2).

How could I solve this problem?

6 Answers 6

5

You start QGIS with GRASS and then run r.null from processing toolbox on your nodata raster and convert all NULL values to 0 values. Then you should be able to build your sum in raster calculator.

enter image description here

enter image description here

3
  • hello @MrXsquared, i tried apply you answer, but not the result yet returns pixels with nodata. Commented Dec 19, 2020 at 14:15
  • 1
    @wesleysc352 That shouldnt be the case. I have attached a short GIF to illustrate.
    – MrXsquared
    Commented Dec 19, 2020 at 14:37
  • 1
    hello @MrXsquared,thanks for the immense help. I had filled in the wrong field. Now it worked. Commented Dec 19, 2020 at 15:08
4

I would note that the GRASS module r.mapcalc allows you to add rasters, while ignoring NULL cells, without changing the original. For example:

r.mapcalc "raster3 = if(isnull(raster1), raster2, raster1 + raster2)

1

You can use r.series:

r.series input=raster1,raster2 output=raster3 method=sum
0

The SAGA tool "Rasters Sum" has a simple option for counting 'no data' values as zero.

SAGA > Raster - Calculus > Rasters Sum

enter image description here

0

The SAGA tool "Change a grid's No-Data value" also helps.

In the Processing panel:

SAGA > Raster - Tools > Change a Grid's No-Data Value

enter image description here

0

Use Fill NoData cells to remove NoData values from a raster: you can choose a value the No Data cells are replaced with.

Hot to find the tool:

Menu Processing > Toolbox > Fill NoData cells

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.