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');
步骤分析
- 创建ee影像对象,之后通过multiply()来额外乘以一个系数
- 计算影像三个波段的增强植被指数EVI
- 地图对象设置显示中心,缩放等级
- 添加原始影像图层,设置显示参数
- 添加计算的增强植被指数图层,设置显示参数
主要方法
- 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的顺序。
- this,影像1,一个影像对象
- 影像2,用作系数的影像
- 增强植被指数计算
- 自定义表达式
img.expression()
Evaluates an arithmetic expression on an image, possibly involving additional images.
The bands of the primary input image are available using the built-in function b(), as b(0) or b('band_name').
Variables in the expression are interpreted as additional image parameters which must be supplied in opt_map. The bands of each such image can be accessed like image.band_name or image[0].
Both b() and image[] allow multiple arguments, to specify multiple bands, such as b(1, 'name', 3). Calling b() with no arguments, or using a variable by itself, returns all bands of the image.
Returns the image computed by the provided expression.
Arguments:
this:image (Image):
The Image instance.
expression (String):
The expression to evaluate.
map (Dictionary<Image>, optional):
A map of input images available by name.
Returns: Image
实现影像按照自定义的数学表达式波段运算功能,也可使用额外影像。使用b()来表示输入的影像,b(0),或者b(波段名称)来指定波段,必须在运行时指定,也可以使用image.波段名,image[0]来指定。二者都可以使用多参数来实现指定多个波段,b()表示所有波段。
本例中的表达式是2.5(nir-red)/(nir+6red -7.5*blue+1),红,绿,蓝波段在该MODIS数据中分别是1,2,3波段。
- 波段选择
img.select()
Selects bands from an image.
Returns an image with the selected bands.
Arguments:
this:image (Image):
The Image instance.
var_args (VarArgs<Object>):
One of two possibilities:
Any number of non-list arguments. All of these will be interpreted as band selectors. These can be band names, regexes, or numeric indices. E.g. selected = image.select('a', 'b', 3, 'd');
Two lists. The first will be used as band selectors and the second as new names for the selected bands. The number of new names must match the number of selected bands. E.g. selected = image.select(['a', 4], ['newA', 'newB']);
Returns: Image
从一个影像中选择指定波段。输入一个影像对象,选择波段顺序或者波段名称。也可以指定别名。