GEE学习笔记二 GEE获取Sentine-2与Landsat8 NDVI数据并进行时序变化分析

本文主要演示利用GEE对Lnadsat8与Sentinel-2数据获取研究区内的NDVI并进行时序变化演示

NDVI的计算公式:NDVI = (近红外波段 - 红波段) / (近红外波段 + 红波段)
因为每种卫星波段不同,所以计算NDVI时选用的波段都有所不同,本文提到的Landsat8与Sentinel-2影像计算NDVI公式如下:

Landsat8: NDVI = (band5 - band4) / (band5 + band4)

Sentinel2: NDVI = (band8 - band4) / (band8 + band4)

通过GEE获取两种影像数据的NDVI以及趋势线代码如下:

var geometry = ee.FeatureCollection('users/huiengine/taian_boundary')
Map.centerObject(geometry,7)

var visParam_NDVI = {
 min: -0.1,
 max: 0.9,
 palette: 'FFFFFF, CE7E45, DF923D, F1B555, FCD163, 99B718, 74A901, 66A000, 529400,' +
   '3E8601, 207401, 056201, 004C00, 023B01, 012E01, 011D01, 011301'
};



//--------------------------------Landsat8获取 NDVI
//Landsat8去云函数
function maskL8sr(image) {
  // Bits 3 and 5 are cloud shadow and cloud, respectively.
  var cloudShadowBitMask = (1 << 3);
  var cloudsBitMask = (1 << 5);
  // Get the pixel QA band.
  var qa = image.select('pixel_qa');
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                 .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
  return image.updateMask(mask);
}

function createNDVI_L8(image){
  var ndvi = image.normalizedDifference(["B5","B4"]).rename('NDVI');
  return image.addBands(ndvi);
}

var L8_COL = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
.filterDate("2020-04-01", "2020-05-15")
.filterBounds(geometry)
.map(maskL8sr)
.map(createNDVI_L8)
.select('NDVI');
print(L8_COL)
Map.addLayer(L8_COL.mean().clip(geometry), visParam_NDVI, 'L8_col');

//趋势线代码 
var L8_chart = ui.Chart.image.series({
    imageCollection: L8_COL.select('NDVI'),
    region: geometry,
    reducer: ee.Reducer.mean(),
    scale: 500
    }).setOptions({
      interpolateNulls: true,
      lineWidth: 2,
      title: 'Landsat8 NDVI Time Seires',
      vAxis: {title: 'NDVI'},
      hAxis: {title: 'Date'},
      trendlines: { 0: {title: 'NDVI_trend',type:'linear', showR2: true,  color:'red', visibleInLegend: true}}
    });
print(L8_chart);



//--------------------------------Sentinel-2获取 NDVI
//使用QA波段去云
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).set(image.toDictionary(image.propertyNames()));
}

//NDVI的计算公式
function createNDVI(image){
  var ndvi = image.normalizedDifference(["B8","B4"]).rename('NDVI');
  return image.addBands(ndvi);
}

var S2_COL = ee.ImageCollection("COPERNICUS/S2")
.filterDate("2020-04-01", "2020-05-15")
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20))
.filterBounds(geometry)
.map(maskS2clouds)
.map(createNDVI)
.select('NDVI');
print(S2_COL)
Map.addLayer(S2_COL.mean().clip(geometry), visParam_NDVI, 'S2_col');

//趋势线代码 
var S2_chart = ui.Chart.image.series({
    imageCollection: S2_COL.select('NDVI'),
    region: geometry,
    reducer: ee.Reducer.mean(),
    scale: 500
    }).setOptions({
      interpolateNulls: true,
      lineWidth: 2,
      title: 'Sentinel-2 NDVI Time Seires',
      vAxis: {title: 'NDVI'},
      hAxis: {title: 'Date'},
      trendlines: { 0: {title: 'NDVI_trend',type:'linear', showR2: true,  color:'red', visibleInLegend: true}}
    });
print(S2_chart);





结果显示
Landsat8获取的NDVI
Landsat8获取的NDVI图
Sentinel-2获取的NDVI
Sentinel-2获取的NDVI图
NDVI时间序列及趋势
获取NDVI时间序列曲线及趋势

附上本文代码链接:https://code.earthengine.google.com/5ddaca630b23728664fd88d4a82c8d22

GEE是Google Earth Engine的缩写,是一个基于云计算的地理信息数据处理平台。使用GEE进行Landsat-8级产品数据的大气校正可以分为以下几个步骤: 1. 在GEE中选择Landsat-8 OLI/TIRS Collection 2 Level-2数据集作为数据源。 2. 选择需要进行大气校正的影像,并导入到代码中。 3. 根据影像的时间和位置信息,获取对应的气象数据,如大气温度、水汽含量等。 4. 使用提供的大气校正模块,对影像进行大气校正。GEE提供了多种大气校正模块,如DOS (Dark Object Subtraction)、ATCOR (Atmospheric and Topographic Correction)等。 5. 对校正后的影像进行后续处理,如NDVI计算、图像显示等。 以下是一个基于GEE进行Landsat-8级产品数据大气校正的示例代码: ```javascript // 选择数据集 var dataset = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2') .filter(ee.Filter.eq('WRS_PATH', 44)) .filter(ee.Filter.eq('WRS_ROW', 34)) .filterDate('2018-01-01', '2018-12-31') .select(['SR_B2', 'SR_B3', 'SR_B4', 'SR_B5', 'SR_B6', 'SR_B7']); // 导入需要进行大气校正的影像 var img = ee.Image(dataset.first()); // 获取影像的时间和位置信息 var date = img.get('system:time_start'); var lat = img.get('LAT'); var lon = img.get('LON'); // 获取气象数据 var meteoData = ee.ImageCollection('NOAA/CFSV2/FOR6H') .filterBounds(ee.Geometry.Point(lon, lat)) .filterDate(ee.Date(date).advance(-1, 'day'), ee.Date(date)) .select(['Temperature_height_above_ground', 'Specific_humidity_height_above_ground']); // 获取大气温度和水汽含量 var airTemp = meteoData.select('Temperature_height_above_ground').mean(); var waterVap = meteoData.select('Specific_humidity_height_above_ground').mean(); // 大气校正 var corrImg = ee.Algorithms.Landsat.simpleCloudScore(img).select(['B2','B3','B4','B5','B6','B7','cloud']); var dosCorr = ee.Image(ee.Algorithms.Landsat.dos(corrImg, airTemp, waterVap, 0.08)); // 输出校正后的影像 Map.addLayer(dosCorr, {bands: ['B4', 'B3', 'B2'], min: 0, max: 3000}, 'dos corrected'); ``` 其中,ee.Algorithms.Landsat.simpleCloudScore用于对影像进行云检测,返回一个包含云掩膜的影像,ee.Algorithms.Landsat.dos用于进行DOS大气校正,返回一个校正后的影像。在输出校正后的影像时,可以选择需要显示的波段、色彩范围等参数。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值