Julia 的multiple dispatch 是一个强大的特性,它允许用户定义多个同名但根据类型具有不同功能的函数。在我们之前计算 NDVI 的示例的基础上,我们将在这里定义额外的函数,称为ndvi
在工作流中对不同类型执行计算:
# define an ndvi function to calculate for EE.FeatureCollection
function ndvi(fc::EE.FeatureCollection)
# map the ndvi-feature function over the fc
return map(fc,ndvi)
end
# define ndvi function to calculate from two Numbers
function ndvi(nir::EE.Number,red::EE.Number)
# compute ndvi from numbers
return divide(subtract(nir,red),add(nir,red))
end