0

I want to mask all the layers in an ImageCollection (in the present case MOD44B) using the landcover (Globcover) values from another Image.

var MOD44B = ee.ImageCollection("MODIS/006/MOD44B"),
    Globcover = ee.Image("ESA/GLOBCOVER_L4_200901_200912_V2_3"),
    visualization = {"bands":["Percent_Tree_Cover"],"min":0,"max":100,"palette":["bbe029","0a9501","074b03"]};

var MOD44B = MOD44B.filterDate('2000-01-01', '2019-12-31')
var MOD44B = MOD44B.select('Percent_Tree_Cover')

var Globcover = Globcover.select('landcover')
var Globcover = Globcover.lte(30).or(Globcover.gte(190)).rename('Class');
print(Globcover)
Map.addLayer(Globcover)

//MOD44B = MOD44B.map(Globcover.eq(1)); //<------ This line is not working.
Map.addLayer(MOD44B, visualization, 'TC')

I want to mask all the white regions from Globcover (Image) in MOD44B (Imagecollection). enter image description here

2

ImageCollection.map takes a function to apply to each image in the collection. Give it a function which applies the mask:

MOD44B = MOD44B.map(function (image) {
  return image.updateMask(Globcover);
});

I also removed .eq(1) because it was unnecessary — the image you called Globcover is already binary since it came from .or().

1
  • The code worked perfectly. Thanks, @Kevin. – Ep1c1aN Mar 16 at 22:20

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.