I'm trying to create a map on Google Earth Engine with only some Land-Cover class, but I can't find a solution to this problem.

I'm using this MODIS dataset: MODIS/061/MCD12Q1/2002_01_01 I'm using this type of Land-Cover: LC_Type1

From LC_Type1, I just want to use the classes from 1 to 5 (the ones described as Evergreen Needleleaf Forests, Evergreen Broadleaf Forests, Needleleaf Forests, Broadleaf Forest, and Mixed Forests)

How do I filter only these 5 classes?

The final aim is to use these classes to extract NPP values from another MODIS dataset for computing a time-series chart of yearly NPP. This last part is not a problem because is something I just manage to resolve. My only problem is with the "filtering" of these land-cover classes.

I tried to filter these classes but it is always giving me errors.

I'm stuck here:

// MODIS Land-Cover dataset
var landcover = ee.Image("MODIS/061/MCD12Q1/2002_01_01")

// visualization palette
var LCVis = {
  min: 1.0,
  max: 17.0,
  palette: [
    '05450a', '086a10', '54a708', '78d203', '009900', 'c6b044', 'dcd159',
    'dade48', 'fbff13', 'b6ff05', '27ff87', 'c24f44', 'a5a5a5', 'ff6d4c',
    '69fff8', 'f9ffa4', '1c0dff'

Map.centerObject(roi, 8)
Map.addLayer(landcover, LCVis, 'MODIS land-cover')

I tried

// MODIS Land-Cover dataset
var landcover = ee.Image("MODIS/061/MCD12Q1/2002_01_01")
                  .select('LC_Type1', [1,5])

but it's not working.

Is there a solution?

  • What are the errors?
    – PolyGeo
    Jan 20, 2023 at 9:10

1 Answer 1


You can mask the other pixels

// create mask with pixels values less than or equal to 5
var mymask = landcover.lte(5);

// Apply mask
var forest = landcover.updateMask(mymask);

// Visualize
Map.addLayer(forest, LCVis, 'MODIS forest')
  • 1
    Perfect! Exactly what I was looking for! Thank you so much!
    – frog11235
    Jan 20, 2023 at 9:20

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.