I have calculated MNDWI index. I have a set of sample points (collected over the waterbodies in Google Earth Engine platform itself) which I have used to extract the MNDWI values. Now I want to calculate the max, min , mean, and standard deviation of these set of sample values. I have proceeded this far. And now I'm stuck.

var IHR = ee.FeatureCollection('projects/nmsheiari223/assets/Uttarakhand');

function addndviL(input) {
  var ndviL = input.normalizedDifference(['SR_B4', 'SR_B3']).rename('ndviL');
  return input.addBands(ndviL);

function addmndwiL(input) {
  var mndwiL = input.normalizedDifference(['SR_B2', 'SR_B5']).rename('mndwiL');
  return input.addBands(mndwiL);

function addndsiL(input) {
  var ndsiL = input.normalizedDifference(['SR_B2', 'SR_B5']).rename('ndsiL');
  return input.addBands(ndsiL);

var dataset = ee.ImageCollection('LANDSAT/LE07/C02/T1_L2')
    .filterDate('2000-10-01', '2000-11-30')
    .map(function(image){return image.clip(IHR)})

// Applies scaling factors.
function applyScaleFactors(image) {
  var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
  var thermalBand = image.select('ST_B6').multiply(0.00341802).add(149.0);
  return image.addBands(opticalBands, null, true)
              .addBands(thermalBand, null, true);

dataset = dataset.map(applyScaleFactors);

var visualization = {
  bands: ['SR_B4', 'SR_B3', 'SR_B2'],
  min: 0.0,
  max: 0.3,

Map.centerObject(IHR, 8);

var collectionL = dataset.median();
Map.addLayer(collectionL, visualization, 'RGBL (432)');

var green = collectionL.select('SR_B2');
var swir = collectionL.select('SR_B5');

var N = green.subtract(swir);
var D = green.add(swir);
var MNDWI = N.divide(D);
Map.addLayer(MNDWI, {}, 'MNDWI');

//Extracting values
var sampled_points = MNDWI.sampleRegions({
  collection: geometry,
  scale: 30,
  geometries: true

The 'geometry' in the above code represents my collected samples over waterbodies. I tried the ee.Reducer.max() this way shown below:

var maxReducer = ee.Reducer.max();
var theMax = sampled_points.reduceRegion(maxReducer, geometry);
print(theMax, 'Max');

But this of course didn't work. What am I missing?

1 Answer 1


If I understand correctly, you want aggregate stats (min max mean std) of MNDWI over your sample points?.

In this case you can use aggregate_stats over your samples Fc:

var stats = sampled_points.aggregate_stats('MNDWI');

assuming the property column generated by GEE by the sampling function is called 'MNDWI', although worth double checking it.

  • Thanks! But how do I check the property column? Commented Jul 6, 2023 at 3:39
  • Note: I tried exporting the values in csv format to know the column property (though this is not the way I'm looking for). But surprisingly, the property name is taken as 'SR_B2'. Now I'm confused, whether in the exported file, the extracted values are representing the Band2 values, or actually the calculated MNDWI values. If the former is true, why it is taking that particular band's values? And, if the later one is true, why the column property is selected as 'SR_B2'? What am I missing here? Commented Jul 6, 2023 at 4:40
  • By looking at your code, you provided the green band first when calculating the mndwi as a variable, so it takes the band name.However, you have calculated mndwi beforehand for the entire collection, so you performed the calculation for every image in the dataset and never used it. Commented Jul 6, 2023 at 15:38
  • Yes, thanks! Got it! Commented Jul 7, 2023 at 4:11

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.