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

时间:2019-05-17 09:44:46

标签: time-series polygon raster 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表示?

1 个答案:

答案 0 :(得分:0)

您需要在第二个调用中添加'band'参数,如下所示:

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