【问题标题】:How to create time series (NDVI) for each polygon contained in a feature collection in google earth engine?如何为谷歌地球引擎中的特征集合中包含的每个多边形创建时间序列(NDVI)?
【发布时间】:2019-05-18 05:36:08
【问题描述】:

我有一个 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?

【问题讨论】:

    标签: time-series polygon raster google-earth-engine


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-11-29
      • 1970-01-01
      • 1970-01-01
      • 2022-07-03
      • 2021-07-22
      • 2011-03-12
      • 1970-01-01
      • 2019-01-05
      • 1970-01-01
      相关资源
      最近更新 更多