#> Warning: package 'dplyr' was built under R version 3.5.1
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. enn
for 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~
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.
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.
# All patch IDs of class 2 with an ENN > 2.5
subsample_patches <- landscape %>%
lsm_p_enn() %>%
dplyr::filter(class == 2 & value > 2.5) %>%
dplyr::pull(id)
# Show results
subsample_patches
#> [1] 10 11 12 13 14 15 16 17 19 21 23
As the result of every function always returns a tibble, combining the metrics that were selected for your research question is straightforward:
# bind results from different metric functions
patch_metrics <- bind_rows(
lsm_p_cai(landscape),
lsm_p_circle(landscape),
lsm_p_enn(landscape)
)
# look at the results
patch_metrics
#> # A tibble: 81 x 6
#> layer level class id metric value
#> <int> <chr> <int> <int> <chr> <dbl>
#> 1 1 patch 1 1 cai 0
#> 2 1 patch 1 2 cai 48.0
#> 3 1 patch 1 3 cai 0
#> 4 1 patch 1 4 cai 14.3
#> 5 1 patch 1 5 cai 0
#> 6 1 patch 1 6 cai 0
#> 7 1 patch 1 7 cai 0
#> 8 1 patch 1 8 cai 0
#> 9 1 patch 1 9 cai 0
#> 10 1 patch 2 10 cai 31.4
#> # ... with 71 more rows
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"
calculate_metrics(landscape, what = c("lsm_c_pland", "lsm_l_ta", "lsm_l_te"))
#> # A tibble: 5 x 6
#> layer level class id metric value
#> <int> <chr> <int> <int> <chr> <dbl>
#> 1 1 class 1 NA pland 19.9
#> 2 1 class 2 NA pland 26.9
#> 3 1 class 3 NA pland 53.2
#> 4 1 landscape NA NA ta 0.09
#> 5 1 landscape NA NA te 364
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
.
# bind results from different metric functions
patch_metrics <- bind_rows(
lsm_p_cai(landscape),
lsm_p_circle(landscape),
lsm_p_enn(landscape)
)
# look at the results
patch_metrics_full_names <- dplyr::left_join(x = patch_metrics,
y = lsm_abbreviations_names,
by = "metric")
patch_metrics_full_names
#> # A tibble: 81 x 8
#> layer level class id metric value full_name type
#> <int> <chr> <int> <int> <chr> <dbl> <chr> <chr>
#> 1 1 patch 1 1 cai 0 core area index core area metric
#> 2 1 patch 1 2 cai 48.0 core area index core area metric
#> 3 1 patch 1 3 cai 0 core area index core area metric
#> 4 1 patch 1 4 cai 14.3 core area index core area metric
#> 5 1 patch 1 5 cai 0 core area index core area metric
#> 6 1 patch 1 6 cai 0 core area index core area metric
#> 7 1 patch 1 7 cai 0 core area index core area metric
#> 8 1 patch 1 8 cai 0 core area index core area metric
#> 9 1 patch 1 9 cai 0 core area index core area metric
#> 10 1 patch 2 10 cai 31.4 core area index core area metric
#> # ... with 71 more rows
In calculate_metrics
this exists as option (full_name = TRUE
).
calculate_metrics(landscape, what = c("lsm_c_pland", "lsm_l_ta", "lsm_l_te"),
full_name = TRUE)
#> # A tibble: 5 x 8
#> layer level class id metric value full_name type
#> <int> <chr> <int> <int> <chr> <dbl> <chr> <chr>
#> 1 1 class 1 NA pland 19.9 percentage of la~ area and ege~
#> 2 1 class 2 NA pland 26.9 percentage of la~ area and ege~
#> 3 1 class 3 NA pland 53.2 percentage of la~ area and ege~
#> 4 1 landsca~ NA NA ta 0.09 total area area and ege~
#> 5 1 landsca~ NA NA te 364 total edge area and ege~