Skip to contents

Performs a species occurrence check within a fixed radius around a GPS point using GBIF occurrence data.

Usage

tax_occur_check(
  taxa_name,
  longitude,
  latitude,
  radius_km = 50,
  circle_form = TRUE,
  clean_coord = TRUE,
  info_names = c("decimalLongitude", "decimalLatitude", "country", "year",
    "scientificName", "recordedBy", "gbifRegion"),
  return_all_occ = FALSE,
  verbose = TRUE,
  clean_coord_verbose = FALSE,
  n_occur = 1000,
  ...
)

Arguments

taxa_name

Character. Scientific name of the species to check.

longitude

Numeric. Longitude of the test point in decimal degrees.

latitude

Numeric. Latitude of the test point in decimal degrees.

radius_km

Numeric. Search radius in kilometers (default: 50).

circle_form

(Logical, default: TRUE). Whether to use a circular search area. If FALSE, a square bounding box is used.

clean_coord

(Logical, default: TRUE). Whether to clean coordinates using CoordinateCleaner

info_names

Character vector. Columns to select from GBIF data (default:c("decimalLongitude", "decimalLatitude", "country", "year", "scientificName", "recordedBy", "gbifRegion")). Note that "scientificName", "decimalLongitude" and "decimalLatitude" are required.

return_all_occ

(Logical, default: FALSE). If TRUE, return all occurrences found within the radius in a data frame called "occ_data" in the resulting list.

verbose

(Logical, default: TRUE). Whether to print progress messages.

clean_coord_verbose

(Logical, default: FALSE). Whether to print messages from CoordinateCleaner.

n_occur

Numeric (default: 1000). Maximum number of occurrences to retrieve from GBIF.

...

Additional parameters passed to [rgbif::occ_search()].

Value

A list containing: - count_in_radius: Number of occurrences found within the radius - closest_distance_km: Distance to the closest occurrence in kilometers - mean_distance_km: Mean distance to all occurrences in kilometers - total_count_in_world: Total number of occurrences with coordinates worldwide - search_radius: The search radius used (in kilometers) - closest_point_lat: Latitude of the closest occurrence - closest_point_lon: Longitude of the closest occurrence - sample_point_lat: Latitude of the tested point - sample_point_lon: Longitude of the tested point - occ_data (optional, if `return_all_occ` is TRUE): Data frame of all occurrences found within the radius

See also

[tax_occur_check_pq()], [tax_occur_multi_check_pq()]

Author

Adrien Taudiere

Examples

# \donttest{
# Check for Oak species near Paris
long <- 2.3522
lat <- 48.8566

Q_rob_in_Paris <- tax_occur_check("Quercus robur", long, lat, 100)
#> Reading ne_50m_land.zip from naturalearth...
#>  After cleaning with CoordinateCleaner::clean_coordinates:
#> - 957 occurrences remain(s)
#> - Total original: 1000
#> - Retention rate: 95.7%
#>  Found 755 occurrences for species Quercus robur:
#>  Closest occurrence: 7.82 km
Q_rob_in_Paris
#> $count_in_radius
#> [1] 755
#> 
#> $closest_distance_km
#> [1] 7.82
#> 
#> $mean_distance_km
#> [1] 69.16
#> 
#> $total_count_in_world
#> [1] 1489130
#> 
#> $search_radius
#> [1] 100
#> 
#> $closest_point_lat
#> [1] 48.8222
#> 
#> $closest_point_lon
#> [1] 2.44544
#> 
#> $sample_point_lat
#> [1] 48.8566
#> 
#> $sample_point_lon
#> [1] 2.3522
#> 

tax_occur_check("Trametopsis brasiliensis", long, lat, 100)
#> ! No occurrences found for Trametopsis brasiliensis
#> $count_in_radius
#> [1] 0
#> 
#> $closest_distance_km
#> [1] NA
#> 
#> $mean_distance_km
#> [1] NA
#> 
#> $total_count_in_world
#> [1] 0
#> 
#> $search_radius
#> [1] 100
#> 
#> $closest_point_lat
#> [1] NA
#> 
#> $closest_point_lon
#> [1] NA
#> 
#> $sample_point_lat
#> [1] 48.8566
#> 
#> $sample_point_lon
#> [1] 2.3522
#> 


# Visualize occurrences around Paris for Fagus sylvatica
res_occ <- tax_occur_check("Fagus sylvatica", long, lat, 200,
  return_all_occ = TRUE
)
#> Reading ne_50m_land.zip from naturalearth...
#>  After cleaning with CoordinateCleaner::clean_coordinates:
#> - 870 occurrences remain(s)
#> - Total original: 1000
#> - Retention rate: 87%
#>  Found 658 occurrences for species Fagus sylvatica:
#>  Closest occurrence: 8.3 km

occ_data_sf <- sf::st_as_sf(res_occ$occ_data,
  coords = c("decimalLongitude", "decimalLatitude"),
  crs = 4326
)

if (requireNamespace("leaflet")) {
  library(leaflet)
}
#> Loading required namespace: leaflet
if (requireNamespace("leafpop")) {
  library(leafpop)
}
#> Loading required namespace: leafpop
leaflet() |>
  addTiles() |>
  setView(lat, long, zoom = 12) |>
  fitBounds(
    lat1 = as.vector(sf::st_bbox(occ_data_sf))[2],
    lng1 = as.vector(sf::st_bbox(occ_data_sf))[1],
    lat2 = as.vector(sf::st_bbox(occ_data_sf))[4],
    lng2 = as.vector(sf::st_bbox(occ_data_sf))[3]
  ) |>
  leaflet::addCircles(data = occ_data_sf, color = "blue", stroke = 1, opacity = 0.8) |>
  leaflet::addCircleMarkers(lat, long, color = "orange", radius = 2, opacity = 1)
#> Error in loadNamespace(x): there is no package called ‘leaflet’
# }