-2

I want to write an equation for fractional vegetation in Google Earth Engine using NDVI.

My code is;

var ndviClip = ndvi.clip(table);
Map.addLayer(ndviClip, {min: -1, max: 1, palette: ['FF0000', '00FF00']});
print(ndviClip);

var min = ndviClip.reduceRegion({
  reducer: ee.Reducer.min(),
  geometry: box,
  scale: 30,
  maxPixels: 1e9
});

var max = ndviClip.reduceRegion({
  reducer: ee.Reducer.max(),
  geometry: box,
  scale: 30,
  maxPixels: 1e9
});


var fv=ndviClip.subtract(min).(divide(max.subtract(min))); 

//min and max are ndviClip image min max values

It gives an error for the final line.

How I can write an equation in Google Earth Engine for this kind of situation?

1
  • 1
    Welcome to GIS SE! We're a little different from other sites; this isn't a discussion forum but a Q&A site. Please check out our short tour to learn about our focussed Q&A format. What is the precise wording of the error?
    – PolyGeo
    Dec 13, 2018 at 22:58

2 Answers 2

1

Without being able to access your image, I guess this should work for your equation:

var min = ee.Number(ndviClip.reduceRegion({
  reducer: ee.Reducer.min(),
  geometry: box,
  scale: 30,
  maxPixels: 1e9
}).values().get(0));

print(min)

var max = ee.Number(ndviClip.reduceRegion({
  reducer: ee.Reducer.max(),
  geometry: box,
  scale: 30,
  maxPixels: 1e9
}).values().get(0));

print(max)

var fv = ndviClip.subtract(min).divide(max.subtract(min)); 
print(fv)
0
1

If your ndviClip is an ImageCollection, can calculate FVC like this:

var calculateFVC = function(image) {
  var fvc = image.expression(
    '(NDVI - NDVI_min) / (NDVI_max - NDVI_min)',
    {
      'NDVI': image.select('NDVI'),
      'NDVI_min': 0.1, // Minimum NDVI threshold
      'NDVI_max': 0.8  // Maximum NDVI threshold
    }
  ).rename('FVC');
  return image.addBands(fvc);
};

Than add the fvc bands to the ImageCollection

var ndviClip = ndviClip.map(calculateFVC)

Not the answer you're looking for? Browse other questions tagged or ask your own question.