README last updated: 2025-02-11
| CI | Development | CRAN | License |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------|
| [](https://github.com/r-spatialecology/landscapemetrics/actions/workflows/R-CMD-check.yaml) | [](https://lifecycle.r-lib.org/articles/stages.html) | [](https://cran.r-project.org/package=landscapemetrics) | [](https://www.gnu.org/licenses/gpl-3.0) |
| [](https://app.codecov.io/gh/r-spatialecology/landscapemetrics) | [](https://www.repostatus.org/) | [](https://cran.r-project.org/package=landscapemetrics) | [](https://doi.org/10.1111/ecog.04617) |
> Starting from v2.0.0, **landscapemetrics** uses `terra` and `sf`
> internally. More information about the `terra` package can be found
> here: Hesselbarth, M.H.K., Sciaini, M., With, K.A., Wiegand, K., Nowosad, J. 2019. landscapemetrics: an open‐source R tool to calculate landscape metrics. Ecography, 42: 1648-1657 (v0.0).
For more information see [Publication record](https://r-spatialecology.github.io/landscapemetrics/articles/articles/publication_record.html) vignette. The get a BibTex entry, please use `citation("landscapemetrics")`. ## Installation There are several ways to install **landscapemetrics**: ``` r # Get the stable version from CRAN install.packages("landscapemetrics") # Alternatively, you can install the development version from Github # install.packages("remotes") remotes::install_github("r-spatialecology/landscapemetrics") ``` #### Announcement Due to an improved connected-component labelling algorithm (**landscapemetrics** v1.4 and higher), patches are labeled in a different order than before and therefore different patch IDs might be used compared to previous versions. However, results for all metrics are identical. ## 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. Before using **landscapemetrics**, be sure to check your raster (see `check_landscape()`). All functions in **landscapemetrics** start with `lsm_` (for **l**and**s**cape **m**etrics). 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 | ### Using metric functions Every function follows the same implementation design, so the usage is quite straightforward: ``` r library(landscapemetrics) library(terra) # internal data needs to be read landscape <- terra::rast(landscapemetrics::landscape) # landscape raster plot(landscape) ```
``` r
# calculate for example the Euclidean nearest-neighbor distance on patch level
lsm_p_enn(landscape)
#> # A tibble: 28 × 6
#> layer level class id metric value
#>