var l8 =ee.ImageCollection('LANDSAT/LC08/C01/T2_TOA')

var landsat2016 = l8.filterDate('2016-01-01', '2016-12-31');

var median = l8.filterDate('2016-01-01', '2016-12-31').median();

// Load or import the Hansen et al. forest change dataset.
var hansenImage = ee.Image('UMD/hansen/global_forest_change_2015');

// Select the land/water mask.
var datamask = hansenImage.select('datamask');

// Create a binary mask.
var mask = datamask.eq(1);

// Update the composite mask with the water mask.

var maskedComposite = median.mask(mask);

var maskedComposite2 = median.updateMask(mask);

So what the difference between maskedComposite and maskedComposite2?

1 Answer 1


In the way you apply the mask and updateMask, there is no difference. I would rather use updateMask, as this is written about the mask function:

Note: the version that sets a mask will be deprecated. To set a mask from an image on previously unmasked pixels, use Image.updateMask. To unmask previously masked pixels, use Image.unmask.

  • So to answer @Graylemon question, are there cases where those functions are different? The documentation you cite is hard to follow... does it mean we should use updateMask when there's paradoxically no mask to update? And when should we use mask then? Thanks!!
    – Matifou
    Feb 16, 2022 at 9:54
  • There is no difference, except for that the function 'mask' will (somewhere in the future) be deprecated.
    – Kuik
    May 27, 2022 at 13:35

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.