mat_cost_dist {graph4lg} | R Documentation |
Compute cost distances between points on a raster
Description
The function computes cost-distances associated to least cost paths between point pairs on a raster with specified cost values.
Usage
mat_cost_dist(
raster,
pts,
cost,
method = "gdistance",
return = "mat",
direction = 8,
parallel.java = 1,
alloc_ram = NULL
)
Arguments
raster |
A parameter indicating the raster file on which cost distances are computed. It can be:
All the raster cell values must be present in the column 'code' from
|
pts |
A parameter indicating the points between which cost distances are computed. It can be either:
The point coordinates must be in the same spatial coordinate reference system as the raster file. |
cost |
A
|
method |
A character string indicating the method used to compute the cost distances. It must be:
|
return |
A character string indicating whether the returned object is a
|
direction |
An integer (4, 8, 16) indicating the directions in which
movement can take place from a cell. Only used when |
parallel.java |
An integer indicating how many computer cores are used
to run the .jar file. By default, |
alloc_ram |
(optional, default = NULL) Integer or numeric value indicating RAM gigabytes allocated to the java process when used. Increasing this value can speed up the computations. Too large values may not be compatible with your machine settings. |
Value
The function returns:
If
return="mat"
, a pairwisematrix
with cost-distance values between points.If
return="df"
, an object of typedata.frame
with three columns:from: A character string indicating the ID of the point of origin.
to: A character string indicating the ID of the point of destination.
cost_dist: A numeric indicating the accumulated cost-distance along the least-cost path between point ID1 and point ID2.
Author(s)
P. Savary
Examples
## Not run:
x <- raster::raster(ncol=10, nrow=10, xmn=0, xmx=100, ymn=0, ymx=100)
raster::values(x) <- sample(c(1,2,3,4), size = 100, replace = TRUE)
pts <- data.frame(ID = 1:4,
x = c(10, 90, 10, 90),
y = c(90, 10, 10, 90))
cost <- data.frame(code = 1:4,
cost = c(1, 10, 100, 1000))
mat_cost_dist(raster = x,
pts = pts, cost = cost,
method = "gdistance")
## End(Not run)