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:


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


for the calculation in that grid?

  • 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 Jun 22 '16 at 8:31

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.

  • May I ask if "0/0" is the nodata value defined by user? – wwwwwwww Jun 20 '16 at 15:25
  • @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 Jun 20 '16 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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