I am writing a code that calculates the number of burned patches in a study area. The process is based on iterating over a list of numbers.

Code: Link

var country = ['ZA'];
var geometry = ee.FeatureCollection('USDOS/LSIB/2013')
                      .filter(ee.Filter.inList('cc', country));
Map.centerObject(geometry, 5);

var modisFire = ee.ImageCollection('MODIS/006/MCD64A1')
                  .map(function(image) { return image.clip(geometry);})
                  .filter(ee.Filter.date('2017-06-01', '2017-08-01'))

var myList = ee.List.sequence(2, 50, 5);

var computeNumPatches = myList.map(function (number){
  var image = ee.Image(modisFire.toList(2).get(0)).int16();
  var patches = image.connectedPixelCount(number, true);
  patches = patches.updateMask(patches.gte(number));
  var numPatches = patches.reduceRegion({
    reducer: ee.Reducer.count(),
    geometry: geometry,
    crs: 'EPSG:4326',
    scale: 500});
  return numPatches;


Error Message

List (Error)
Image.gte, argument 'image2': Invalid type. Expected type: Image<unknown bands>. Actual type: Float. Actual value: 2.0 

When mapping over a list, you have to cast the element to the correct type before using it:

myList.map(function (number) {
  number = ee.Number(number)


  • Thanks a lot! I
    – farhat
    Apr 21 '20 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.