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);
posted @ 2022-06-22 15:07  Weltㅤ  阅读(1269)  评论(4编辑  收藏  举报