1

I want to filter a raster in GEE with multiple values. I input a list of values and map over the function to apply the filter. Here is the GEE code to loop over a list of numbers and filter the raster (DEM) for values equal to the numbers in the list.

var aec = function(n){
  var ii = ee.Image(n)    // casting the number to image before filtering but didn't work
  var DEM141 = DEM.eq(ii)

  var DEM141Count = DEM141.reduceRegion({
    geometry: ROI,
    scale: 30,
    reducer: ee.Reducer.sum()
  })
  return DEM141Count
}

var elevs = ee.List.sequence(100,150,1);
var areas = elevs.map(aec)
print(areas)

I keep getting this error: Image.lte, argument 'image2': Invalid type. Expected: Image<unknown bands>. Actual: Float.

The GEE code link is: https://code.earthengine.google.com/6e55360bc82695f930d64ee70a415dc0

1 Answer 1

2

The trick is to define n as a imageConstant with a projection:

Map.addLayer(DEM, {min: 100, max: 300}, 'DEM')

var ElevHist = ui.Chart.image.histogram({
  region: ROI,
  image: DEM,
  scale: 30,

})

print(ElevHist)

print(DEM.projection())

// var lte = ee.Image(DEM).lte(ii)

var aec = function(n){
  var ii = ee.Image.constant(n)//.reproject(DEM.projection())
  var DEM141 = ee.Image(DEM).lte(ii)

  var DEM141Count = ee.Number(DEM141.reduceRegion({
    geometry: ROI,
    scale: 30,
    reducer: ee.Reducer.sum()
  }).values().get(0))
  return DEM141Count
}

// print(DEM141Count.get('elevation'))

var elevs = ee.List.sequence(140,150,1);
var areas = elevs.map(aec)
print(areas)

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.