0

The below code computes area elevation relationship by iteration algorithm. But when the interval sets to 0.5 shows same area values in a row(like the below picture).

enter image description here

code link: https://code.earthengine.google.com/d6fea46bec579534464dc7e9d58e4290

Map.centerObject(geometry);
 

var dem = ee.Image("JAXA/ALOS/AW3D30/V2_2").clip(geometry).select('AVE_DSM');


Map.addLayer(dem,[],'DEM',false);


var demMin = ee.Number(dem.reduceRegion(ee.Reducer.min(), geometry, 250).get('AVE_DSM')).float();
var demMax = ee.Number(dem.reduceRegion(ee.Reducer.mean(), geometry, 250).get('AVE_DSM')).float();


print('minElevation:',demMin);
print('maxElevation:',demMax);


//////////////////////////////// area elevation 

var interval = ee.Number(0.5);

var waterlevel = ee.List.sequence(demMin,demMax,interval);



var calcArea = function(level,list){
   
  var inundated = dem.lte(ee.Number(level));
   
  var area = inundated.multiply(30.0).multiply(30.0);
  var totalarea = area.reduceRegion(ee.Reducer.sum(), geometry);
   

  return ee.List(list).add(totalarea.get('AVE_DSM'));
 };

var first = ee.List([]);
 
var AREA = ee.List(waterlevel.iterate(calcArea, first));

print('Area Estimated:',AREA)

1 Answer 1

0

But when the interval sets to 0.5 shows same area values in a row(like the below picture).

The bands have integer values: if you print(dem.bandTypes()); then you can see the type reported as AVE_DSM: signed int16. Therefore, any step smaller than 1.0 will sometimes not differ from the previous step. There simply isn't any more resolution in the data.


You didn't ask about performance, but a note: in general, iterate is not very efficient, and should be avoided whenever possible. In this case, there is no need at all to use iterate because each value computed does not depend on the previous value(s); map suffices. Here is your code modified to use map:

var calcArea = function(level) {
  var inundated = dem.lte(ee.Number(level));
  var area = inundated.multiply(30.0).multiply(30.0);
  var totalarea = area.reduceRegion(ee.Reducer.sum(), geometry);
  return totalarea.get('AVE_DSM');
};
var AREA = waterlevel.map(calcArea);
1
  • You mean there is no way to solve the same areas for intervals with less than 1 value? Commented Nov 28, 2020 at 19:30

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.