1

The GEE tutorial shows how to mask an image for one pixel value using .eq(pixel value).

However, I want to mask all pixels in an image with a value of 15 or less in this dataset

var riverflow = ee.Image('WWF/HydroSHEDS/15ACC');

var flowAccumulation = riverflow.select('b1');

And now I need to use .updateMask. This must be very straightforward right?

1 Answer 1

2

If you want to keep pixels that have a value of 15 or less than 15 and mask the rest of the pixels:

var riverflow = ee.Image('WWF/HydroSHEDS/15ACC');

var flowAccumulation = riverflow.select('b1');
//Map.addLayer(flowAccumulation)

var masked = flowAccumulation.updateMask(flowAccumulation.lte(15)); 
//Map.addLayer(masked)

On the other hand, If you want to mask the pixels that have a value of 15 or less than 15 and keep the rest of the pixels:

var riverflow = ee.Image('WWF/HydroSHEDS/15ACC');

var flowAccumulation = riverflow.select('b1');
//Map.addLayer(flowAccumulation)

var masked = flowAccumulation.updateMask(flowAccumulation.gte(15)); 
//Map.addLayer(masked)

Hope it helps.

2
  • Just tried this, unfortunately it does the exact opposite. But I did some research and using .gt instead of .lt worked! Not sure what they stand for...
    – Olivier
    Commented Jun 1, 2020 at 14:22
  • 1
    "gt" stands for greater than, while "lte" stands for less than equal. In the question you mentioned "mask all pixels in an image with a value of 15 or less". Although the question is different from what you want, I edited the answer.
    – HamiEbra
    Commented Jun 2, 2020 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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