0

I am working with MODIS imageries in GEE and I am new to its interface. So I have been able to access the land cover product of MODIS (MCD12Q1). I have added imageries from 2003 uptil 2016. How can i extract images of any particular year e.g. 2005 or 2010 in GEE for visualiztion?. There is only one image per year in this product

Here is my code for fetching and displaying the collection:

var dataset = ee.ImageCollection('MODIS/006/MCD12Q1')
              .select('LC_Type1')
              .filterDate('2003-01-01','2016-12-31')
              .map(function(img){
                var d = ee.Date(ee.Number(img.get('system:time_start')));
                var m =ee.Number(d.get('month'));
                var y = ee.Number(d.get('year'));
                return img.set({'month':m,'year':y});
              });
//var igbpLandCover = dataset.select('LC_Type1');
var palette =[
  '1f8dff',//water
  '152106',//evergreen needleaf forests
  '225129',//evergreen broadleaf forests
  '369b47',//deciduous needleleaf forests
  '30eb5b',//deciduoud broadleaf forests
  '387242',//mixed deciduous forests
  '6a2325',//closed shrubland
  'c3aa69',//openshrubland
  'b76031',//woody savanna
  'd9903d',//savanna
  '91af40',//grasslands
  '111149',//permanenet wetlands
  'cdb33b', //croplands
  'cc0013', //urban
  '33280d', //crop/natural veg. mosaic
  'd7cdcc',//permanent snow/ice
  'f7e084', //barren/desert
  ].join(',');
Map.setCenter(100,15,6);
Map.addLayer(dataset,{'min':0,'max':17,'palette':palette},'IGBP classification');
0

The way I'd do this is by filtering the ImageCollection. There are many way you could apply a filter in this case, I show you one way:

var dataset = ee.ImageCollection('MODIS/006/MCD12Q1')
              .select('LC_Type1')
              .filterDate('2003-01-01','2016-12-31')
              .map(function(img){
                var d = ee.Date(ee.Number(img.get('system:time_start')));
                var m =ee.Number(d.get('month'));
                var y = ee.Number(d.get('year'));
                return img.set({'month':m,'year':y});
              });

var year = 2010

var filtered = dataset.filter(ee.Filter.calendarRange(year, year, 'year'))
var image = filtered.first()

var palette =[
  '1f8dff',//water
  '152106',//evergreen needleaf forests
  '225129',//evergreen broadleaf forests
  '369b47',//deciduous needleleaf forests
  '30eb5b',//deciduoud broadleaf forests
  '387242',//mixed deciduous forests
  '6a2325',//closed shrubland
  'c3aa69',//openshrubland
  'b76031',//woody savanna
  'd9903d',//savanna
  '91af40',//grasslands
  '111149',//permanenet wetlands
  'cdb33b', //croplands
  'cc0013', //urban
  '33280d', //crop/natural veg. mosaic
  'd7cdcc',//permanent snow/ice
  'f7e084', //barren/desert
  ].join(',');

Map.setCenter(100,15,6);
Map.addLayer(image, {'min':0,'max':17,'palette':palette}, 'IGBP classification '+year.toString());

link to code editor

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.