ee.Algorithms.Landsat.simpleComposite
函数来做到这一点,但是当我将该函数应用于我的
filtered
变量时,我继续运行其余的代码,这表明filtered.map 不是一个函数。我的猜测是 simplecomposite 函数以某种方式改变了过滤对象的类,但我不确定如何正确实现
ee.Algorithms.Landsat.simpleComposite
以仅包含云量低于 10% 的图像。我对 Google 地球引擎还很陌生,因此我们将不胜感激任何帮助!
var LS7 = ee.ImageCollection("LANDSAT/LE07/C02/T1"),
//filtering data
var filtered = LS7.filterDate('2016-01-01', '2016-12-31');
var filtered = ee.Algorithms.Landsat.simpleComposite({collection: filtered,asFloat:true})
// Map over the collection to produce the desired data as a collection.
var MSAVI2_collection = filtered.map(function (image) {
return image.expression(
'(2 * NIR + 1 - sqrt(pow((2 * NIR + 1), 2) - 8 * (NIR - RED)) ) / 2',
{
'NIR': image.select('B4'),
'RED': image.select('B3')
}
);
});
//take an average of all MSAVI2 Values.
var MSAVI2 = MSAVI2_collection.median();
//add the MSAVI2 layer
Map.addLayer(MSAVI2, {min: -0.15, max: 0.15}, 'MSAVI2');
我不断运行其余的代码,这表明filtered.map不是一个函数。原因是
ee.Algorithms.Landsat.simpleComposite
的输出是一个简单的图像,而不是
ImageCollection
ee对象(根据函数文档),并且
ee.Image
没有
map
方法。要计算单个图像中的 MSAVI2 表达式,请遵循以下方法:
// Check the image type of 'filtered' variable
print(ee.Algorithms.ObjectType(filtered));
// Compute MSAVI2 index
var getMSAVI2 = function(img){
return img.expression(
'(2 * NIR + 1 - sqrt(pow((2 * NIR + 1), 2) - 8 * (NIR - RED)) ) / 2',
{
'NIR': img.select('B4'),
'RED': img.select('B3')
});
};
// Apply above function to the composite image
var MSAVI2 = getMSAVI2(filtered);
//add the MSAVI2 layer
Map.addLayer(MSAVI2, {min: -0.15, max: 0.15}, 'MSAVI2');