extractFromSpeciesRaster: Extract from speciesRaster

View source: R/extractFromSpeciesRaster.R

extractFromSpeciesRasterR Documentation

Extract from speciesRaster

Description

Return species from intersection between spatial points or polygons and a speciesRaster object.

Usage

extractFromSpeciesRaster(x, spatial, collapse = TRUE)

Arguments

x

object of class speciesRaster

spatial

coordinates as either a spatial points object (sp or sf), a marix/dataframe with two columns, a numeric vector of c(long, lat), or as a spatial polygon object (sp or sf).

collapse

boolean; if TRUE, then a vector of unique species is returned, pooled from all cells, if FALSE, then list is returned with species from every cell as intersected by spatial.

Details

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.

Value

A vector of species if collapse = TRUE, or a list of species by cell if collapse = FALSE.

Author(s)

Pascal Title

Examples

library(sf)
# get the projection of the speciesRaster
proj <- summary(tamiasSpRas)$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 = "+init=epsg:4326")
pts <- st_coordinates(st_transform(ptsSF, crs = proj))

# extract with table of coordinates
extractFromSpeciesRaster(tamiasSpRas, pts)

# extract with spatial points object
extractFromSpeciesRaster(tamiasSpRas, ptsSF)

# extract with spatial polygon
hull <- st_convex_hull(st_union(ptsSF))
extractFromSpeciesRaster(tamiasSpRas, hull)


# returns each cell's contents
extractFromSpeciesRaster(tamiasSpRas, hull, collapse=FALSE)

# collapses results to unique set of species
extractFromSpeciesRaster(tamiasSpRas, hull, collapse=TRUE)


ptitle/speciesRaster documentation built on June 11, 2022, 1:35 a.m.