Skip to content

Commit

Permalink
Merge pull request #57 from PoisotLab/feature/gbif-many-taxa
Browse files Browse the repository at this point in the history
[GBIF] add option to look for vector of taxa
  • Loading branch information
tpoisot authored Nov 16, 2022
2 parents a3d1cd6 + 673e337 commit 73ca18a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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

0 comments on commit 73ca18a

Please sign in to comment.