Skip to contents

This function downloads occurrence records from GBIF for a given vector of species names within a specified polygon, provided as a WKT string. The function sets up GBIF credentials, checks for taxon keys, handles synonyms, and downloads records based on the polygon and species names.

Usage

download_gbif_records(
  species_names,
  wkt,
  output_occur_path,
  gbif_user,
  gbif_pwd,
  gbif_email,
  import_to_r = TRUE
)

Arguments

species_names

A vector of species names to download records for.

wkt

The well-known text (WKT) representation of a polygon for spatial filtering.

output_occur_path

The path where the downloaded records will be saved.

gbif_user

Your GBIF username.

gbif_pwd

Your GBIF password.

gbif_email

Your GBIF email for notifications.

import_to_r

A logical value indicating whether to import the downloaded data into R. Default is TRUE.

Value

A list containing the downloaded occurrence records (if import_to_r is TRUE) and the citation for the GBIF download.

Details

The function automatically filters records to ensure that occurrences with geospatial issues or missing coordinates are excluded. Additionally, it excludes fossil and living specimens from the download.

Examples

# Define the path to the polygon file included in the package
polygon_path <- system.file("extdata", "danube_basin.gpkg", package = "yourPackageName")

# Convert the polygon to WKT format using the `get_wkt` function from your package
wkt <- get_wkt(bbox_danube_basin)

# Download occurrences for species of interest
output_occur_path <- "./downloaded_records"
gbif_data <- download_gbif_records(
  species_names = c("Hucho hucho", "Alburnoides bipunctatus", "Chondrostoma nasus"),
  wkt = wkt,
  output_occur_path = output_occur_path,
  gbif_user = "your_username",
  gbif_pwd = "your_password",
  gbif_email = "your_email@example.com",
  import_to_r = TRUE
)
#> Error: 401 - Unauthorized

# Access the downloaded records
occurrence_records <- gbif_data$raw_download

# Access the GBIF citation
gbif_citation <- gbif_data$gbif_download_citation

# Create a metadata file for the downloaded records
create_metadata_file(file_path = paste0(output_occur_path,"file_name.zip"),
description = "This file contains fish species occurrences from GBIF",
author = "Your Name",
author_email = "your_email@example.com",
source = gbif_citation)
#> Error in create_metadata_file(file_path = paste0(output_occur_path, "file_name.zip"),     description = "This file contains fish species occurrences from GBIF",     author = "Your Name", author_email = "your_email@example.com",     source = gbif_citation): The specified file does not exist.