Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GBIF] add option to look for vector of taxa #57

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions GBIF/src/occurrence.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,18 @@ function occurrences(t::GBIFTaxon, query::Pair...)
taxon_query = String(level) * "Key" => getfield(t, level).second
return occurrences(taxon_query, query...)
end

"""
occurrences(t::Vector{GBIFTaxon}, query::Pair...)

Returns occurrences for a series of taxa -- the query arguments are the same as the `occurrences` function.
"""
function occurrences(ts::Vector{GBIFTaxon}, query::Pair...)
taxon_query = []
for t in ts
levels = [:kingdom, :phylum, :class, :order, :family, :genus, :species]
level = levels[findlast(l -> getfield(t, l) !== missing, levels)]
push!(taxon_query, String(level) * "Key" => getfield(t, level).second)
end
return occurrences(taxon_query..., query...)
end
6 changes: 6 additions & 0 deletions GBIF/test/occurrences.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ while length(obs) < count(obs)
end
@test length(obs) == count(obs)

# Version with multiple taxa
serval = GBIF.taxon("Leptailurus serval", strict=true)
leopard = GBIF.taxon("Panthera pardus", strict=true)
obs = occurrences([leopard, serval], "hasCoordinate" => true, "occurrenceStatus" => "PRESENT")
@test typeof(obs) == GBIFRecords

# Version with the full query AND a set page size - this one has about 250 records
obs = occurrences(serval, "hasCoordinate" => "true", "continent" => "AFRICA", "decimalLongitude" => (-30, 40), "limit" => 45)
while length(obs) < count(obs)
Expand Down