concave_area: Concave hull polygons based on occurrences

View source: R/concave_area.R

concave_areaR Documentation

Concave hull polygons based on occurrences

Description

concave_area helps in creating concave polygons based on occurrences, buffering polygons, masking raster layers, and writing results if needed.

Usage

concave_area(data, longitude, latitude, length_threshold = 5,
             split = FALSE, cluster_method = "hierarchical",
             split_distance = NULL, n_kmeans = NULL, buffer_distance = NULL,
             raster_layers = NULL, clip = FALSE, mask = FALSE,
             save = FALSE, name = "calib_area_concave")

Arguments

data

data.frame of occurrence records containing at least longitude and latitude columns.

longitude

(character) name of the column with longitude data.

latitude

(character) name of the column with latitude data.

length_threshold

(numeric) distance in km to define when a segment length stops being considered for further detalization. Higher values result in simpler shapes. Default = 5.

split

(logical) if TRUE, a distance (for hierarchical clustering) or a number (for K-means clustering) is used to separate distinct chunks of data Recommended when the species of interest has a disjunct distribution. Default = FALSE.

cluster_method

(character) name of the method to be used for clustering the occurrences. Options are "hierarchical" and "k-means"; default = "hierarchical". Note that this parameter is ignored when split = FALSE. See details cluster_split.

split_distance

(numeric) distance in km that will be considered as the limit of connectivity among polygons created with clusters of occurrences. This parameter is used when cluster_method = "hierarchical" and split = TRUE. Default = NULL.

n_kmeans

(numeric) if split = TRUE, number of clusters in which the species occurrences will be grouped using the "k-means" method. Default = NULL.

buffer_distance

(numeric) distance in km to be used to create a buffer for the concave hull. Default = NULL.

raster_layers

optional RasterStack to be used in restricting the resulting SpatialPolygon and in preparing variables for further processing. Default = NULL.

clip

(logical) whether or not to clip polygons considering boundaries of layers in raster_layers. Using this option increases the time of processing considerably. Default = FALSE.

mask

(logical) whether or not to mask the raster_layers to the area created with thsi function. Default = FALSE.

save

(logical) whether or not to write the results in the working directory. Default = FALSE.

name

(character) name of a folder to be written with the results if save = TRUE. Default = "calib_area_concave".

Value

If raster layers are masked, a lits containing a SpatialPolygonDataFrame and a RasterStack of the masked layers.

If raster layers are not masked, a SpatialPolygonDataFrame.

If save = TRUE, results are written in a folder named as in name.

Examples

# reading data
occurrences <- read.csv(system.file("extdata", "occurrences.csv",
                                    package = "ellipsenm"))

# producing simple concave polygons
cv_area <- concave_area(data = occurrences, longitude = "longitude",
                       latitude = "latitude")

sp::plot(cv_area)
points(occurrences[, 2:3])

# producing concave polygons with buffers
cv_area1 <- concave_area(data = occurrences, longitude = "longitude",
                        latitude = "latitude", buffer_distance = 50)

sp::plot(cv_area1)
points(occurrences[, 2:3])

# producing concave polygons splitted considering clusters
cv_area2 <- concave_area(data = occurrences, longitude = "longitude",
                        latitude = "latitude", split = TRUE,
                        cluster_method = "k-means", n_kmeans = 2,
                        buffer_distance = 5)

sp::plot(cv_area2)
points(occurrences[, 2:3])

# producing concave polygons, masking layers
vars <- raster::stack(list.files(system.file("extdata", package = "ellipsenm"),
                                 pattern = "bio", full.names = TRUE))

cv_area3 <- concave_area(data = occurrences, longitude = "longitude",
                        latitude = "latitude", buffer_distance = 50,
                        raster_layers = vars, mask = TRUE)

raster::plot(cv_area3$masked_variables[[1]])
sp::plot(cv_area3$calibration_area, add = TRUE)
points(occurrences[, 2:3])

# producing concave polygons, masking layers, and saving results
cv_area4 <- concave_area(data = occurrences, longitude = "longitude",
                        latitude = "latitude", buffer_distance = 50,
                        raster_layers = vars, mask = TRUE, save = TRUE,
                        name = "concave_area")

# check directory
dir()

marlonecobos/ellipsenm documentation built on Oct. 18, 2023, 8:09 a.m.