因为目前从事的研究,需要计算sentinel-2A影像数据一年中NDVI的均值,在网上也学习了一些博客,很多博客没有把ndvi计算和保存到本地没有写完,这篇博客将这一整套流程写了下,作为参考。
首先要导入矢量范围,可以自己手动画,也可以导入制作好的矢量 接着正文部分如下,打开GEE平台复制下面的代码,点击运行,右边出现RUN就能点击下载到谷歌云盘了。
Map.centerObject(geometry,6)
var colorizedVis = {
min: -1,
max: 1,
palette: ['blue', 'white', 'green'],
};
function maskS2clouds(image) {
var qa = image.select('QA60');
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000).set(image.toDictionary(image.propertyNames()));
}
var S2 = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2020-01-01', '2020-12-31')
.filterBounds(geometry)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.map(maskS2clouds);
var addNDVI = function(image) {
return image.addBands(image.normalizedDifference(['B8', 'B4']).rename('NDVI'));
};
var S2 = S2.map(addNDVI);
var NDVI = S2.select(['NDVI']);
print(NDVI);
var NDVImed = NDVI.reduce(ee.Reducer.mean());
Map.addLayer(NDVImed.clip(geometry), colorizedVis, 'NDVI image');
var name = "ndvi_mean_2020";
print(name);
Export.image.toDrive({
image: NDVImed ,
description: name,
fileNamePrefix: name,
folder: 'rock_ndvi',
region: geometry,
crs:'EPSG:4326',
scale: 10,
maxPixels: 1e13
});
右边界面:
|