NDVI为归一化植被指数、EVI为增强植被指数,据GEE官方介绍NDTI为归一化热差指数,用于区分城市地区的人行道和屋顶、NDBI为归一化建筑物指数
用来分析城市建成区。今天来分享如何在GEE中利用landsat影像计算上述指数,并进行相关性分析。相关性分析用Pearson相关系数表示:
//首先,选择研究区,以山西省为研究区
var roi = ee.FeatureCollection("users/lilei655123/shanxi");
//去云函数
function rmL8Cloud(image) {
var cloudShadowBitMask = (1 << 3);
var cloudsBitMask = (1 << 5);
var qa = image.select('pixel_qa');
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
return image.updateMask(mask)
.copyProperties(image)
.copyProperties(image, ["system:time_start",'system:time_end']);
}
var star_date = '2020-07-01'//定义起始时间
var end_date = '2020-09-30'//定义终止时间
var L8_ = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR").filterBounds(roi)
.filterDate(star_date, end_date)
//.filter(ee.Filter.lt('CLOUD_COVER',10))//云量设//按云量排序//云量过滤
.map(rmL8Cloud)
.median()
.clip(roi)
print(L8_)
// 加载影像
Map.addLayer(L8_,{min:0.0,max:0.4, bands:'B5,B4,B3'},'Image');
Map.centerObject(roi)
var img = L8_.select(['B2','B3', 'B4', 'B5','B6', 'B7'])
//计算NDVI
var ndvi = img.expression(
'((NIR - RED) / (NIR + RED))', {
'NIR': img.select('B5'),
'RED': img.select('B4')
}).rename('NDVI');
//计算NDTI
var ndti = img.expression(
'((SWIR1-SWIR2)/(SWIR1 + SWIR2))',{
'SWIR1': img.select('B6'),
'SWIR2': img.select('B7')
}).rename('NDTI');
//计算EVI
var evi = img.expression(
'2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
'NIR': img.select('B5'),
'RED': img.select('B4'),
'BLUE': img.select('B2')
}).rename('EVI');
//计算NDBI
var ndbi = img.expression(
'(MIR - NIR)/(MIR + NIR)', {
'NIR': img.select('B5'),
'MIR': img.select('B6')
}).rename('NDBI');
//计算MNDWI
var mndwi = img.expression(
'(GREEN - MIR) / (GREEN + MIR)', {
'GREEN': img.select('B3'),
'MIR': img.select('B6')
}).rename('MNDWI')
//pearsonsCorrelation计算相关性系数
img = img.addBands(ndvi.rename('ndvi'))
img = img.addBands(ndti.rename('ndti'))
img = img.addBands(ndbi.rename('ndbi'))
img = img.addBands(evi.rename('evi'))
img = img.addBands(mndwi.rename('mndwi'))
var corra =img.select(["ndvi","ndti"])
// Here, sample the stack:
var sample = corra.sample({'region':roi,
'scale': 30,
'projection': 'EPSG:4326',
'numPixels':100})
// Call reducer correctly:
var correl = ee.Reducer.pearsonsCorrelation();
// Then choose two properties to see the correlation:
var reduced = sample.reduceColumns(correl, ['ndvi', 'ndti'])
print(reduced)
Map.addLayer(ndvi, {'min':0,'max':1,'palette':['#A9A9A9','00FF00']}, 'NDVI')
//导出函数
Export.image.toDrive({
image: ndvi,//
description: 'ndvi2020',//
scale: 30,//
region:roi,//
maxPixels:1e13,
fileFormat: 'GeoTIFF',
});
计算结果:
Pearson相关系数结果:
声明:仅供学习使用!
**更多内容请关注微信公众号“生态遥感监测笔记”