View source: R/polygon_selection.R
| polygon_selection | R Documentation | 
polygon_selection helps in selecting polygons that intersect with occurrences. Buffering polygons, masking raster layers, and writing results can also be performed if needed.
polygon_selection(data, longitude, latitude, polygons,
                  buffer_distance = NULL, raster_layers = NULL,
                  clip = FALSE, dissolve = FALSE, mask = FALSE,
                  save = FALSE, name = "calib_area_poligons")
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.  | 
polygons | 
 SpatialPolygon* object.  | 
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   | 
dissolve | 
 (logical) whether or not to dissolve polygons. Default = FALSE.  | 
mask | 
 (logical) whether or not to mask the   | 
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
  | 
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.
# reading data
occurrences <- read.csv(system.file("extdata", "occurrences.csv",
                                    package = "ellipsenm"))
spatial_poly <- #HERE YOUR SPATIAL POLYGON OBJECT
# selecting polygons
sp_area <- polygon_selection(data = occurrences, longitude = "longitude",
                             latitude = "latitude", polygons = spatial_poly)
sp::plot(sp_area)
points(occurrences[, 2:3])
# selecting polygons with buffers
sp_area1 <- polygon_selection(data = occurrences, longitude = "longitude",
                              latitude = "latitude", polygons = spatial_poly,
                              buffer_distance = 50)
sp::plot(sp_area1)
points(occurrences[, 2:3])
# selecting polygons, masking layers
vars <- raster::stack(list.files(system.file("extdata", package = "ellipsenm"),
                                 pattern = "bio", full.names = TRUE))
sp_area3 <- polygon_selection(data = occurrences, longitude = "longitude",
                              latitude = "latitude", polygons = spatial_poly,
                              buffer_distance = 50, raster_layers = vars,
                              mask = TRUE)
raster::plot(sp_area3$masked_variables[[1]])
sp::plot(sp_area3$calibration_area, add = TRUE)
points(occurrences[, 2:3])
# selecting polygons, masking layers, and saving results
sp_area4 <- polygon_selection(data = occurrences, longitude = "longitude",
                              latitude = "latitude", polygons = spatial_poly,
                              buffer_distance = 50, raster_layers = vars,
                              mask = TRUE, save = TRUE, name = "p_selection")
# check directory
dir()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.