Google Earth Engine – Showing Only One Type of Land Usage in Map

google-earth-enginegoogle-earth-engine-javascript-api

I am trying to make a simple visualization in Google Earth Engine. The goal is just to filter the mangroves in the ESA WorldCover 10m v100 map.

According to the documentation there is a band called 'Map' and a 'Class Table' with numerical values corresponding to landcover. In my particular case mangroves have the value 95.

I tried the following:

var dataset = ee.ImageCollection("ESA/WorldCover/v100")
                
var visualization = {
  bands: ['Map'],
}; 

dataset = dataset.first()
                 .select('Map')
                 .eq(95)

Fine, it works, but I get a B&W layer with mangroves in white. The desired output woulld be a map (the default map) showing only the mangroves. In short: a visualization filter not a binary mask.

Best Answer

By applying .eq(95) you, as suggested, create a binary image. To avoid you have to apply a mask(). See the difference:

Map.addLayer(dataset.eq(95).clip(geometry), {}, 'binary')
Map.addLayer(dataset.mask(dataset.eq(95)).clip(geometry), {}, 'mask')   

     

https://code.earthengine.google.com/9b6a8c5086d0ac87ac5ef18092bd8971