google-earth-engine – Extracting Min and Max Values of All Bands in Google Earth Engine

extractgoogle-earth-enginegoogle-earth-engine-javascript-api

I want to extract minimum and maximum values for all the bands in an image here is my code:

https://code.earthengine.google.com/8edcbe3386ba6e639dec363e3af0eb38

Map.setOptions('HYBRID');

//Get elevation data
var elevation = ee.Image("USGS/SRTMGL1_003").clip(roi)

//compute slope and aspect
var slope = ee.Terrain.slope(elevation);
var aspect = ee.Terrain.aspect(elevation);

var dataset= elevation
.addBands(slope.float().rename('slope'))
.addBands(aspect.float().rename('aspect'))

//Extract values of bands
var bands = dataset.bandNames()
var value = dataset.reduceRegions(pts, ee.Reducer.first(),1000);

//Print/get min and max values
var stat = value.aggregate_stats('aspect');

print(stat.get('min'),'min')
print(stat.get('max'),'max')

How would it be possible to get each band's min and max values together?

I have to compute stats for each band separately otherwise.

Best Answer

You can use reduceRegion() method on your image with reducer as ee.Reducer.minMax()

var minMax = dataset.reduceRegion({
    reducer: ee.Reducer.minMax(),
    geometry: roi,
    scale: 30,
    maxPixels: 1e10
})

print('Min & Max all bands: ', minMax)
Related Question