if (FALSE) {
# occ_download(pred("basisOfRecord", "LITERATURE"))
# occ_download(pred("taxonKey", 3119195), pred_gt("elevation", 5000))
# occ_download(pred_gt("decimalLatitude", 50))
# occ_download(pred_gte("elevation", 9000))
# occ_download(pred_gte('decimalLatitude", 65))
# occ_download(pred("country", "US"))
# occ_download(pred("institutionCode", "TLMF"))
# occ_download(pred("catalogNumber", 217880))
# occ_download(pred("gbifId", 142317604))
# download format
# z <- occ_download(pred_gte("decimalLatitude", 75),
# format = "SPECIES_LIST")
# res <- occ_download(pred("taxonKey", 7264332), pred("hasCoordinate", TRUE))
# pass output directly, or later, to occ_download_meta for more information
# occ_download(pred_gt('decimalLatitude', 75)) %>% occ_download_meta
# Multiple queries
# occ_download(pred_gte("decimalLatitude", 65),
# pred_lte("decimalLatitude", -65), type="or")
# gg <- occ_download(pred("depth", 80), pred("taxonKey", 2343454),
# type="or")
# x <- occ_download(pred_and(pred_within("POLYGON((-14 42, 9 38, -7 26, -14 42))"),
# pred_gte("elevation", 5000)))
# complex example with many predicates
# shows example of how to do date ranges for both year and month
# res <- occ_download(
# pred_gt("elevation", 5000),
# pred_in("basisOfRecord", c('HUMAN_OBSERVATION','OBSERVATION','MACHINE_OBSERVATION')),
# pred("country", "US"),
# pred("hasCoordinate", TRUE),
# pred("hasGeospatialIssue", FALSE),
# pred_gte("year", 1999),
# pred_lte("year", 2011),
# pred_gte("month", 3),
# pred_lte("month", 8)
# )
# Using body parameter - pass in your own complete query
## as JSON
query1 <- '{"creator":"sckott",
"notification_address":["stuff1@gmail.com"],
"predicate":{"type":"and","predicates":[
{"type":"equals","key":"TAXON_KEY","value":"7264332"},
{"type":"equals","key":"HAS_COORDINATE","value":"TRUE"}]}
}'
# res <- occ_download(body = query1, curlopts=list(verbose=TRUE))
## as a list
library(jsonlite)
query <- list(
creator = unbox("sckott"),
notification_address = "stuff1@gmail.com",
predicate = list(
type = unbox("and"),
predicates = list(
list(type = unbox("equals"), key = unbox("TAXON_KEY"),
value = unbox("7264332")),
list(type = unbox("equals"), key = unbox("HAS_COORDINATE"),
value = unbox("TRUE"))
)
)
)
# res <- occ_download(body = query, curlopts = list(verbose = TRUE))
# Prepared query
occ_download_prep(pred("basisOfRecord", "LITERATURE"))
occ_download_prep(pred("basisOfRecord", "LITERATURE"), format = "SIMPLE_CSV")
occ_download_prep(pred("basisOfRecord", "LITERATURE"), format = "SPECIES_LIST")
occ_download_prep(pred_in("taxonKey", c(2977832, 2977901, 2977966, 2977835)))
occ_download_prep(pred_within("POLYGON((-14 42, 9 38, -7 26, -14 42))"))
## a complicated example
occ_download_prep(
pred_in("basisOfRecord", c("MACHINE_OBSERVATION", "HUMAN_OBSERVATION")),
pred_in("taxonKey", c(2498343, 2481776, 2481890)),
pred_in("country", c("GB", "IE")),
pred_or(pred_lte("year", 1989), pred("year", 2000))
)
# x = occ_download(
# pred_in("basisOfRecord", c("MACHINE_OBSERVATION", "HUMAN_OBSERVATION")),
# pred_in("taxonKey", c(9206251, 3112648)),
# pred_in("country", c("US", "MX")),
# pred_and(pred_gte("year", 1989), pred_lte("year", 1991))
# )
# occ_download_meta(x)
# z <- occ_download_get(x)
# df <- occ_download_import(z)
# str(df)
# library(dplyr)
# unique(df$basisOfRecord)
# unique(df$taxonKey)
# unique(df$countryCode)
# sort(unique(df$year))
}
Run the code above in your browser using DataLab