0

I have a function that performs an operation over a specific ROI. Now, I want to apply the same function over a collection of ROIs by mapping the function over a feature collection. Haven't found any feasible solution anywhere.

Here's what I am trying:

var myfunc = function(feature) {
  var geometry = feature.geometry();

  var L7 = ee.ImageCollection("LANDSAT/LE07/C01/T1_TOA")
      .filterDate('2009-10-01','2010-12-01')
      .filterBounds(geometry)

  var Convert_scale = function(img) {
    var I = ee.Image(img)
    var correct_scale = I.select(['B1','B2','B3','B4','B5','B7']).multiply(0.0001)
    return I.addBands(correct_scale,['B1','B2','B3','B4','B5','B7'],true)
  }

  L7 = L7.map(Convert_scale)

   return L7;
}

var fc = ee.FeatureCollection("users/climateClass/strips_bross_allin");
var L7coll = ee.ImageCollection(fc.map(myfunc))
print(L7coll) //.first())
Map.addLayer((L7coll).mosaic())

The resulting image collection has zero bands and adding first image to map gives a Layer error

Here's my code.

2

Your reason L7coll fails to display on the map is that it's an ee.FeatureCollection where each feature is an ee.ImageCollection. I'm guessing you wanted an ee.ImageCollection with images. myfunc() probably should return an ee.Image instead of an ee.ImageCollection.

var myfunc = function(feature) {
  var geometry = feature.geometry();

  var L7 = ee.ImageCollection("LANDSAT/LE07/C01/T1_TOA")
      .filterDate('2009-10-01','2010-12-01')
      .filterBounds(geometry)

  var Convert_scale = function(img) {
    var I = ee.Image(img)
    var correct_scale = I.select(['B1','B2','B3','B4','B5','B7']).multiply(0.0001)
    return I.addBands(correct_scale,['B1','B2','B3','B4','B5','B7'],true)
  }

  L7 = L7.map(Convert_scale)

   return L7.median(); // Turn your collection into an image in one way or another
}

var fc = ee.FeatureCollection("users/climateClass/strips_bross_allin");
var L7coll = ee.ImageCollection(fc.map(myfunc))
print(L7coll) //.first())
Map.addLayer(L7coll.mosaic(), {bands: 'B3,B2,B1', min: 0, max: 0.00003, gamma: 1.5})
Map.centerObject(fc)

https://code.earthengine.google.com/806525d0a4a96ae06599aa624cb2b716

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.