get_GBIF: Get an occurrence record set from GBIF

get_gbifR Documentation

Get an occurrence record set from GBIF

Description

Get new occurrence record set from GBIF and save as .rds. GBIF is the Global Biodiversity Information Facility.

Usage

get_gbif(
  aoi = NULL,
  save_dir = NULL,
  get_new = FALSE,
  data_map = NULL,
  predicates = NULL,
  request_wait = 20,
  name = "gbif",
  filter_inconsistent = TRUE,
  filter_NA_date = TRUE,
  occ_char = TRUE,
  adj_spa_rel = TRUE,
  previous_key = NULL,
  ...
)

Arguments

aoi

sf defining area of interest.

save_dir

Character. File path into which to save outputs. If null results will be saved to fs::path("out", "ds", "gbif") as file gbif.rds.

get_new

Logical. If FALSE will attempt to load data from previously saved results.

data_map

Dataframe or NULL. Mapping of fields to retrieve. See example envImport::data_map

predicates

List. Any number of gbif predicates

request_wait

Integer. Time in seconds to wait between rgbif::occ_download_meta() requests. Used by rgbif::occ_download_wait() status_ping argument.

name

Character or NULL. data_name value in envImport::data_map (or other data_map). Required if data_map is not NULL

filter_inconsistent

Logical. If TRUE inconsistencies between the occurrenceStatus column and either organismQuantity or individualCount are removed. e.g. a record with occurrenceStatus == "ABSENT" but individualCount == 1 would be filtered.

filter_NA_date

Logical. Filter if is.na(eventDate).

occ_char

Logical. If true, occ_derivation will be coerced to character (to match other data sources).

adj_spa_rel

Logical. If true, an attempt will be made to check coordinateUncertaintyInMeters against: information in informationWithheld. If informationWithheld contains "Coordinate uncertainty increased to", readr::parse_number() is used to retrieve that number, which is then used to replace any value in coordinateUncertaintyInMeters; and if the column issue contains COORDINATE_UNCERTAINTY_METERS_INVALID, coordinateUncertaintyInMeters is limited to 10000 or greater.

previous_key

Character. e.g. 0092123-240506114902167. If provided, an attempt will be made to load (or download) a previous query of occurrence data.

...

Passed to envImport::file_prep()

Details

Uses various rgbif functions to return a dataframe of occurence records. Requires gbif credentials.

Any arguments to rgbif::occ_download() can be passed via extra_prediates. For convenience, aoi can also be passed directly and internally it is converted to a bounding box in appropriate lat/long and passed to rgbif::pred_within() in WKT format.

Value

Dataframe of occurrences, full download (as key.zip) in save_dir and file saved to save_dir as gbif.parquet.

Examples


  # setup -------
  library("envImport")

  # no aoi ------
  out_dir <- file.path(system.file(package = "envImport"), "examples", "get_gbif_ex")

  gbif_data <- get_gbif(save_dir = out_dir
                        , get_new = FALSE
                        #, data_map = envImport::data_map
                        , predicates = rgbif::pred_and(rgbif::pred("taxonKey", 2474903)
                                                       , rgbif::pred("year", 2000)
                                                       )
                        , previous_key = "0057516-240626123714530"
                        )

  # 667 records 2024-08-09
  nrow(gbif_data)
  head(gbif_data)

  # with aoi
  out_dir <- file.path(system.file(package = "envImport"), "examples", "get_gbif_aoi_ex")

  gbif_data <- get_gbif(save_dir = out_dir
                        , aoi = envClean::aoi
                        , data_map = envImport::data_map
                        , get_new = FALSE
                        , predicates = rgbif::pred("year", 2000)
                        )

  # 107 records 2024-08-09
  nrow(gbif_data)

  # .bib created
  readr::read_lines(fs::path(out_dir, "gbif", "gbif.bib"))

Acanthiza/envImport documentation built on Aug. 14, 2024, 8:18 a.m.