-1

I am new to GEE and Javascript. I was looking for a solution to calculate the areas of NDVI values above 0.2 from the years 1989 and 2018, and quantify vegetation loss. Is this possible? I have pasted the codes below. https://code.earthengine.google.com/48b9e089abdb51354c45333c7ea8b0f2

var MMR = 
/* color: #d63000 */
/* displayProperties: [
  {
    "type": "rectangle"
  }
] */
ee.Geometry.Polygon(
    [[[112.21780240632957, 30.2114140665558],
      [112.21780240632957, 29.295784619630325],
      [113.23403775789207, 29.295784619630325],
      [113.23403775789207, 30.2114140665558]]], null, false);
  // Load 1989 and 2010 Landsat5 annual composites.
  var image1989 = ee.ImageCollection("LANDSAT/LT05/C01/T1").filterDate('1989-01-01','1989-12-31')
  .filterBounds(MMR)
  .median()
  .clip(MMR);

  var image2010 = ee.ImageCollection("LANDSAT/LT05/C01/T1").filterDate('2010-01-01','2010-12-31')
  .filterBounds(MMR)
  .median()
  .clip(MMR);

  // Compute NDVI the easy way.
  var ndvi1989 = image1989.normalizedDifference(['B4', 'B3']);
  var ndvi2010 = image2010.normalizedDifference(['B4', 'B3']);

  // Compute the multi-band difference image.
  var diff = ndvi1989.subtract(ndvi2010);

  var NDVI_Palette = '00FF00, FFFF00, 000000';
  Map.addLayer(ndvi1989.gte(0.2), {min: -0.3, max: 0.4, palette: NDVI_Palette}, "NDVI 1989");
  Map.addLayer(ndvi2010.gte(0.2), {min: -0.3, max: 0.4, palette: NDVI_Palette}, "NDVI 2010");
  Map.addLayer(diff, {min: -0.3, max: 0.4, palette: NDVI_Palette}, "Difference NDVI", false);
  Map.centerObject(MMR, 9);
Eva
  • 1
  • 2

1 Answers1

1

See my answer on gis.stackexchange, where you asked the same question.

var area_1989 = ndvi1989.gte(0.2).selfMask()
                            .multiply(ee.Image.pixelArea())
                            .reduceRegion({reducer:ee.Reducer.sum(),
                                          geometry:MMR,
                                          scale:30,
                                          maxPixels:1e9
                                          })

print('Area 1989:', area_1989.get('Area'))
hooge048
  • 224
  • 1
  • 4