Get Started with landscapemetrics

2018-08-14

#> Warning: package 'dplyr' was built under R version 3.5.1

Using landscapemetrics

All functions in landscapemetrics start with lsm_ (for landscapemetrics). The second part of the name specifies the level (patch - p, class - c or landscape - l). The last part of the function name is the abbreviation of the corresponding metric (e.g. ennfor the euclidean nearest-neighbor distance):

# general structure
lsm_"level"_"metric"

# Patch level
## lsm_p_"metric"
lsm_p_enn()

# Class level
## lsm_c_"metric"
lsm_c_enn()

# Landscape level
## lsm_p_"metric"
lsm_l_enn()

All functions return an identical structured tibble:

layer level class id metric value
1 patch 1 1 landscape metric x
1 class 1 NA landscape metric x
1 landscape NA NA landscape metric x

# Import raster
landscape_raster <- landscape
# for local file: raster("pathtoyourraster/raster.asc")
# ... or any other raster file type, geotiff, ...

# Calculate e.g. perimeter of all patches
lsm_p_perim(landscape_raster)
#> # A tibble: 27 x 6
#>    layer level class    id metric value
#>    <int> <chr> <int> <int> <chr>  <dbl>
#>  1     1 patch     1     1 perim      4
#>  2     1 patch     1     2 perim    130
#>  3     1 patch     1     3 perim     12
#>  4     1 patch     1     4 perim     20
#>  5     1 patch     1     5 perim      4
#>  6     1 patch     1     6 perim     10
#>  7     1 patch     1     7 perim      4
#>  8     1 patch     1     8 perim      4
#>  9     1 patch     1     9 perim      8
#> 10     1 patch     2    10 perim     38
#> # ... with 17 more rows

The metrics are encoded using abbreviations in the result tibble. In case you want to match the full name of each metric, we provide a tibble (lsm_abbreciations_names) you can join with the result tibble using the metric column. The this also adds the type of the metrics.

# Calculate metric
result <- lsm_c_dcad(landscape)

# Left join with abbreviation tibble
result_full_name <- left_join(x = result, 
                                     y = lsm_abbreviations_names, 
                                     by = "metric")
# Show results
result_full_name
#> # A tibble: 3 x 8
#>   layer level class    id metric  value full_name             type        
#>   <int> <chr> <int> <int> <chr>   <dbl> <chr>                 <chr>       
#> 1     1 class     1    NA dcad    5556. disjunct core area d~ core area m~
#> 2     1 class     2    NA dcad    8889. disjunct core area d~ core area m~
#> 3     1 class     3    NA dcad   13333. disjunct core area d~ core area m~

Important information about using landscapemetrics

The resolution of a raster cell has to be in meters, as the package converts units internally and returns results in either meters, square meters or hectares. For more information see the help file of each function.

Using landscapemetrics in a tidy workflow

Every function in landscapemetrics accept data as its first argument, which makes piping a natural workflow. A possible use case is that you would load your spatial data, calculate some landscape metrics and then use the resulting tibble in further analyses.

Use multiple metric functions

As the result of every function always returns a tibble, combining the metrics that were selected for your research question is straightforward:

Additionally, we provide a wrapper where the desired metrics can be specified as a vector of strings. Because all metrics regardless of the level return an identical tibble, different levels can be mixed. It is also possible to calculate all available metrics at a certain level using e.g. what = "patch"

All metrics are abbreviated in the result tibble. Therefore, we provide a tibble containing the full metric names, as well as the class of each metric (lsm_abbreviations_names). Using e.g. the left_join() function of the dplyr package one could join a result tibble and the abbrevations tibble.

In calculate_metrics this exists as option (full_name = TRUE).