Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
giswqs
GitHub Repository: giswqs/geemap
Path: blob/master/examples/javascripts/NormalizedDifference.js
2313 views
1
// NormalizedDifference example.
2
//
3
// Compute Normalized Difference Vegetation Index over MOD09GA product.
4
// NDVI = (NIR - RED) / (NIR + RED), where
5
// RED is sur_refl_b01, 620-670nm
6
// NIR is sur_refl_b02, 841-876nm
7
8
// Load a MODIS image.
9
var img = ee.Image('MODIS/006/MOD09GA/2012_03_09');
10
11
// Use the normalizedDifference(A, B) to compute (A - B) / (A + B)
12
var ndvi = img.normalizedDifference(['sur_refl_b02', 'sur_refl_b01']);
13
14
// Make a palette: a list of hex strings.
15
var palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718',
16
'74A901', '66A000', '529400', '3E8601', '207401', '056201',
17
'004C00', '023B01', '012E01', '011D01', '011301'];
18
19
// Center the map
20
Map.setCenter(-94.84497, 39.01918, 8);
21
22
// Display the input image and the NDVI derived from it.
23
Map.addLayer(img.select(['sur_refl_b01', 'sur_refl_b04', 'sur_refl_b03']),
24
{gain: [0.1, 0.1, 0.1]}, 'MODIS bands 1/4/3');
25
Map.addLayer(ndvi, {min: 0, max: 1, palette: palette}, 'NDVI');
26
27