GEE必须会教程——基于Landsat影像构建NDVI时间序列

很久很久以前,小编写了一篇基于MODIS影像构建归一化植被指数的文章,不知道大家还有没有印象,有一段时间没有更新时间序列分析相关的文章了。

今天,我们来看看基于Lansat影像,我们来看看在GEE上如何构建NDVI的时间序列。今天写起来有点手痛,小编就只能水一篇代码了。

//导入研究区域
var roi = ee.FeatureCollection('users/hesuixinya511/Province')
                            .filterMetadata("NAME","equals","重庆");
Map.centerObject(roi,6);
Map.addLayer(roi,{"color":"red"},"重庆");
//还原缩放
function applyScaleFactors(image) {
  var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
  var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0);
  return image.addBands(opticalBands, null, true)
              .addBands(thermalBands, null, true);
}
//定义去云掩膜函数
function Mask(image){
  var cloudMask = (1<<3);
  var cloudshadowMask = (1<<4);
  var QA = image.select("QA_PIXEL");
  var mask = QA.bitwiseAnd(cloudMask).eq(0).and(QA.bitwiseAnd(cloudshadowMask).eq(0));
  return image.updateMask(mask);
}
//对L5/L7/L8影像进行处理
var years = ee.List.sequence(2000, 2011);
var L5_COL = ee.ImageCollection(years
  .map(function(y) {
    var start = ee.Date.fromYMD(y, 1, 1);
    var end = start.advance(12, 'month');
    var ndvi = ee.ImageCollection('LANDSAT/LT05/C02/T1_L2')
                  .filterDate(start, end)
                  .map(applyScaleFactors)
                  .map(Mask)
                  .map(function(image){
                    var ndvi = image.normalizedDifference(['SR_B4', 'SR_B3']).rename('NDVI');
                    return image.addBands(ndvi);
                  });
    return ndvi.reduce(ee.Reducer.median()).clip(roi)
                  .set('Year',y);
}));
print (L5_COL);

var years = ee.List.sequence(2012, 2012);
var L7_COL = ee.ImageCollection(years
  .map(function(y) {
    var start = ee.Date.fromYMD(y, 1, 1);
    var end = start.advance(12, 'month');
    var ndvi = ee.ImageCollection('LANDSAT/LE07/C02/T1_L2')
                  .filterDate(start, end)
                  .map(applyScaleFactors)
                  .map(Mask)
                  .map(function(image){
                    var ndvi = image.normalizedDifference(['SR_B4', 'SR_B3']).rename('NDVI');
                    return image.addBands(ndvi);
                  });
    return ndvi.reduce(ee.Reducer.median()).clip(roi)
                  .set('Year',y);
}));
print (L7_COL);

var years = ee.List.sequence(2013, 2023);
var L8_COL = ee.ImageCollection(years
  .map(function(y) {
    var start = ee.Date.fromYMD(y, 1, 1);
    var end = start.advance(12, 'month');
    var ndvi = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2')
                  .filterDate(start, end)
                  .map(applyScaleFactors)
                  .map(Mask)
                  .map(function(image){
                    var ndvi = image.normalizedDifference(['SR_B5', 'SR_B4']).rename('NDVI');
                    return image.addBands(ndvi);
                  });
    return ndvi.reduce(ee.Reducer.median()).clip(roi)
                  .set('Year',y);
}));
print (L8_COL);

var data = ee.ImageCollection(L5_COL.merge(L7_COL).merge(L8_COL));
print(data);
//创建时间序列图表.
var yearlychart = ui.Chart.image.series({
    imageCollection: data.select('NDVI_median'),
    region: roi,
    reducer: ee.Reducer.mean(),
    scale: 500,
    xProperty:'Year'
    }).setOptions({
      interpolateNulls: true,
      lineWidth: 2,
      title: 'NDVI Daily Time Seires',
      vAxis: {title: 'NDVI', viewWindow: {max: 0.8,min: 0.4,}},
      hAxis: {title: 'Date'},
      trendlines: { 0: {title: 'NDVI_trend',type:'linear', showR2: true,  color:'red', visibleInLegend: true}}
    });
print(yearlychart);

来看看结果:

今天的分享到这里就结束了,祝大家身体健康! 

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值