0

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 muss 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?

2

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, privacy policy and cookie policy

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