View source: R/makeCatchment.R
makeCatchment | R Documentation |
A function to perform the necessary raster arithmetic to determine the
catchment of a location based on a movement cost function and an optional
weight.
getCosts
must have been run before this tool can be used.
makeCatchment(
rasters = tempdir(),
cost,
direction = "both",
ids = NULL,
name = NULL,
w = NULL
)
rasters |
One of either a character string or multilayer SpatRaster.
If character string, it represents the filepath
to the workspace used as |
cost |
A character with the desired pre-calculated
cost names (e.g. |
direction |
A character vector containing one or both of |
ids |
A character vector containing the IDs of the locations to consider
in the catchment calculation. Default is |
name |
A character string representing the |
w |
A named numreic vector with multiplicative weights for a given location. Names must correspond with ID strings. Missing locations are assumed to have a weight of 1. |
See also mwVoronoi
A SpatVector with catchment polygons
# Generate a DEM
n <- 5
dem <- expand.grid(list(x = 1:(n * 100),
y = 1:(n * 100))) / 100
dem <- as.data.table(dem)
dem[, z := 250 * exp(-(x - n/2)^2) +
250 * exp(-(y - n/2)^2)]
dem <- rast(dem)
ext(dem) <- c(10000, 20000, 30000, 40000)
crs(dem) <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"
# Export it so it doesn't just exist on the memory
dir <- tempdir()
writeRaster(dem, paste0(dir,"/DEM.tif"),overwrite=TRUE)
# Import raster, get the grid
dem <- rast(paste0(dir,"/DEM.tif"))
grid <- makeGrid(dem = dem, nx = n, ny = n, sources = TRUE)
# Import the data lying between x = (12000,16000) and y = (32000,36000)
region <- ext(c(12000,16000,32000,36000))
region <- as.polygons(region)
crs(region) <- crs(grid)
# Generate five random points that fall within the region
points <- data.table(ID = 1:5,
x = runif(5, ext(region)[1], ext(region)[2]),
y = runif(5, ext(region)[3], ext(region)[4]))
# Make a world but limit it to the DEM grid size
defineWorld(source = grid, cut_slope = 0.5,
res = res(dem), dir = dir, overwrite=TRUE)
# Calculate cost rasters
costRasters <- getCosts(region, from = points, dir = dir,
destination = 'all',
polygons = 'center',
costs = 'all', costFUN = energyCosts,
output = c('object','file'),
m = 70, v_max = 1.5, BMR = 76, k = 3.5, s = 0.05, l_s = 1,
L = 0.8)
# Calculate catchments for work
catchments <- makeCatchment(costRasters,
cost = 'dW_l')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.