0

I am trying to extract one LULC class (e.g. cropland) for the entire globe from the MODIS global lulc. How it can be done? Code I am using to display global lulc is:

    var cover = ee.Image('MODIS/051/MCD12Q1/2012_01_01').select('Land_Cover_Type_1');
    var cover_palette = [
    'aec3d4', // water
    '152106', '225129', '369b47', '30eb5b', '387242', // forest
    '6a2325', 'c3aa69', 'b76031', 'd9903d', '91af40',  // shrub, grass
    '111149', // wetlands
    'cdb33b', // croplands
    'cc0013', // urban
    '33280d', // crop mosaic
    'd7cdcc', // snow and ice
    'f7e084', // barren
    '6f6f6f'  // tundra
     ];

    Map.addLayer(cover, {min: 0, max: 17, palette: cover_palette },  
                'Land Cover classification');
7

There is a lot of ways to do this. If you want to preserve class ID, you need to mask the desired class. For example:

var crop_mask = cover.eq(13); // create a mask for crops
var crop = cover.mask(crop_mask); // mask it
Map.addLayer(crop,{},'Crops');

As Rodrigo E. Principe and Nicholas Clinton suggest:

var crop = cover.updateMask(cover.eq(13)); // mask it
Map.addLayer(crop,{},'Crops');
  • 2
    I think you should use upadteMask, which will replace mask for applying a mask to an Image. Saludos =) – Rodrigo E. Principe Apr 23 '18 at 23:56
  • Good suggestion. updateMask() is equivalent to mask(newMask.and(image.mask()) which is preferable because you're not unmasking any pixels. – Nicholas Clinton Apr 24 '18 at 18:09
  • @RodrigoE.Principe yes, you're right. Edited and thanks for the orientation – aldo_tapia Apr 24 '18 at 19:55
  • Thanks all of you. Is it possible to do this masking for several years. For example, I want to study the dynamics of cropland from 2005-2013 and I am trying to do that using: var filtered = crop.filterDate('2001-01-01', '2012-01-01'); Map.addLayer(filtered); This is giving me an error saying crop.filterDate is not a function. How it can be resolved? – Alexia k Boston Apr 27 '18 at 9:47
  • And while using the filterDate command in the starting just after select('Land_Cover_Type_1'); command; it is not giving me any temporal analysis though it is not giving any error. – Alexia k Boston Apr 27 '18 at 9:59

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.