Biodiversity API#
The helpers shared by the four biodiversity backends (gbif, obis, wdpa, iucn). For how to use them, see
Biodiversity usage.
Geometry#
earthlens.biodiversity.wkt_from_bbox(space)
#
Build a counter-clockwise WKT polygon from a spatial extent's bbox.
SpatialExtent exposes the bbox edges as .west/.south/.east/.north but
has no .wkt(), so the cluster builds the geometry= filter the GBIF /
OBIS / WDPA APIs accept here. shapely.geometry.box emits a
counter-clockwise ring, which GBIF requires.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
SpatialExtent
|
A spatial extent exposing |
required |
Returns:
| Type | Description |
|---|---|
str
|
A |
Examples:
- Build the WKT for a small box:
Source code in libs/core/src/earthlens/biodiversity/_helpers.py
Occurrence conversion#
earthlens.biodiversity.occurrences_to_fc(records, *, lat_field, lon_field, columns)
#
Map occurrence rows to a points FeatureCollection (EPSG:4326).
Accepts both shapes the cluster produces: a list[dict] of records (GBIF's
occ.search()["results"]) or a pandas.DataFrame (the value pyobis's
.execute() returns). The output is one feature per row, restricted and
ordered to columns with their declared dtypes, plus a geometry column
of shapely.Point(lon, lat). A row whose latitude or longitude is missing
gets a null geometry rather than an invalid POINT (nan nan) that would
corrupt a written file. An empty input yields an empty FeatureCollection
carrying exactly columns, so the result type is identical whether or not
the query matched anything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
records
|
Iterable[Mapping] | DataFrame
|
Occurrence rows as a |
required |
lat_field
|
str
|
Name of the latitude column (e.g. |
required |
lon_field
|
str
|
Name of the longitude column (e.g. |
required |
columns
|
Mapping[str, str]
|
Ordered mapping of output column name to pandas dtype; the result carries exactly these attribute columns. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FeatureCollection |
FeatureCollection
|
One feature per row, CRS |
Source code in libs/core/src/earthlens/biodiversity/_helpers.py
Licensing#
earthlens.biodiversity.LicenseWarning
#
Bases: UserWarning
Warns that a downloaded result carries license obligations.
Emitted by warn_license when a result's license is non-commercial
(CC-BY-NC), share-alike, or otherwise restricts redistribution (the
custom Protected Planet / IUCN Red List terms). A downstream commercial
user must be told the obligation rides along with the data rather than
discovering it silently.
Promoted here from the Overture backend so every biodiversity source — and
Overture — raises the same warning class; earthlens.overture._helpers
re-exports it for backward compatibility.
Source code in libs/core/src/earthlens/biodiversity/_helpers.py
earthlens.biodiversity.warn_license(license_id, label, *, detail=None)
#
Emit a LicenseWarning when a result's license is restrictive.
No-ops for permissive licenses (CC0, CC-BY) so a caller can pass every
record's license unconditionally. detail appends a source-specific
obligation to the message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
license_id
|
str
|
The license id/label on the result (e.g. |
required |
label
|
str
|
A short source/dataset label for the message (e.g. |
required |
detail
|
str | None
|
Optional source-specific obligation appended to the message. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
|