5

I would like to merge 5 years of world ocean surface productivity data raster into 1 averaged raster in QGIS. However, not every pixel has data in every year. To generate the raster layer with the averaged data, should I use Raster Calculator? And produce the average raster using:

(raster1+raster2+raster3+raster4+raster5)/5

But how can I omit those pixels with no data for the calculation of the average?

Is there a way to detect the nodata pixel such that it will just divided by the number of layers that have data in that pixel? For example if raster3 doesn't have the data, it will automatically become

(raster1+raster2+raster4+raster5)/4

for the calculation in that grid?

1
  • I just noticed your edit. I don't think that's possible to do using only the Raster Calculator. You will likely have to make a python script or model to achieve what you're looking for :)
    – Joseph
    Commented Jun 22, 2016 at 8:31

1 Answer 1

1

Not tested but try something like:

(
("raster1" != 0/0) * "raster1" + 
("raster2" != 0/0) * "raster2" + 
("raster3" != 0/0) * "raster3" + 
("raster4" != 0/0) * "raster4" + 
("raster5" != 0/0) * "raster5"
) / 5

where if a pixel does not equal a nodata value (0/0) then it will return the original value (otherwise return a zero) and continue on with summing and averaging the rasters.

2
  • May I ask if "0/0" is the nodata value defined by user?
    – wwwwwwww
    Commented Jun 20, 2016 at 15:25
  • 1
    @wwwwwwww - I think the 0/0 just returns whatever nodata value is at the pixel. You could replace this with e.g. -32768 if you know that is your nodata value.
    – Joseph
    Commented Jun 20, 2016 at 15:29

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.