make.distmat: Make a distance matrix between all non-NA raster cells

View source: R/make.distmat.R

make.distmatR Documentation

Make a distance matrix between all non-NA raster cells

Description

This function produces a matrix of distances between all non-NA cells in a raster for use by fauxcurrence().

Usage

make.distmat(rast, dist_meth = "distRcpp", dist_fun = "Haversine")

Arguments

rast

A raster object.

dist_meth

A string indicating the distance method, either "distm", "distRcpp" or "costdist".

dist_fun

A string indicating the distance function if dist_meth is "distm" or "distRcpp". Must be either "Haversine" or "Vincenty" if dist_meth == "distRcpp", can be the name of any function which takes the same input and produces the same output as geosphere::distHaversine if dist_meth == "distm".

Details

If dist_meth is set to "distm", the geosphere::distm function is used to calculate distances between all non-NA cells of rast using the function specified by dist_fun, for example "distGeo", "distHaversine" or "distVincentyEllipsoid" from the geosphere package. If dist_meth is set to "distRcpp", distRcpp::dist_mtom is used. This is significantly faster than geosphere::distm, but only two distance functions can be used: "Haversine" or "Vincenty". If dist_meth is set to "costdist", relative cost-distance is calculated using the gdistance package. Rast is also used for cost-distance calculation. Therefore, if relative overland distance is desired, values in the study region (i.e. land) should all be set to the same positive value, but if an arbitrary cost-distance calculation is desired, they should be set to the appropriate travel cost.

Value

a matrix containing the distances between the centres of each non-NA cell of rast.

Examples

library(raster)
my.raster <- raster(system.file("external/test.grd", package="raster"))
my.raster[!is.na(my.raster)] <- 1
my.distmat.overland <- make.distmat(rast=my.raster,dist_meth="costdist")

ogosborne/fauxcurrence documentation built on April 15, 2022, 10:19 a.m.