https://github.com/r-spatialecology/vectormetrics
R package for calculating landscape and shape metrics for vector layers
https://github.com/r-spatialecology/vectormetrics
landscape-ecology landscape-metrics r rstats spatial spatial-vector
Last synced: about 1 month ago
JSON representation
R package for calculating landscape and shape metrics for vector layers
- Host: GitHub
- URL: https://github.com/r-spatialecology/vectormetrics
- Owner: r-spatialecology
- License: gpl-3.0
- Created: 2018-10-04T06:48:27.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-19T21:17:32.000Z (about 1 year ago)
- Last Synced: 2024-06-11T16:07:34.807Z (12 months ago)
- Topics: landscape-ecology, landscape-metrics, r, rstats, spatial, spatial-vector
- Language: R
- Homepage: https://r-spatialecology.github.io/vectormetrics/
- Size: 6.27 MB
- Stars: 14
- Watchers: 4
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
Awesome Lists containing this project
README
---
output:
github_document
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# vectormetrics
[](https://www.gnu.org/licenses/gpl-3.0)
[](https://lifecycle.r-lib.org/articles/stages.html#experimental)
[](https://github.com/r-spatialecology/vectormetrics/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/r-spatialecology/vectormetrics)## Overview
`vectormetrics` is an R package for calculating landscape and shape metrics for vector layers.
Its aim is to provide a set of metrics that can characterize landscape patterns and properties of the shapes defined as polygons and multipolygons.
Whole package is based on Simple Feature geometry standard provided by **sf** package.
Every function can be used in a tidy, piped workflow, as it always takes the data as the first argument and returns a `tibble`.## Installation
You can download most recent development version of the package from GitHub with:
```{r install_github, eval = FALSE}
remotes::install_github("r-spatialecology/vectormetrics")
```## Using vectormetrics
### Function names structure
All functions in `vectormetrics` start with *vm_* (for vector metrics).
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 and *rect* for the rectangularity).
Some landscape and class level functions have also a suffix at the end, that specifies the aggregation method (e.g. *mean*, *sd*).```{r function_names, eval = FALSE}
# Patch level
## vm_p_"metric"
vm_p_area()
vm_p_square()# Class level
## vm_c_"metric"[_"aggregation"]
vm_c_np()
vm_c_shape_sd()# Landscape level
## vm_l_"metric"[_"aggregation"]
vm_l_lpi()
vm_l_square_mn()
```### Examples
Some examples of calculating metrics on all levels and with different class and patch columns.
```{r vector_landscape, warning=FALSE, message=FALSE}
library(vectormetrics)
library(sf)
data("vector_landscape")
plot(vector_landscape)
``````{r simple_examples}
## Shape index
vm_p_shape(vector_landscape, class_col = "class")## Number of patches
vm_c_np(vector_landscape, class_col = "class")## Largest patch index
vm_l_lpi(vector_landscape)## Mean squareness
vm_l_square_mn(vector_landscape)
```### Utility functions
For now there are two utility functions available in the package.
First one is `get_patches()` which breaks multipolygon geometries into polygons.
There are two types of neighborhood relations available: 4 (edge) and 8 (vertex).
This function enables users to create set of geometries from aggregated shapes and analyze each shape's properties separately.```{r get_patches, message = FALSE}
vector_patches = get_patches(vector_landscape, class_col = "class", direction = 4)
vector_patchesvector_patches |>
dplyr::mutate(patch = as.factor(patch)) |>
plot()## Shape index
vm_p_shape(vector_patches, class_col = "class", patch_col = "patch")## Number of patches
vm_c_np(vector_patches, class_col = "class")## Mean squareness
vm_l_square_mn(vector_patches)
```Another utility function is `get_axes()` which calculates the length of the major and minor axes of the shape.
It is used to calculate the elongation metric in `vm_p_elong()` but since length of axes might be useful information itself, `get_axes()` was exported as a separate function.```{r get_axes, message = FALSE}
get_axes(vector_patches, class_col = "class")
```## Contributing
This is an experimental version of the package, so any feedback and contributions in the form of pull requests are welcome.