buffer_area: Polygons based on buffered occurrences

View source: R/buffer_area.R

buffer_areaR Documentation

Polygons based on buffered occurrences

Description

buffer_area helps in creating buffer polygons based on occurrences, masking raster layers, and writing results if needed.

Usage

buffer_area(data, longitude, latitude, buffer_distance = 100,
            raster_layers = NULL, clip = FALSE, mask = FALSE,
            save = FALSE, name = "calib_area_buffer")

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.

buffer_distance

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

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 polygons
b_area <- buffer_area(data = occurrences, longitude = "longitude",
                      latitude = "latitude", buffer_distance = 50)

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

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

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

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

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

# check directory
dir()

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