我从地球引擎(ee)编码开始。按照https://developers.google.com/earth-engine/tutorial_api_07的指示,我可以将一些代码放在一起并得到绘图。但是,为什么在filterDate('2017-01-01', '2017-12-31')
期间,情节上的日期范围是从2016年到2018年?
var image = ee.Image(
s2.filterBounds(point)
.filterDate('2017-01-01', '2017-12-31')
.sort('CLOUD_COVER')
.first()
);
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
return image.addBands(ndvi);
};
var ndvi = addNDVI(image).select('NDVI');
var withNDVI = s2.map(addNDVI);
var chart = ui.Chart.image.series({
imageCollection: withNDVI.select('NDVI'),
region: point,
reducer: ee.Reducer.first(),
scale: 30
}).setOptions({title: 'NDVI over time'});
print(chart);
答案 0 :(得分:0)
您的代码未生成日期范围内的预期图表,因为您是将时间过滤结果设置为图像(ee.Image(...first()
),然后将原始s2
图像集合用于NDVI计算和图表。您的代码应如下所示,在其中将过滤结果设置为图像收集变量,并在NDVI函数中使用它并进行绘图:
var s2 = ee.ImageCollection("COPERNICUS/S2"),
point = ee.Geometry.Point([-86.54734555291998, 34.74135144079877]);
var filteredIC = s2.filterBounds(point)
.filterDate('2017-01-01', '2017-12-31')
.sort('CLOUD_COVER')
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
return image.addBands(ndvi);
};
var withNDVI = filteredIC.map(addNDVI);
var chart = ui.Chart.image.series({
imageCollection: withNDVI.select('NDVI'),
region: point,
reducer: ee.Reducer.first(),
scale: 30
}).setOptions({title: 'NDVI over time'});
print(chart);
以下是代码的链接:https://code.earthengine.google.com/6e7dba0fbbda1cab133b3dffe31e2e9e
我希望这会有所帮助!