I am now using Google Earth Engine to process the Landsat 8 images. Now I have calculated NDVI, EVI, mNDWI and generated some maps. I am now want to generate a function based on those indices values, output binary numbers (0 or 1) and layout binary image. But I get stuck, and I hope anybody could help me. I want to justify the water body, there's a formula:

water = 1 EVI < 0.1 and (mNDWI > EVI or mNDWI > NDVI)

water = 0 For other cases

The GEE guideline says the traditional if statement is not recommended and yes I tried it doesn't work, I used the way they suggested:

var water = ee.Algorithms.If(evi < 0.1 && (mndvi>evi || mndwi > ndvi), 1, 0);
var waterViz = {min: 0, max: 1, palette: ['00FFFF', '0000FF']};
Map.addLayer(water, waterViz, 'water', false);

And it says:"Cannot add an object of type ComputedObject to the map."

I have seen a similar question here, but that user used ArcGIS. I am new to JavaScript.


Try using image operator, like:

water = evi.lt(0.1).and(mndvi.gt(evi).or(mndvi.gt(ndvi)))

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.