我正在尝试计算完整 Landsat 集合的 ndvi。首先,我去除云层,然后尝试计算 ndvi 指数,如下所示。 不幸的是我没有得到任何结果,有人知道为什么代码不起作用吗?
谢谢
代码:
// Function to cloud mask Landsat 8.
var maskL8SR = function(image) {
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = ee.Number(2).pow(3).int();
var cloudsBitMask = ee.Number(2).pow(5).int();
// Get the QA band.
var qa = image.select('pixel_qa');
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0).and(
qa.bitwiseAnd(cloudsBitMask).eq(0));
return image
// Scale the data to reflectance and temperature.
.select(['B4', 'B5'], ['Red', 'NIR']).multiply(0.0001)
.updateMask(mask);
};
var lst8 = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterDate('2013-04-07', '2018-05-01')
.filterBounds(geometry)
.map(maskL8SR)
.map(addNDVI_l8).select('NDVI');
lst8 = lst8.map(addNDVI_l8);
lst8 = lst8.filterBounds(geometry);
最佳答案
GEE 具有计算 NDVI 的内置函数
选择图片
var image = ee.Image(
l8.filterBounds(point)
.filterDate('2015-01-01', '2015-12-31')
.sort('CLOUD_COVER')
.first()
);
计算NDVI
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
显示图片
Map.centerObject(image, 9);
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
Map.addLayer(ndvi, ndviParams, 'NDVI image');
没有该功能
var nir = image.select('B5');
var red = image.select('B4');
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI');
集合
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
return image.addBands(ndvi);
};
var withNDVI = l8.map(addNDVI);
所有这些例子都来自一个非常好的tutorial GEE 写的,值得一看。
关于collections - 计算 Landsat 集合的 NDVI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52631489/