1

I first used the Maximum Value Composite to generate a annual NDVI for a watershed, and then calculated the mena NDVI for the entire basin. I don't know if this code is correct. In addition, I want to get the annual mean NDVI of the basin in 2013-2018 (after Maximum Value Composite), I don't know how to modify my code.

var roi = ee.FeatureCollection("users/qq2385973028/shape/Chabagou_catchment");
var dataset = ee.ImageCollection('MODIS/006/MOD13Q1')

function generateImage() {
  Map.centerObject(roi, 10);
  var img = dataset.filterDate("2017-1-1", "2017-12-31")
              .filterBounds(roi)
              .select("NDVI")
              .mosaic()
              .clip(roi);
  var visParam = {
   min: 0.0,
  max: 8000.0,
    palette: 'FFFFFF, CE7E45, DF923D, F1B555, FCD163, 99B718, 74A901, 66A000, 529400,' +
      '3E8601, 207401, 056201, 004C00, 023B01, 012E01, 011D01, 011301'
  };
  Map.addLayer(img, visParam, "NDVI");
  return img;
}
var img = generateImage();

 //image collection
  var l8Col = dataset.filterDate("2015-1-1", "2015-12-31")
              .filterBounds(roi)
              .select("NDVI")
  var image = l8Col.reduce(ee.Reducer.max());
  print(image);

  var visParam = {
     min: 0.0,
  max: 8000.0,
    palette: 'FFFFFF, CE7E45, DF923D, F1B555, FCD163, 99B718, 74A901, 66A000, 529400,' +
      '3E8601, 207401, 056201, 004C00, 023B01, 012E01, 011D01, 011301'
  };
  Map.addLayer(image.clip(roi), visParam, "NDVI_min1");

 var image2 =l8Col.max()
 Map.addLayer(image2.clip(roi), visParam, "NDVI_min2");
  //image
  var dict = image.reduceRegion({
    reducer: ee.Reducer.mean(),
    geometry: roi,
    scale: 250,
    maxPixels: 1e13
  });
  print("dict", dict);


  • I've added the "google earth engine" tag because this looks like Google Earth Engine code. – Spacedman Sep 11 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.