morrowcj/remotePARTS

distm_FUN for projections like UTM.

SeltaZheng opened this issue · 3 comments

My rasters are in UTM projection and the distance is Euclidean. I used rater::pointDistance to calculate it.
I tried to use pointDistance for fitcor() but failed.
Any suggestions on distance functions that will work for UTM?

Thank you.

remotePARTS cannot handle rasters natively. you need to convert it into a flat format (e.g., a matrix).

Euclidean distances, or any other distances, can be used, with the "distm_FUN" argument, by simply passing a function that conforms to the following rules: 1) the first argument is a 2-column matrix of coordinates and 2) it returns a distance matrix. So for example the following function would work

euc_dist <- function(coords){
    as.matrix(stats::dist(coords))
}

And you could then pass it to fitCor either by reference:

fitCor(AR.map$residuals, coords, covar_FUN = "covar_exp", start = list(range = .1), distm_FUN = "euc_dist")

or inline:

fitCor(AR.map$residuals, coords, covar_FUN = "covar_exp", start = list(range = .1), distm_FUN = function(x){as.matrix(dist(x))})

Got it! Thanks for helping 👍

Of course, @SeltaZheng. Feel free to reach out for any else you need.