Hello, I want to get all the observations (all fields including latitude, longitude of an observation) by its taxon name by the API.
After that I want all the images of a taxon by its name by API.
Finally I want all the vernacular names of a taxon by its name by API.
Thank you
Best regards
Hi @Sylvain_Ard
The easiest would be to generate a download based on a list of taxon names. We have some tutorials on how to do that here: Downloading occurrences from a long list of species in R and Python - GBIF Data Blog
Having all the data in one download will make citing the data much easier. See also our citation guidelines: https://www.gbif.org/citation-guidelines
Also check this thread about getting vernacular names: API Offset Limit - #3 by DG070
All observations (occurrences)
I agree that the download service would probably be better suited to your question, is there any reason you’d prefer to use the API?
Keep in mind that the API is hard limited to 100.000 occurrences, if your query has more results, you can not fetch all of them via the API.
All images
This is certainly possible! For example: https://api.gbif.org/v1/occurrence/4517444301, have a look at media
The file can be found on the path under identifier
, you can have mulitple different images per occurrence. However, keep in mind that not all data providers will tell you what image format they are providing, if you are downloading from lots of different datasets you will get lots of differet sizes, extensions and filenames and formats.
It’s important to keep respect the license on an image by image basis, without a license, you can not reuse the image in any way. Lots of images will have open licenses like CC-BY (where you’ll need to attribute the image to the copyright owner), or CC-BY-NC (where you can’t use the image for commercial use, including wikipedia, this includes the vast majority of reuse sadly).
Vernacular Names
You are looking for information that is housed in checklists, this is separate from occurrence data. Also consider wikidata, or even iNaturalist as other crowd sourced information sources.
Hi,
I have lowered my ambitions, I would simply like to retrieve 30 images of a taxon given by its taxonId, and its common names by its taxonId in PHP, how to do it please?
Thank you
Best regards
For R and Python good wrappers exist for the API; Introduction to rgbif • rgbif and pygbif · PyPI
I don’t have much experience with PHP. Have a look at the API documentation: GBIF API Reference :: Technical Documentation
If you want to keep it fully in GBIF, I suppose you could query for some occurrences for a taxonKey, then go over those media objects to see if any match your license requirements, and download those files. But I think that is probably not the way to go… I assume you don’t want random images, but somewhat representable ones, and rights clearing them will be a hassle!
Altough I think you might be better off using something like wikicommons, but remember, you need to check the license to make sure you are allowed to use it! You could also consider something like Unsplash I suppose, they sometimes have species names…
Using sparql in php (via the wikidata query GUI, I didn’t write this code):
<?php
class SPARQLQueryDispatcher
{
private $endpointUrl;
public function __construct(string $endpointUrl)
{
$this->endpointUrl = $endpointUrl;
}
public function query(string $sparqlQuery): array
{
$opts = [
'http' => [
'method' => 'GET',
'header' => [
'Accept: application/sparql-results+json',
'User-Agent: WDQS-example PHP/' . PHP_VERSION, // TODO adjust this; see https://w.wiki/CX6
],
],
];
$context = stream_context_create($opts);
$url = $this->endpointUrl . '?query=' . urlencode($sparqlQuery);
$response = file_get_contents($url, false, $context);
return json_decode($response, true);
}
}
$endpointUrl = 'https://query.wikidata.org/sparql';
$sparqlQueryString = <<< 'SPARQL'
SELECT ?image
WHERE {
?taxon wdt:P846 "3240562" .
?taxon wdt:P18 ?image .
}
SPARQL;
$queryDispatcher = new SPARQLQueryDispatcher($endpointUrl);
$queryResult = $queryDispatcher->query($sparqlQueryString);
var_export($queryResult);
Have a look yourself: https://w.wiki/9G8c
For the vernacuar names you can use the Species API:
curl -X 'GET' \
'https://api.gbif.org/v1/species/3240565/vernacularNames' \
-H 'accept: application/json'
results in:
{
"offset": 0,
"limit": 20,
"endOfRecords": true,
"results": [
{
"taxonKey": 3240565,
"vernacularName": "Fat Dormouse",
"language": "eng",
"source": "Catalogue of Life Checklist",
"sourceTaxonKey": 219039870
},
{
"taxonKey": 3240565,
"vernacularName": "Fat Dormouse",
"language": "eng",
"source": "Integrated Taxonomic Information System (ITIS)",
"sourceTaxonKey": 134105327
},
{
"taxonKey": 3240565,
"vernacularName": "fat dormice",
"language": "",
"source": "NCBI Taxonomy",
"sourceTaxonKey": 104051993
}
]
}
Hope it helps!
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.