I calculated NDSI and NDWI, NDWI disguises my water. I need to calculate the area of ​​snow, but I think that he considers all the snow and is masked. So I need to subtract (SNOW-WATER). And then already calculate the area of ​​only snow. How do I calculate snow from water?

var collection = ee.ImageCollection('COPERNICUS/S2') 
  .filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", 10)) 
  .filterBounds(geometry) ;

print(collection) ;

//Let's centre the map view over our ROI
Map.centerObject(geometry, 13);
var medianpixels = collection.median(); // This finds the median value of all the pixels which meet the criteria. 

var medianpixelsclipped = medianpixels.clip(geometry).divide(10000);
// Now visualise the mosaic as a natural colour image. 
Map.addLayer(medianpixelsclipped, {bands: ['B4', 'B3', 'B2'], min: 0, max: 1, gamma: 1.5}, 'Sentinel_2 mosaic',false);

// User specified parameters

// setup Visualization
var viz = {min:-0.50, max:0.75, palette:['red', 'green', 'orange', 'white']};

// Data
// calculate ndsi
var ndsi = medianpixelsclipped.normalizedDifference(['B3', 'B11']).rename('NDSI');
var scale=30;
Map.addLayer(ndsi, {min:0.4, max:1, palette:['EB984E ','FDFEFE  '] },'NDSI') ;
// Create an NDWI image, define visualization parameters and display.
var ndwi = medianpixelsclipped.normalizedDifference(['B3', 'B8']).rename ('NDWI');
var ndwiViz = {min: 0.2, max: 1, palette: ['0000ff','ffa500']};
Map.addLayer(ndwi, ndwiViz, 'NDWI', false);
var ndwiMasked = ndwi.updateMask (ndwi.gte (0.2)).rename ('NDWI masked');
Map.addLayer (ndwiMasked, ndwiViz, 'NDWI masked');

var evi =  medianpixelsclipped.expression(
    '( water-snow)', {
      'snow': ndsi.select('NDSI'),
      'water':  ndwi.select('NDWI'),


Map.centerObject(geometry, 9);
Map.addLayer(evi, {min: -1, max: 1, palette: ['FF0000','00FF00']});

var reducer = ndsi.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: geometry,
scale: 30,
maxPixels: 1E13
// km square
var area = ee.Number(reducer.get('NDSI')).multiply(scale).multiply(scale).divide(1000000);
print('area of ndsi ', area.getInfo() + ' km2');
  • Your question may need some clarification - try to simplify it. Also, separate your code into sections where you are confident about the analysis and not - use some distinctive demarcation. – Justin Braaten May 29 '20 at 23:40

Your Answer

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

Browse other questions tagged or ask your own question.