我正在尝试为整个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);
答案 0 :(得分:0)
GEE具有用于计算NDVI的内置功能
var image = ee.Image(
l8.filterBounds(point)
.filterDate('2015-01-01', '2015-12-31')
.sort('CLOUD_COVER')
.first()
);
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);
所有这些示例都来自GEE编写的非常好的tutorial,值得一看。