-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrgbif_species_occ.R
67 lines (55 loc) · 1.97 KB
/
rgbif_species_occ.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
pacman::p_load(tidyverse,
glue,
janitor,
fs,
rgbif,
config,
yaml
)
gbif_creds <- config::get(file = "../config.yml", config = "gbif")
# specified by stuart
#species_tbl <- read_csv2("data/species.csv")
ods_species_path <- "data/lnrs-species-tbl.csv"
species_tbl <- read_csv(ods_species_path)
#https://geopick.gbif.org/
bounds <- "POLYGON (-3.065186 51.33576, -2.842712 51.486514, -2.58728 51.633362, -2.183533 51.551459, -2.246704 51.299711, -2.584534 51.218927, -3.043213 51.284253, -3.065186 51.33576)"
bounds <- "POLYGON ((-3.065186 51.33576, -3.043213 51.284253, -2.584534 51.218927, -2.246704 51.299711, -2.183533 51.551459, -2.58728 51.633362, -2.842712 51.486514, -3.065186 51.33576))"
# taxonKeys
keys <- species_tbl$usage_key
# set up the preds
years <- pred_in("year", 2019:2024)
area <- pred_within(bounds) #west of england
taxons <- pred_in("taxonKey", keys)
payload <- pred_and(years, area, taxons)
# get the ID
dl_key <- occ_download(payload,
user = gbif_creds$user,
pwd = gbif_creds$pwd,
email = gbif_creds$email)
dl_id <- yaml.load(dl_key)
dl_key
# see how long..
occ_download_wait(dl_id)
# download
species_gbif_tbl <- occ_download_get(dl_id) %>%
occ_download_import()
# inspect
species_gbif_tbl %>%
glimpse()
species_gbif_tbl$usage
# clean it
ods_species_tbl <- species_gbif_tbl %>%
select(modified,
license,
rightsHolder,
institutionCode,
sex,
lifeStage,
eventDate, year, verbatimLocality, latitude = decimalLatitude,
longitude = decimalLongitude, scientificName, kingdom, phylum, class,
order, family, genericName, lastInterpreted, taxonKey, species, level3Name)
unique(ods_species_tbl$license)
# write
ods_species_tbl %>%
clean_names() %>%
write.csv2("data/lnrs_species_occ_gbif_tbl.csv", row.names = FALSE, na = "")