rij_matrix: Feature by planning unit matrix

rij_matrixR 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

terra::rast() or sf::sf() object representing planning units.

y

terra::rast() object.

...

not used.

memory

logical should calculations be performed using a method that prioritizes reduced memory consumption over speed? If TRUE, then calculations are performed using a method that reduces memory consumption, but can take a long time to complete. If FALSE, then calculations are performed using a method that reduces run time, but will fail when insufficient memory is available. Defaults to NA, such that calculations are automatically performed using the best method given available memory and dataset sizes. Note that this parameter can only be used when the arguments to x and y are both terra::rast() objects.

fun

character for summarizing values inside each planning unit. This parameter is only used when the argument to x is a sf::sf() object. Defaults to "sum".

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)

prioritizr/prioritizr documentation built on March 4, 2024, 3:54 p.m.