View source: R/extractFromEpmGrid.R
extractFromEpmGrid | R Documentation |
Return species from intersection between spatial points or polygons and a epmGrid object.
extractFromEpmGrid(x, spatial, returnCells = FALSE, collapse = TRUE)
x |
object of class |
spatial |
coordinates as either a spatial points object (sp or sf), a matrix/dataframe with two columns, a numeric vector of c(long, lat), or as a spatial polygon object (sp or sf). |
returnCells |
boolean, if |
collapse |
boolean; if |
If spatial
is a spatial object, it will be transformed to
the same projection as x
if needed. If spatial
is not a
spatial object, it is assumed to be in the same projection as x
.
A vector of species if collapse = TRUE
, or a list of species
by cell if collapse = FALSE
. If returnCells = TRUE
, a vector
of cell indices that correspond to the rows in the epmGrid sf object.
Pascal Title
library(sf)
# get the projection of the epmGrid object
proj <- summary(tamiasEPM)$crs
# define some points
pts <- rbind.data.frame(
c(-120.5, 38.82),
c(-84.02, 42.75),
c(-117.95, 55.53))
colnames(pts) <- c('x', 'y')
ptsSF <- st_as_sf(pts, coords = 1:2, crs = "epsg:4326")
pts <- st_coordinates(st_transform(ptsSF, crs = proj))
# extract with table of coordinates
extractFromEpmGrid(tamiasEPM, pts)
# extract with spatial points object
extractFromEpmGrid(tamiasEPM, ptsSF)
# extract with spatial polygon
hull <- st_convex_hull(st_union(ptsSF))
extractFromEpmGrid(tamiasEPM, hull)
# returns each cell's contents
extractFromEpmGrid(tamiasEPM, hull, collapse=FALSE)
# collapses results to unique set of species
extractFromEpmGrid(tamiasEPM, hull, collapse=TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.