【发布时间】:2023-01-26 03:47:13
【问题描述】:
使用此代码,GGE 获得了 2022 年最少云的图像,但我需要计算特定图像 (2022-07-20) 中的 NDVI。我应该改变什么? 如果我尝试在 filter.Date 中指定日期,代码将不起作用。 .filterDate('2022-07-20')
错误是: NDVI 图像:图层错误:Image.select,参数“输入”:无效类型。 预期类型:图像。 实际类型:ImageCollection。
var point = ee.Geometry.Point([8.73727, 45.81165]);
// Import the Sentinel-2 image collection.
var S2 = ee.ImageCollection("COPERNICUS/S2")
// Get the least cloudy image in 2022.
var image = ee.Image(
S2.filterBounds(point)
.filterDate('2022-01-01', '2022-12-31')
.sort('CLOUD_COVER')
.first()
);
// Compute the Normalized Difference Vegetation Index (NDVI).
var nir = image.select('B8');
var red = image.select('B4');
var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI');
// Display the result.
Map.centerObject(image, 9);
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 'green']};
Map.addLayer(ndvi, ndviParams, 'NDVI image');
【问题讨论】:
-
刚刚运行你的代码,你提到的错误没有显示。
标签: javascript google-earth-engine