归一化指数计算
主要功能
计算指定数据集指定两个波段的归一化指数
代码
// NormalizedDifference example.
//
// Compute Normalized Difference Vegetation Index over MOD09GA product.
// NDVI = (NIR - RED) / (NIR + RED), where
// RED is sur_refl_b01, 620-670nm
// NIR is sur_refl_b02, 841-876nm
// Load a MODIS image.
var img = ee.Image('MODIS/006/MOD09GA/2012_03_09');
// Use the normalizedDifference(A, B) to compute (A - B) / (A + B)
var ndvi = img.normalizedDifference(['sur_refl_b02', 'sur_refl_b01']);
// Make a palette: a list of hex strings.
var palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
'74A901', '66A000', '529400', '3E8601', '207401', '056201',
'004C00', '023B01', '012E01', '011D01', '011301'];
// Center the map
Map.setCenter(-94.84497, 39.01918, 8);
// Display the input image and the NDVI derived from it.
Map.addLayer(img.select(['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03']),
{gain: [0.1, 0.1, 0.1]}, 'MODIS bands 1/4/3');
Map.addLayer(ndvi, {min: 0, max: 1, palette: palette}, 'NDVI');
步骤分析
- 创建ee影像对象,通过影像数据集名称日期来筛选指定数据集特定日期的数据
- 计算影像两个波段的归一化指数
- 添加一个色板
- 地图对象设置显示中心,缩放等级
- 添加原始影像图层,设置显示参数
- 添加计算的归一化指数图层,设置显示参数
主要方法
- img.normalizedDifference()
Computes the normalized difference between two bands. If the bands to use are not specified, uses the first two bands. The normalized difference is computed as (first − second) / (first + second).
Arguments:
this:input (Image):
The input image.
bandNames (List, default: null):
A list of names specifying the bands to use. If not specified, the first and second bands are used.
Returns: Image
计算输入的两个波段的归一化指数,计算表达式为:b1-b2/b1+b1
- this,应该是一个影像对象
- 波段名称,默认为空
- 一个列表用于指定波段,如果没有指定输入波段,默认使用前两个波段
- 色板参数设置
['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
'74A901', '66A000', '529400', '3E8601', '207401', '056201',
'004C00', '023B01', '012E01', '011D01', '011301'];
CSS的颜色
Snipaste_2019-01-03_01-29-11.png