我们可以利用GEE获取一块研究区的NDVI值,那么我们如何利用GEE获取单个或者一定数量的矢量点处的NDVI值呢?
本文演示利用GEE获取矢量点处的NDVI值,其中本文获取的NDVI为Sentinel2数据获取的NDVI,获取Landsat影像的NDVI代码可见博主历史笔记利用GEE获取Sentinel-2与Landsat8影像NDVI。
var geometry = ee.FeatureCollection("users/huiengine/Shandong_Boundary")
//在区域内生成随机样本点
var points = ee.FeatureCollection("users/huiengine/ShanDong_ST2020")
print(points,"points");
Map.addLayer(points, {}, "Points" , true);
Map.addLayer(geometry, {}, "shandong" , true);
//sentinel数据去云
function maskS2clouds(image) {
var qa = image.select('QA60');
// 第10和11位分别是云和卷云。位移运算去云
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);
}
function NDVI_Sentinel2(image){
var ndvi = image.normalizedDifference(["B8","B4"]).rename('NDVI');
return image.addBands(ndvi.rename('NDVI'));
}
var scol= ee.ImageCollection("COPERNICUS/S2")
.filterBounds(geometry)
.filterDate('2020-04-01', '2020-05-15')
.map(maskS2clouds)
.map(NDVI_Sentinel2)
;
print("scol",scol);
var ndvi_before =scol.qualityMosaic('NDVI').clip(points);
print("ndvi_before",ndvi_before);
// 值提取至点
var samples = ndvi_before.select("NDVI").sampleRegions({
collection: points,
scale: 30 ,
geometries: true
});
print(samples,'samples');
Map.addLayer(samples,{}, "samples" , false);
print(" ndvi value ", samples);
//导出逐年NDVI个点的CSV文件
Export.table.toDrive({
collection: samples,
description:'shandong_ST',
folder:"shandong",
});
将结果导入到Google drive下载后即可得到矢量点处的NDVI值数据
样本点分布图
矢量点处的NDVI值