今天来分享一下如何在GEE中基于哨兵二号数据计算植被覆盖度,并分级制图。 以宁夏回族自治区为研究区 代码如下: var roi = ee.FeatureCollection("users/lilei655123/Ningxia"); Map.centerObject(roi,7)
今天来分享一下如何在GEE中基于哨兵二号数据计算植被覆盖度,并分级制图。
以宁夏回族自治区为研究区
代码如下:
var roi = ee.FeatureCollection("users/lilei655123/Ningxia");
Map.centerObject(roi,7)
//boundary
var styling = {color:"red",fillColor:"00000000"};
Map.addLayer(roi.style(styling),{},"geometry")
function maskS2clouds(image) {
var qa = image.select('QA60');
// Bits 10 and 11 are clouds and cirrus, respectively.
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000);
}
var S2 = ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2021-07-01', '2021-09-30')
.filterBounds(roi)
// Pre-filter to get less cloudy granules.
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',10))
.map(maskS2clouds)
.median();
//ndvi
var NDVI1 = S2.expression('(NIR-R)/(NIR+R)',{
'R': S2.select(['B4']),
'NIR': S2.select(['B8']),
})
var imgFVC = ((NDVI1.subtract(ee.Image(0.05))).divide((ee.Image(0.95)).subtract(ee.Image(0.05)))).float();
var FVC=((imgFVC.lt(0)).multiply(0))
.add(((imgFVC.gt(0)).and(imgFVC.lte(1))).multiply(imgFVC))
.add((imgFVC.gt(1)).multiply(1))
var FVC_Class=FVC.where(FVC.lt(0.2),1)
.where(((FVC.gte(0.2)).and(FVC.lt(0.4))),2)
.where(((FVC.gte(0.4)).and(FVC.lt(0.6))),3)
.where(((FVC.gte(0.6)).and(FVC.lt(0.8))),4)
.where(FVC.gt(0.8),5)
Map.addLayer(FVC_Class.clip(roi),{min:1,max:5,palette:['DCDCDC','FFEBCD','99B718','529400','011301']},'FVC_Class')
var visualization = {
min: 0.0,
max: 0.3,
bands: ['B4', 'B3', 'B2'],
};
Map.addLayer(S2.clip(roi), visualization, 'RGB');
显示结果如下:
声明:仅供学习使用!
更多内容请关注微信公众号“生态遥感监测笔记”