示例1:合成平均图像(去云Mask)并计算某地NDVI平均值(Reduce)

Guide: Masking

  • 取一段时间内的多张图像ee.ImageCollection

  • 计算每张图像的NDVIimage.normalizedDifference()并作为一个新的band添加至图像image.addBands()
    NDVI = (NIR-R) / (NIR+R)

  • 计算每张Landsat图像的云覆盖的指数ee.Algorithms.Landsat.simpleCloudScore(image).select(['cloud])
    只选取云指数小于10的像素.lt(10)
    ee.Number.lt(right)小于括号里的值时返回1

  • 从多张图像选取每个Band上平均值,构成一幅新的图像
    .reduce(ee.Reducer.mean())

  • 选取一个地区的feature.filter(ee.Filter.aq())
    可以从feature获得这个地区的地理信息feature.geometry()
    因为feature是由Geometry和property dictionary组成放入

  • 计算指定地区的NDVI平均值.reduceRegion()

// This function gets NDVI from a Landsat 8 image.
var addNDVI = function(image) {
  return image.addBands(image.normalizedDifference(['B5', 'B4']));
};

// This function masks cloudy pixels.
var cloudMask = function(image) {
  var clouds = ee.Algorithms.Landsat.simpleCloudScore(image).select(['cloud']);
  return image.updateMask(clouds.lt(10));
};

// Load a Landsat collection, map the NDVI and cloud masking functions over it.
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
  .filterBounds(ee.Geometry.Point([-122.262, 37.8719]))
  .filterDate('2014-03-01', '2014-05-31')
  .map(addNDVI)
  .map(cloudMask);

// Reduce the collection to the mean of each pixel and display.
var meanImage = collection.reduce(ee.Reducer.mean());
var vizParams = {bands: ['B5_mean', 'B4_mean', 'B3_mean'], min: 0, max: 0.5};
Map.addLayer(meanImage, vizParams, 'mean');

// Load a region in which to compute the mean and display it.
var counties = ee.FeatureCollection('TIGER/2016/Counties');
var santaClara = ee.Feature(counties.filter(ee.Filter.eq('NAME', 'Santa Clara')).first());
Map.addLayer(santaClara);

// Get the mean of NDVI in the region.
var mean = meanImage.select(['nd_mean']).reduceRegion({
  reducer: ee.Reducer.mean(),
  geometry: santaClara.geometry(),
  scale: 30
});

// Print mean NDVI for the region.
mean.get('nd_mean').evaluate(function(val){
  print('Santa Clara spring mean NDVI:', val);
});
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容