前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >GEE 教程——基于sentinel-2数据的NDVI和EVI指数的对比

GEE 教程——基于sentinel-2数据的NDVI和EVI指数的对比

作者头像
此星光明
发布2025-01-21 12:45:21
发布2025-01-21 12:45:21
11700
代码可运行
举报
运行总次数:0
代码可运行

简介

GEE 教程——基于sentinel-2数据的NDVI和EVI指数的对比

NDVI(Normalized Difference Vegetation Index)和EVI(Enhanced Vegetation Index)是两种常用的植被指数,用于评估植被生长状况和活力。

NDVI是最常见的植被指数之一,通过计算红外波段和可见光波段的差异来评估植被的绿度。NDVI的计算公式为:(NIR - Red) / (NIR + Red),其中NIR为近红外波段反射值,Red为红光波段反射值。NDVI的取值范围为-1到1之间,数值越高表示植被覆盖度越高。

EVI是一种对NDVI的改进,主要解决NDVI在饱和和大气效应方面存在的问题。EVI的计算公式为:2.5 * (NIR - Red) / (NIR + 6 * Red - 7.5 * Blue + 1),其中NIR、Red和Blue分别为对应波段的反射值。EVI的取值范围没有限制,通常为负数到正数之间,数值越高表示植被覆盖度越高。

NDVI和EVI可以用于监测植被生长的季节变化、评估植被健康状况、监测干旱程度等。它们在农业、林业、生态学等领域有广泛的应用。

函数

ui.Chart.array.values(array, axis, xLabels)

Generates a Chart from an array. Plots separate series for each 1-D vector along the given axis.

  • X-axis = Array index along axis, optionally labeled by xLabels.
  • Y-axis = Value.
  • Series = Vector, described by indices of the non-axis array axes.

Returns a chart.

Arguments:

array (Array|List<Object>):

Array to chart.

axis (Number):

The axis along which to generate the 1-D vector series.

xLabels (Array|List<Object>, optional):

Labels for ticks along the x-axis of the chart.

Returns: ui.Chart

代码解释

### 1. 区域定义 - **AOI (Area of Interest)**: 定义了一个感兴趣区域,使用多边形来指定地理坐标。 - **Silviculture**: 定义了一个林业区域,包含多个多边形,表示特定的林业区域。

### 2. 时间范围 - **startDate 和 endDate**: 设置了数据筛选的时间范围,从2020年1月15日到1月30日。

### 3. 数据获取 - **S2 (Sentinel-2 Image Collection)**: 从 Sentinel-2 数据集中获取影像,使用 `filterDate` 方法筛选指定时间段内的影像,并使用 `filterBounds` 方法确保影像覆盖 AOI 区域。 - **img**: 计算所选影像集合的中位数,并使用 `clip` 方法裁剪到 AOI 区域。

### 4. 可视化设置 - **viz**: 定义了影像的可视化参数,包括最小值、最大值和所选波段(B4, B3, B2),用于生成真实颜色图层。

### 5. 指数计算 - **EVI (Enhanced Vegetation Index)**: 通过公式计算 EVI,使用 NIR(近红外)、红光和蓝光波段的数据。计算后重命名为 'EVI' 并添加到地图上。 - **NDVI (Normalized Difference Vegetation Index)**: 通过公式计算 NDVI,使用 NIR 和红光波段的数据。计算后重命名为 'NDVI' 并添加到地图上。

### 6. 数据提取 - **reduceRegion**: 对 NDVI 和 EVI 使用 `reduceRegion` 方法,提取在 Silviculture 区域内的指数值,并将结果存储为列表。

### 7. 图表生成 - **ui.Chart.array.values**: 创建一个散点图,X 轴为 NDVI,Y 轴为 EVI。设置图表的标题、坐标轴标签、点大小和颜色等选项。

### 8. 显示图表 - **print(chart)**: 将生成的图表打印到控制台,以便查看 NDVI 和 EVI 之间的关系。

代码

代码语言:javascript
代码运行次数:0
复制
var AOI = 
    /* color: #d63000 */
    /* shown: false */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.FeatureCollection(
        [ee.Feature(
            ee.Geometry.Polygon(
                [[[-51.92002134176155, -20.867693855608483],
                  [-51.92002134176155, -21.076711250815702],
                  [-51.66733579488655, -21.076711250815702],
                  [-51.66733579488655, -20.867693855608483]]], null, false),
            {
              "system:index": "0"
            })]),
    Silviculture = /* color: #d63000 */ee.FeatureCollection(
        [ee.Feature(
            ee.Geometry.Polygon(
                [[[-51.919489641815915, -21.070400386207087],
                  [-51.91914631906201, -21.07608680920586],
                  [-51.86970784249951, -21.075926631253044],
                  [-51.86884953561474, -21.062230778235893],
                  [-51.880780001312985, -21.055262228676774],
                  [-51.89142300668408, -21.049174493073686],
                  [-51.91408230844189, -21.06431326993577],
                  [-51.91365315499951, -21.065114220519593],
                  [-51.91459729257275, -21.065915166790838],
                  [-51.91528393808056, -21.065354504853783],
                  [-51.91837384286572, -21.06759713992241]]]),
            {
              "system:index": "0"
            }),
        ee.Feature(
            ee.Geometry.Polygon(
                [[[-51.89446721090192, -21.03403128224377],
                  [-51.89060482992048, -21.0283432524203],
                  [-51.88047680868024, -21.0342716167512],
                  [-51.883395052088446, -21.04003952862024],
                  [-51.86648640645856, -21.04997263103133],
                  [-51.862709856165594, -21.04404489157035],
                  [-51.86785969747419, -21.04060028591779],
                  [-51.874897813929266, -21.032028479606254],
                  [-51.885884142054266, -21.02113276177408],
                  [-51.89257893575544, -21.026580720248674],
                  [-51.893866396082586, -21.025859678353108],
                  [-51.899617052210516, -21.030506331598072]]]),
            {
              "system:index": "1"
            }),
        ee.Feature(
            ee.Geometry.Polygon(
                [[[-51.82752095358001, -21.001431265393105],
                  [-51.81516133443939, -21.009844581869093],
                  [-51.813702212735286, -21.0084824580534],
                  [-51.80958233968841, -21.011206693248024],
                  [-51.80168591634857, -21.001912039112916],
                  [-51.817993747159115, -20.989571690123878],
                  [-51.827692614956966, -21.000870360762605]]]),
            {
              "system:index": "2"
            }),
        ee.Feature(
            ee.Geometry.Polygon(
                [[[-51.91164435698424, -20.972607294147554],
                  [-51.909756081837756, -20.96723751303933],
                  [-51.908554452199084, -20.967558102399774],
                  [-51.90984191252623, -20.97308816065749],
                  [-51.90314711882506, -20.97429032016416],
                  [-51.90271796538268, -20.972687438673304],
                  [-51.9011730129901, -20.972607294147554],
                  [-51.89396323515807, -20.94279055042917],
                  [-51.90743865324889, -20.938541982407138],
                  [-51.91542090727721, -20.971805846526593]]]),
            {
              "system:index": "3"
            }),
        ee.Feature(
            ee.Geometry.Polygon(
                [[[-51.88027011563257, -20.933849466828253],
                  [-51.87168704678491, -20.933689136122553],
                  [-51.859670750398195, -20.93801800493194],
                  [-51.85795413662866, -20.935292435456148],
                  [-51.86636554409937, -20.925512042578937],
                  [-51.870657078523195, -20.928237790018102],
                  [-51.87271701504663, -20.923587955709245],
                  [-51.86756717373804, -20.914127502638163],
                  [-51.871172062654054, -20.9053078985724],
                  [-51.86979877163843, -20.897289626668368],
                  [-51.87271701504663, -20.892959581678944],
                  [-51.86722385098413, -20.88093102356683],
                  [-51.867395512361085, -20.87788363587991],
                  [-51.870657078523195, -20.878044026246894],
                  [-51.88679324795679, -20.919419016077246],
                  [-51.88679324795679, -20.931765154267616]]]),
            {
              "system:index": "4"
            })]);
            
            
var startDate = ee.Date.fromYMD(2020,1,15);
var endDate = ee.Date.fromYMD(2020,1,30);

var S2 = ee.ImageCollection("COPERNICUS/S2").filterDate(startDate,endDate).filterBounds(AOI)
var img = ee.Image(S2.median()).clip(AOI);

var viz = {min:0,max:3000,bands:"B4,B3,B2"};
Map.addLayer(img,viz,"True Color");

var evi = img.expression(
    '2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
      'NIR': img.select('B8').divide(10000),
      'RED': img.select('B4').divide(10000),
      'BLUE': img.select('B2').divide(10000)
}).rename('EVI');

var eviParams = {min: -0.2, max: 0.8, palette: ['red', 'yellow', 'green']};
Map.addLayer(evi, eviParams, 'EVI');

var ndvi = img.expression(
    '((NIR - RED) / (NIR + RED))', {
      'NIR': img.select('B8').divide(10000),
      'RED': img.select('B4').divide(10000)
}).rename('NDVI');

var ndviParams = {min: -0.2, max: 0.8, palette: ['red', 'yellow', 'green']};
Map.addLayer(ndvi, ndviParams, 'NDVI');

var ndvi_silv_list = ndvi.reduceRegion(ee.Reducer.toList(), Silviculture, 120);
var evi_silv_list = evi.reduceRegion(ee.Reducer.toList(), Silviculture, 120);

var y = ee.Array(evi_silv_list.get('EVI'));
var x = ee.Array(ndvi_silv_list.get('NDVI'));

var chart = ui.Chart.array.values(y, 0, x)
      .setOptions({
      title: 'NDVI vs. EVI',
      hAxis: {'title': 'NDVI'},
      vAxis: {'title': 'EVI'},
      pointSize: 1,
});

print(chart);

结果

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2025-01-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 简介
  • 函数
    • ui.Chart.array.values(array, axis, xLabels)
      • Arguments:
      • Returns: ui.Chart
  • 代码解释
  • 代码
  • 结果
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档