-1

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
    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 '18 at 22:58
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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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