今天来分享一下如何在GEE中利用森林变化数据集进行分析,所使用的数据集为UMD/hansen/global_forest_change_2020_v1_8
GEE调用代码如下:
//以山西省为研究区
var roi = ee.FeatureCollection("users/lilei655123/shanxi");
var GFC = ee.Image("UMD/hansen/global_forest_change_2020_v1_8")
Map.centerObject(roi,5)
var treeCover = GFC.select(['treecover2000']).clip(roi);
var loss = GFC.select(['loss']).clip(roi);
var gain = GFC.select(['gain']).clip(roi);
// 绿色显示森林覆盖范围
Map.addLayer(treeCover,
{palette: ['000000', '00FF00'], max: 100}, 'Forest Cover')
// 红色代表损失
Map.addLayer(loss.updateMask(loss),
{palette: ['FF0000']}, 'Loss')
// 蓝色代表增益
Map.addLayer(gain.updateMask(gain),
{palette: ['0000FF']}, 'Gain')
// 统计每年损失的面积
var lossAreaImage = loss.multiply(ee.Image.pixelArea())
var lossYear = GFC.select(['lossyear'])
var lossByYear = lossAreaImage.addBands(lossYear).reduceRegion({
reducer: ee.Reducer.sum().group({
groupField: 1
}),
geometry: roi,
scale: 30,
maxPixels: 1e13
})
print(lossByYear)
var statsFormatted = ee.List(lossByYear.get('groups'))
.map(function(year) {
var d = ee.Dictionary(year);
return [ee.Number(d.get('group')).format("20%02d"), d.get('sum')]
})
var statsDictionary = ee.Dictionary(statsFormatted.flatten())
print(statsDictionary)
var chart = ui.Chart.array.values({
array: statsDictionary.values(),
axis: 0,
xLabels: statsDictionary.keys()
}).setChartType('ColumnChart')
.setOptions({
title: 'Yearly Forest Loss',
hAxis: {title: 'Year', format: '####'},
vAxis: {title: 'Area (square meters)'},
legend: { position: "none" },
lineWidth: 1,
pointSize: 3
})
print(chart)
分析结果
声明:仅供学习使用!
**更多内容请关注微信公众号“生态遥感监测笔记”