rij_matrix {prioritizr} | R Documentation |
Feature by planning unit matrix
Description
Generate a matrix showing the amount of each feature in each planning unit (also known as an rij matrix).
Usage
rij_matrix(x, y, ...)
## S4 method for signature 'Raster,Raster'
rij_matrix(x, y, ...)
## S4 method for signature 'SpatRaster,SpatRaster'
rij_matrix(x, y, memory, ...)
## S4 method for signature 'Spatial,Raster'
rij_matrix(x, y, fun, ...)
## S4 method for signature 'sf,Raster'
rij_matrix(x, y, fun, ...)
## S4 method for signature 'sf,SpatRaster'
rij_matrix(x, y, fun, ...)
Arguments
x |
|
y |
|
... |
not used. |
memory |
|
fun |
|
Details
Generally, processing sf::st_sf()
data takes much longer to process than
terra::rast()
data.
As such, it is recommended to use terra::rast()
data for planning units
where possible.
The performance of this function for large terra::rast()
datasets
can be improved by increasing the GDAL cache size.
The default cache size is 25 MB.
For example, the following code can be used to set the cache size to 4 GB.
terra::gdalCache(size = 4000)
Value
A dgCMatrix
sparse matrix object.
The sparse matrix represents the spatial intersection between the
planning units and the features. Rows correspond to features,
and columns correspond to planning units. Values correspond to the amount
(or presence/absence) of the feature in the planning unit. For example,
the amount of the third species in the second planning unit would be
stored in the third column and second row.
Examples
## Not run:
# load data
sim_pu_raster <- get_sim_pu_raster()
sim_pu_polygons <- get_sim_pu_polygons()
sim_zones_pu_raster <- get_sim_zones_pu_raster()
sim_features <- get_sim_features()
# create rij matrix using raster layer planning units
rij_raster <- rij_matrix(sim_pu_raster, sim_features)
print(rij_raster)
# create rij matrix using polygon planning units
rij_polygons <- rij_matrix(sim_pu_polygons, sim_features)
print(rij_polygons)
# create rij matrix using raster planning units with multiple zones
rij_zones_raster <- rij_matrix(sim_zones_pu_raster, sim_features)
print(rij_zones_raster)
## End(Not run)