Recently we were asked on GitHub whether there was a way to get all animal occurrences that are not a bird. This seems like an easy enough request, but unfortunately, there is currently no way to exclude groups from a download search and get everything but a certain group.

A user can get all birds, but they can’t get no birds!

I thought this was an interesting question and probably useful for other people wanting smaller downloads, since there are currenly around half a billion occurrence records for birds. I decided to get all the class keys that were not Aves (212) and make a no birds animal search query.

search query for all animals that are not a bird

This query above is all the taxon keys for classes that are not birds. You could also add taxon_key=6 to the end of this and get all plants and animals that are not a bird.

This brute-force approach of getting everything that is not of interest only works if your end query has less than 200 taxon keys. Fortunately for the case of animals, there are only 100 non-bird classes.

I generated this query using this R code.


library(purrr)
library(roperators) # for %+% string operator
library(stringr)

# api call to get all class keys for animals
base_url <- "https://www.gbif.org/api/species/search?"
params <- "rank=CLASS&highertaxon_key=1&status=ACCEPTED&status=DOUBTFUL&advanced=1&limit=200" 

url <- base_url %+% params

query <- httr::GET(url) %>% 
httr::content() %>% 
pluck("results") %>%
map(~ .x$classKey) %>%
map_chr(~ "taxon_key=" %+% .x) %>%
paste(collapse="&") %>%
str_replace_all("taxon_key=212&","") # remove birds 

# paste this result into a browser
"https://www.gbif.org/occurrence/search?" %+% query 
https://www.gbif.org/occurrence/search?taxon_key=119&taxon_key=120&taxon_key=121&taxon_key=131&taxon_key=133&taxon_key=134&taxon_key=135&taxon_key=136&taxon_key=137&taxon_key=139&taxon_key=140&taxon_key=143&taxon_key=144&taxon_key=146&taxon_key=158&taxon_key=159&taxon_key=175&taxon_key=176&taxon_key=199&taxon_key=203&taxon_key=204&taxon_key=205&taxon_key=206&taxon_key=207&taxon_key=209&taxon_key=210&taxon_key=211&taxon_key=213&taxon_key=214&taxon_key=215&taxon_key=216&taxon_key=221&taxon_key=222&taxon_key=224&taxon_key=225&taxon_key=226&taxon_key=229&taxon_key=235&taxon_key=236&taxon_key=238&taxon_key=239&taxon_key=247&taxon_key=248&taxon_key=249&taxon_key=250&taxon_key=251&taxon_key=252&taxon_key=253&taxon_key=254&taxon_key=255&taxon_key=256&taxon_key=276&taxon_key=277&taxon_key=278&taxon_key=281&taxon_key=290&taxon_key=307&taxon_key=308&taxon_key=309&taxon_key=345&taxon_key=346&taxon_key=347&taxon_key=350&taxon_key=351&taxon_key=352&taxon_key=353&taxon_key=354&taxon_key=355&taxon_key=356&taxon_key=358&taxon_key=359&taxon_key=360&taxon_key=361&taxon_key=365&taxon_key=367&taxon_key=5964034&taxon_key=5967490&taxon_key=7188530&taxon_key=7188589&taxon_key=7194193&taxon_key=7375758&taxon_key=7496922&taxon_key=7664204&taxon_key=7742773&taxon_key=7774442&taxon_key=7799559&taxon_key=7920181&taxon_key=8066236&taxon_key=8246594&taxon_key=8355438&taxon_key=8365233&taxon_key=9238047&taxon_key=9251154&taxon_key=9273948&taxon_key=9304242&taxon_key=9312928&taxon_key=9421786&taxon_key=9424764&taxon_key=9455590&taxon_key=9632402