Skip to contents

Extract metrics

Usage

extract_lsm(
  landscape,
  y,
  extract_id = NULL,
  metric = NULL,
  name = NULL,
  type = NULL,
  what = NULL,
  directions = 8,
  progress = FALSE,
  verbose = TRUE,
  ...
)

Arguments

landscape

A categorical raster object: SpatRaster; Raster* Layer, Stack, Brick; stars or a list of SpatRasters.

y

2-column matrix with coordinates or sf point geometries.

extract_id

Vector with id of sample points. If not provided, sample points will be labelled 1...n.

metric

Abbreviation of metrics (e.g. 'area').

name

Full name of metrics (e.g. 'core area')

type

Type according to FRAGSTATS grouping (e.g. 'aggregation metrics').

what

Selected level of metrics: either "patch", "class" or "landscape". It is also possible to specify functions as a vector of strings, e.g. what = c("lsm_c_ca", "lsm_l_ta").

directions

The number of directions in which patches should be connected: 4 (rook's case) or 8 (queen's case).

progress

Print progress report.

verbose

Print warning messages.

...

Arguments passed to calculate_lsm().

Value

tibble

Details

This functions extracts the metrics of all patches the spatial object(s) y (e.g. spatial points) are located within. Only patch level metrics are possible to extract. Please be aware that the output is slightly different to all other lsm-function of landscapemetrics. Returns a tibble with chosen metrics and the ID of the spatial objects.

See also

Examples

landscape <- terra::rast(landscapemetrics::landscape)

points <- matrix(c(10, 5, 25, 15, 5, 25), ncol = 2, byrow = TRUE)
extract_lsm(landscape, y = points)
#> Warning: Please use 'check_landscape()' to ensure the input data is valid.
#> # A tibble: 36 × 7
#>    layer level class    id metric   value extract_id
#>    <int> <chr> <int> <int> <chr>    <dbl>      <int>
#>  1     1 patch     3    24 area    0.0113          1
#>  2     1 patch     3    24 cai    40.7             1
#>  3     1 patch     3    24 circle  0.747           1
#>  4     1 patch     3    24 contig  0.752           1
#>  5     1 patch     3    24 core    0.0046          1
#>  6     1 patch     3    24 enn     2               1
#>  7     1 patch     3    24 frac    1.36            1
#>  8     1 patch     3    24 gyrate  5.79            1
#>  9     1 patch     3    24 ncore   3               1
#> 10     1 patch     3    24 para    0.885           1
#> # ℹ 26 more rows
extract_lsm(landscape, y = points, type = "aggregation metric")
#> Warning: Please use 'check_landscape()' to ensure the input data is valid.
#> # A tibble: 3 × 7
#>   layer level class    id metric value extract_id
#>   <int> <chr> <int> <int> <chr>  <dbl>      <int>
#> 1     1 patch     3    24 enn        2          1
#> 2     1 patch     3    26 enn        2          2
#> 3     1 patch     3    23 enn        2          3

if (FALSE) { # \dontrun{
# use lines

} # }