convex_area: Convex hull polygons based on occurrences

View source: R/convex_area.R

convex_areaR Documentation

Convex hull polygons based on occurrences

Description

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

Usage

convex_area(data, longitude, latitude, 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_convex")

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.

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 convex 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_convex".

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 convex polygons
cx_area <- convex_area(data = occurrences, longitude = "longitude",
                       latitude = "latitude")

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

# producing convex polygons with buffers
cx_area1 <- convex_area(data = occurrences, longitude = "longitude",
                        latitude = "latitude", buffer_distance = 50)

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

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

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

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

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

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

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

# check directory
dir()

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