Retrieve species occurrence records within an Area of Interest
Source:R/get_records.R
get_records.Rd
Retrieves species occurrence records from specified data providers within a given Area of Interest (AOI). The results are returned as an `sf` object containing point geometries. Duplicates can be removed based on geometry. This is a wrapper of the `occ` function from the spocc package.
Usage
get_records(species, aoi_sf, providers = NULL,
limit = 500, remove_duplicates = FALSE, date = NULL)
Arguments
- species
(`character`) Vector of species names to query.
- aoi_sf
(`sf`) An `sf` object representing the Area of Interest. Must have a valid CRS.
- providers
(`character`) Data providers to query (e.g., `"gbif"`, `"inat"`). Default is `NULL`, which queries all available providers.
- limit
(`integer`) Maximum number of records to retrieve per provider. Default is 500.
- remove_duplicates
(`logical`) Whether to remove duplicate geometries. Default is `FALSE`.
- date
(`character`) Vector of length two specifying the date range (e.g., `c("YYYY-MM-DD", "YYYY-MM-DD")`). Records outside this range will be excluded. Default is `NULL` (no date filtering).
Value
(`sf`) An `sf` object containing species occurrence records within the specified AOI that match the query criteria. Returns `NULL` if no records are found or if input parameters are invalid.
Details
This function simplifies retrieving occurrence records by wrapping the functionality of the `spocc::occ` function. It handles AOI spatial filtering and optional removal of duplicates.
Examples
# \donttest{
library(sf)
nc <- sf::st_read(system.file("shape/nc.shp", package="sf"))
#> Reading layer `nc' from data source
#> `/home/runner/work/_temp/Library/sf/shape/nc.shp' using driver `ESRI Shapefile'
#> Simple feature collection with 100 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension: XY
#> Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS: NAD27
records <- get_records(
species = "Lynx rufus",
aoi_sf = nc,
providers = c("gbif", "inat"),
limit = 200
)
#> Warning: attribute variables are assumed to be spatially constant throughout all geometries
head(records)
#> Simple feature collection with 6 features and 18 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: -81.58028 ymin: 36.29134 xmax: -81.44359 ymax: 36.35344
#> Geodetic CRS: WGS 84
#> # A tibble: 6 × 19
#> name prov date key AREA PERIMETER CNTY_ CNTY_ID NAME FIPS FIPSNO
#> <chr> <chr> <date> <chr> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <dbl>
#> 1 Lynx … gbif 2023-01-02 4516… 0.114 1.44 1825 1825 Ashe 37009 37009
#> 2 Lynx … gbif 2023-03-29 4171… 0.114 1.44 1825 1825 Ashe 37009 37009
#> 3 Lynx … gbif 2023-03-10 4171… 0.114 1.44 1825 1825 Ashe 37009 37009
#> 4 Lynx … gbif 2023-03-06 4172… 0.114 1.44 1825 1825 Ashe 37009 37009
#> 5 Lynx … gbif 2023-04-28 4171… 0.114 1.44 1825 1825 Ashe 37009 37009
#> 6 Lynx … gbif 2023-04-03 4172… 0.114 1.44 1825 1825 Ashe 37009 37009
#> # ℹ 8 more variables: CRESS_ID <int>, BIR74 <dbl>, SID74 <dbl>, NWBIR74 <dbl>,
#> # BIR79 <dbl>, SID79 <dbl>, NWBIR79 <dbl>, geometry <POINT [°]>
# }