Skip to content

Commit

Permalink
[GBIF] add option to look for vector of taxa
Browse files Browse the repository at this point in the history
  • Loading branch information
tpoisot committed Nov 16, 2022
1 parent a3d1cd6 commit 673e337
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

2 comments on commit 673e337

@tpoisot
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register subdir=GBIF

Release notes:

Updates GBIF to work with the monorepo.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Changing package repo URL not allowed, please submit a pull request with the URL change to the target registry and retry.

Please sign in to comment.