GEE|使用Google Earth Engine制作作物时间序列变化曲线
在提取某种种植模式的时候,需要知道其关键物候期,NDVI时序曲线是一个非常好的手段来帮助我们寻找最优的时间-光谱特征,在GEE上可以较为方便的绘制出NDVI时序曲线,代码如下:
//Sentinel2数据制作经过云量筛选后的时间序列NDVI
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).copyProperties(image).set('system:time_start', image.get('system:time_start'));
}
//定义感兴趣区
var youcai = ee.Feature(
ee.Geometry.Point([112.511781,30.849084]),
{label: 'rape'});
var xiaomai = ee.Feature(
ee.Geometry.Point([112.581530,30.734522]),
{label: 'wheat'});
var zhibei = ee.Feature(
ee.Geometry.Point([112.449210,30.635505]),
{label: 'Vegetation'});
var butoushui = ee.Feature(
ee.Geometry.Point([112.527002,30.455986]),
{label: 'Impermeable layer'});
var shuiti = ee.Feature(
ee.Geometry.Point([112.455339,30.440064]),
{label: 'Water'});
//将wu种作物感兴趣区合并
var cropRegions = new ee.FeatureCollection([youcai,xiaomai,zhibei,butoushui,shuiti]);
//筛选s2数据
var s2= ee.ImageCollection('COPERNICUS/S2_SR')
.filterDate('2021-10-1', '2022-06-01')
.filterBounds(cropRegions)
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE',"less_than",20)
.map(maskS2clouds)
//计算每副影像的NDVI并制作数据集
var ndvi = s2.map(function(image) {
return image
.select()
.addBands(image.normalizedDifference(['B8', 'B4']).select([0], ['NDVI']))
});
//渲染NDVI显示颜色
var vis = {min: -0.2, max: 1, palette: [
'FFFFFF', 'CE7E45', 'FCD163', '66A000', '207401',
'056201', '004C00', '023B01', '012E01', '011301'
]};
Map.addLayer(ndvi, vis, 'NDVI');
//Map.addLayer(cropRegions, {color: COLOR.GAOLIANG},'ROI');
// Map.addLayer(gaoliang, {color: COLOR.GAOLIANG});
// Map.addLayer(yumi, {color: COLOR.YUMI});
// Map.addLayer(dadou, {color: COLOR.DADOU});
//定义图表及样式
var ndviTimeSeries = ui.Chart.image.seriesByRegion({
imageCollection: ndvi,
regions: cropRegions,
reducer: ee.Reducer.mean(),
band: 'NDVI',
scale: 10,
xProperty: 'system:time_start',
seriesProperty: 'label'
});
ndviTimeSeries.setChartType('LineChart');
ndviTimeSeries.setOptions({
title: 'Sentinel-2数据作物时间序列NDVI变化',
vAxis: {
title: 'NDVI'
},
lineWidth: 1,
pointSize: 4,
});
print(ndviTimeSeries);
本文作者:Weltㅤ
本文链接:https://www.cnblogs.com/tangjielin/p/16367778.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步