# Calculating statistical values from set of point values in Google Earth Engine

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');

//DERIVING THE SPECTRAL INDICES (OPTIONAL: TO INCREASE THE ACCURACY)
var ndviL = input.normalizedDifference(['SR_B4', 'SR_B3']).rename('ndviL');
}

var mndwiL = input.normalizedDifference(['SR_B2', 'SR_B5']).rename('mndwiL');
}

var ndsiL = input.normalizedDifference(['SR_B2', 'SR_B5']).rename('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) {
}

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();

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

var N = green.subtract(swir);
var MNDWI = N.divide(D);

//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?

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