make.distmat | R Documentation |
This function produces a matrix of distances between all non-NA cells in a raster for use by fauxcurrence().
make.distmat(rast, dist_meth = "distRcpp", dist_fun = "Haversine")
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". |
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.
a matrix containing the distances between the centres of each non-NA cell of rast.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.