如何为 google 地球引擎中要素集合中包含的每个多边形创建时间序列 (NDVI)?

How to create time series (NDVI) for each polygon contained in a feature collection in google earth engine?

我有 Landsat 5 的图像集和数千个多边形和点的特征集(在示例中,我只有三个)。我想随着时间的推移计算每个多边形的 NDVI(和 NDWI)平均值,就像我使用的那样:ui.Chart.image.series;

如果我只使用此代码测试一个多边形:

var p1= ee.Geometry.Point([-78.55995626672507,35.05443673532838])
var pol = ee.Geometry.Polygon([[[-78.57239414626946,35.01247143741747], 
[-78.57186843330254,35.012559309453266], 
[-78.57199717933526,35.01277020195395], 
[-78.57253362113823,35.01272626606113],
[-78.57239414626946,35.01247143741747]
]]);

var ens = [
ee.Feature(pol, {name: 'Thiessen'})
];

var col =  ee.FeatureCollection(ens)
print(col)

// NDVI: B4 and B3
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
return image.addBands(ndvi);
};

// Apply the cloud mask and NDVI function to Landsat 5 imagery and   print the chart
 var l5 = ee.ImageCollection("LANDSAT/LT05/C01/T1_TOA")
      .filter(ee.Filter.calendarRange(1985,2007,'year'))
      .filter(ee.Filter.calendarRange(1,1,'month'))
      .filterBounds(p1)
      .map(addNDVI) 

print(ui.Chart.image.series(l5.select('NDVI'), col, ee.Reducer.mean(), 30));

使用此代码我获得了 this figure。我想获得具有多个多边形的相同类型的图形(一个图形包含多边形的所有时间序列)。

我试过这段代码:

var p1= ee.Geometry.Point([-78.55995626672507,35.05443673532838])
var p2= ee.Geometry.Point([-78.5725093420931,35.05908805245044])
var pol = ee.Geometry.Polygon([[[-78.57239414626946,35.01247143741747], 
[-78.57186843330254,35.012559309453266], 
[-78.57199717933526,35.01277020195395], 
[-78.57253362113823,35.01272626606113],
[-78.57239414626946,35.01247143741747]
]]);

var ens = [
ee.Feature(p2, {name: 'Thiessen'}),
ee.Feature(pol, {name: 'Thiessen'})
];

var col =  ee.FeatureCollection(ens)
print(col)

// NDVI: B4 and B3
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B4', 'B3']).rename('NDVI');
return image.addBands(ndvi);
};

// Apply the cloud mask and NDVI function to Landsat 5 imagery and    print the chart
var l5 = ee.ImageCollection("LANDSAT/LT05/C01/T1_TOA")
      .filter(ee.Filter.calendarRange(1985,2007,'year'))
      .filter(ee.Filter.calendarRange(1,1,'month'))
      .filterBounds(p1)
      .map(addNDVI) 

//Create a graph of the time-series.
var graph = ui.Chart.image.seriesByRegion({
imageCollection: l5, 
regions: col, 
reducer: ee.Reducer.mean(),
scale: 30,
})
print(graph)

此代码提供this figure

最后的代码显示了我想要的图表。但是,它不会计算我想要的。对于多边形 pol,我应该有两个代码相同的图形,但事实并非如此。我怎么能用代码 1 进行相同的计算但显示为代码 2?

您需要将 'band' 参数添加到第二次调用,如下所示:

var graph = ui.Chart.image.seriesByRegion({
  imageCollection: l5, 
  regions: col, 
  band: 'NDVI',
  reducer: ee.Reducer.mean(),
  scale: 30,
})