Paired matrix of cell centroid distances in raster grid in R

I want to get a paired matrix of distances between the centroids of each cell with every other cell in the raster layer. Also, I'm trying to figure out how to get a paired matrix of differences between values ​​within a raster layer.

I tried looking at the {gdistance} and {spartstat} packages, but it doesn't seem like there is a function for that.

Here's an example:

df <- data.frame(x = rnorm(100, 5, 3), y = rnorm(100, 10, 6))

rast <- raster()
ncol <- 20
nrow <- 20
test <- rasterize(df, rast, FUN=mean)
plot(test, xlim=c(min(df$x), max(df$x)), ylim=c(min(df$y), max(df$x)))

      

Any ideas?

+3


source to share





All Articles