GEE案例

GEE使用表达式完成波段运算

2019-01-03  本文已影响0人  赤豆冰棍

增强植被指数计算

主要功能

对特定影像使用自定义表达式计算增强植被指数

代码

// Compute Enhanced Vegetation Index (EVI) over the MODIS MOD09GA product
// using an expression.

// Load a MODIS image and apply the scaling factor.
var img = ee.Image('MODIS/006/MOD09GA/2012_03_09').multiply(0.0001);

// Compute EVI using an expression.  The second argument is a map from
// variable name to band name in the input image.
var evi = img.expression(
    '2.5 * (nir - red) / (nir + 6 * red - 7.5 * blue + 1)',
    {
        red: img.select('sur_refl_b01'),    // 620-670nm, RED
        nir: img.select('sur_refl_b02'),    // 841-876nm, NIR
        blue: img.select('sur_refl_b03')    // 459-479nm, BLUE
    });

// Center the map.
Map.setCenter(-94.84497, 39.01918, 8);

// Display the input image and the EVI computed from it.
Map.addLayer(img.select(['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03']),
         {min: 0, max: 0.2}, 'MODIS bands 1/4/3');
Map.addLayer(evi, {min: 0, max: 1}, 'EVI');

步骤分析

  1. 创建ee影像对象,之后通过multiply()来额外乘以一个系数
  2. 计算影像三个波段的增强植被指数EVI
  3. 地图对象设置显示中心,缩放等级
  4. 添加原始影像图层,设置显示参数
  5. 添加计算的增强植被指数图层,设置显示参数

主要方法

  1. ee.Image.multiply()
    Multiplies the first value by the second for each matched pair of bands in image1 and image2. If either image1 or image2 has only 1 band, then it is used against all the bands in the other image. If the images have the same number of bands, but not the same names, they're used pairwise in the natural order. The output bands are named for the longer of the two inputs, or if they're equal in length, in image1's order. The type of the output pixels is the union of the input types.
    Arguments:
    this:image1 (Image):
    The image from which the left operand bands are taken.
    image2 (Image):
    The image from which the right operand bands are taken.
    Returns: Image

完成第一个对象与输入参数的乘法,如果两个影像都只有一个波段,则都执行乘法,若有相同波段数量,但是波段名称不同,则按照波段顺序依次相乘。输出波段按照输入波段名称长的来命名,按照影像1的顺序。

  1. 增强植被指数计算

实现影像按照自定义的数学表达式波段运算功能,也可使用额外影像。使用b()来表示输入的影像,b(0),或者b(波段名称)来指定波段,必须在运行时指定,也可以使用image.波段名,image[0]来指定。二者都可以使用多参数来实现指定多个波段,b()表示所有波段。
本例中的表达式是2.5(nir-red)/(nir+6red -7.5*blue+1),红,绿,蓝波段在该MODIS数据中分别是1,2,3波段。

从一个影像中选择指定波段。输入一个影像对象,选择波段顺序或者波段名称。也可以指定别名。

上一篇 下一篇

猜你喜欢

热点阅读