1

I want to get the NDVI of MODIS from Google Earth Engine in a country (Ireland), here is my code. It works, but it doesn't show on the map.

var dataset = ee.FeatureCollection('USDOS/LSIB/2013')
            .filterBounds(ee.Geometry.Point(-7.681, 53.43));

 var image = ee.Image().float().paint(dataset, 'iso_num'); ///import the vector data of the country globally

 var visParams = {
 palette: ['f5ff64', 'b5ffb4', 'beeaff', 'ffc0e8', '8e8dff', 'adadad'],
 min: 0.0,
 max: 894.0,
 opacity: 0.8,
 };

 Map.addLayer(image, visParams, 'USDOS/LSIB/2013'); ///show the data on the map


 var image1 = ee.ImageCollection('MODIS/MOD13A1')

          .filter(ee.Filter.date('2018-01-01', '2019-12-31'))

          .filterBounds(dataset);     ////import the MODIS ndvi data, filter the bounds with the dataset above

  var ndvi = image1.select('NDVI');


  var ndviVis = {
  palette: [
  'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
  '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
  '012E01', '011D01', '011301'
   ],
   };
  Map.addLayer(ndvi, ndviVis, 'NDVI');    

it runs, but only shows the boundary of Ireland. How to get the MODIS NDVI separately?

1 Answer 1

1

The problem is that MODIS/MOD13A1 doesn't contain any imagery in your date range. A minor issue is that image1 actually isn't an ee.Image, but an ee.ImageCollection. You can turn it into an image by calling mosaic(), median() etc. on it.

var image1 = ee.ImageCollection('MODIS/MOD13A1')
  // .filter(ee.Filter.date('2018-01-01', '2019-12-31'))
  .filter(ee.Filter.date('2016-01-01', '2017-01-01'))
  .filterBounds(dataset) ////import the MODIS ndvi data, filter the bounds with the dataset above
  .mosaic()

https://code.earthengine.google.com/a723f750f20883cb4e94b4c70cd303f2

5
  • Hi, I edited it according to what you said, what it does not work and said 'NDVI: Layer error: Image.select: Pattern 'NDVI' did not match any bands' Commented Feb 5, 2020 at 13:35
  • You are still filtering between 2018-01-01 and 2019-12-31. There are no images in that date range. That causes mean() to return an image without bands. Commented Feb 5, 2020 at 13:55
  • Hi, Thank you and it works. However, I just want the NDVI of Ireland, do you know how to restrict the image to this region(Ireland). Thanks a lot Commented Feb 5, 2020 at 13:58
  • Ask another question for that. Commented Feb 5, 2020 at 13:59

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.