取一段时间内的多张图像
ee.ImageCollection
计算每张图像的NDVI
image.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);
});