9

I have an Image Collection, I want to Calculate a Normalized difference and got this Function called ND

/////normalized Differense///////
function ND(Im,B1,B2){
var four = Im.select(B1)
var eight = Im.select(B2)
return eight.subtract(four).divide(four.add(eight)).copyProperties(Im);
}

this way I would call ND but miss the additional Arguments :

ImageCollection.map(ND)

this way I would get an error regarding the second argument of .map:

ImageCollection.map(ND,'B4','B8')

this way I will get "a is not a function":

ImageCollection.map((ND,'B4','B8'),)
ImageCollection.map([ND,'B4','B8'],)

I know there is a ".NormalizedDifference" Function, and I will use it. It's more of a general question how do I map over an ImageCollection with a function that needs multiple inputs?

1 Answer 1

18

You can make a nested function.

/////normalized Differense///////
var ND = function(B1,B2) {
  var wrap = function(Im) {
    var four = Im.select(B1)
    var eight = Im.select(B2)
    return eight.subtract(four).divide(four.add(eight)).copyProperties(Im);
  }
  return wrap
}

And to call it:

ImageCollection.map(ND('B4','B8'))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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