I have calculated NDWI on my study area. After this, I want to select a specific range of values that I will use to make a mask. My specific values range is between 0.2 and -0.1.

This is my code:

var sentinel = collezione.filterBounds(area)

var ndwi = sentinel.normalizedDifference(['B3','B8']);
var palette_NDWI = ['de0000','ff4000','ff7a20','ffc522','fffd30'];
var maschera = ndwi.lt(0.2).and(ndwi.gt(-0.1))
var filtro = sentinel.updateMask(maschera2)


I don't have my expected mask. What should I do? Is there some operator that can extract my range?


1 Answer 1


As you don't provide your study area, I arbitrarily assign one in my script. My Image Collection was 'COPERNICUS/S2_SR' (you don't provide one specific product; only the key word sentinel). So, my complete script looks as follows:

var area = ee.Geometry.Polygon([[[-108.647265625, 39.574670896812535],
          [-104.16484375, 41.247551055345276],
          [-104.340625, 43.58306796571101],
          [-107.32890625, 44.27931722642314],
          [-110.3171875, 42.36127474502225]]]);

var pt = ee.Geometry.Point ([-105.051019, 40.581871]);

var collezione = ee.ImageCollection('COPERNICUS/S2_SR')
  .filterBounds(pt) //it can also be used area instead
  .filterMetadata('MGRS_TILE', 'equals', '13TDF')

var sentinel = collezione;

Map.centerObject(pt, 18);


var ndwi = sentinel.normalizedDifference(['B3','B8']);


//var palette_NDWI = ['de0000','ff4000','ff7a20','ffc522','fffd30'];

var palette_NDWI = {"opacity":1,

var maschera = ndwi.lt(0.2).and(ndwi.gt(-0.1));
var filtro = maschera.updateMask(maschera).multiply(ndwi);


Map.addLayer(filtro, palette_NDWI);

By using your visualization palette, after running above script in GEE code editor, I got result of following image.

enter image description here

It looks as you are searching for a procedure for segregating some kind of buildings. I used Inspector Tab for getting some unmasked values and they are as expected.

  • sorry for my explanation but this is my first post on this platform; thanks for your support but on my layer i want to show all pixels EXCEPT pixels with values comprise between 0.2 and -0.1; so i want to do exactly the opposite of what is shown on your code; is it possible?
    – igha95
    Commented May 17, 2021 at 9:13

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.