Google Earth Engine(区域统计)
提示:
在通过GEE计算遥感的地表参量以后,我们就需要对计算出来的数据进行统计。GEE上面画图的功能并不是很齐全,得到的效果也不尽如人意。因此我们就需要将GEE对区域的统计量进行导出,导入到本地以后,再进行绘图。
本期的的主要内容就是利用GEE对区域内的地表参量(如植被覆盖度、叶面积指数、蒸散量,本次以NDVI为例)进行统计(如平均值、面积等)。最后把统计的值导出到本地。
var table = ee.FeatureCollection("users/boyxiaozheng/feature/beijing");
//定义计算NDVI的函数
function cal_ndvi(image){
var mask=ee.Algorithms.Landsat.simpleCloudScore(image).select(['cloud']).lte(20);
var ndvi=image.normalizedDifference(['B5', 'B4']).updateMask(mask);
return ndvi;
}
//设置开始时间
var start_time=ee.Date('2014-01-01')
//初始化列表,存储统计的值
var data_list=[]
for (var index = 0;index< 4; index++){
var temp_image= ee.ImageCollection("LANDSAT/LC08/C01/T1_RT")
.filterBounds(table.geometry())
.filter(ee.Filter.lt('CLOUD_COVER',10))
//根据循环的index依次筛选四个季度的Landsat-8数据
.filterDate(ee.Date(start_time).advance(index*3,'month'),ee.Date(start_time).advance((index+1)*3,'month'))
.map(cal_ndvi)
.mean();
//对每个季度的影像进行求平均
var meanDictionary = temp_image.reduceRegion({
//可以设置成max、min或count(像元个数)
reducer: ee.Reducer.mean(),
geometry: table.geometry(),
scale: 30,
maxPixels: 1e9
});
//把统计量存成Feature,并记录开始时间和结束时间
var temp_feature=ee.Feature(null,meanDictionary);
temp_feature = temp_feature.set('satr_time', ee.Date(start_time).advance(index*3,'month'));
temp_feature = temp_feature.set('end_time', ee.Date(start_time).advance((index+1)*3,'month'));
data_list.push(temp_feature)
}
//把存储Feature的列表转成FeatureCollection
var featureCollection = ee.FeatureCollection(data_list);
//把数据存到谷歌云盘上面
Export.table.toDrive({
collection: featureCollection,
description: 'exportTableExample',
fileFormat: 'CSV'
});