Skip to content

Commit d5faa12

Browse files
authored
Merge pull request #5 from geopython/ogcapi-records
Ogcapi records
2 parents a6a4313 + c952754 commit d5faa12

7 files changed

Lines changed: 90 additions & 6 deletions

File tree

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ permissions:
2626

2727
jobs:
2828
build:
29-
runs-on: ubuntu-20.04
29+
runs-on: ubuntu-24.04
3030
steps:
3131
- name: Check out repository
3232
uses: actions/checkout@v4

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ on:
1919

2020
jobs:
2121
test:
22-
runs-on: ubuntu-20.04
22+
runs-on: ubuntu-24.04
2323
strategy:
2424
matrix:
2525
python-version: ['3.10']

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ git push && git push --tags
337337
- [Creodias OpenSearch](https://finder.creodias.eu/resto/api/collections/describe.xml)
338338
- [Creodias Sentinel1](https://finder.creodias.eu/resto/api/collections/Sentinel1/describe.xml)
339339
- [Creodias Sentinel2](https://finder.creodias.eu/resto/api/collections/Sentinel2/describe.xml)
340+
- [EOEPCA+ develop resource catalogue](https://resource-catalogue.apx.develop.eoepca.org/collections)
340341

341342
### Inspiration
342343

poetry.lock

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ lxml = "^5.3.0"
2020
geojson-pydantic = "^1.1.2"
2121
rio-stac = "^0.10.1"
2222
rasterio = "^1.4.3"
23+
owslib = "^0.34.1"
2324

2425

2526
[tool.poetry.group.dev.dependencies]

src/eodm/extract.py

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Iterator, Optional
22

33
import pystac_client
4+
from owslib.ogcapi.records import Records
45
from pystac import Collection, Item
56

67
from .opensearch import OpenSearchClient, OpenSearchFeature
@@ -59,9 +60,7 @@ def extract_stac_api_collections(url: str) -> Iterator[Collection]:
5960

6061

6162
def extract_opensearch_features(
62-
url: str,
63-
product_types: list[str],
64-
limit: int = 0,
63+
url: str, product_types: list[str], limit: int = 0
6564
) -> Iterator[OpenSearchFeature]:
6665
"""Extracts OpenSearch Features from an OpenSearch API
6766
@@ -83,3 +82,53 @@ def extract_opensearch_features(
8382
if limit and i >= limit:
8483
break
8584
yield feature
85+
86+
87+
def extract_ogcapi_records_catalogs(url: str) -> Iterator[dict]:
88+
"""Extracts OGC API Records from an OGC API Records endpoint
89+
90+
Args:
91+
url (str): Link to OGC API Records endpoint
92+
93+
Yields:
94+
Iterator[Item]: OGC API Records Catalogs(collections)
95+
"""
96+
97+
records = Records(url)
98+
for record in records.collections()["collections"]:
99+
yield record
100+
101+
102+
def extract_ogcapi_records(
103+
url: str,
104+
catalog_ids: list[str],
105+
datetime_interval: str | None = None,
106+
bbox: list[float] | None = None,
107+
filter: str | None = None,
108+
limit: int | None = None,
109+
) -> Iterator[dict]:
110+
"""Extracts OGC API Records from an OGC API Records endpoint
111+
112+
Args:
113+
url (str): Link to OGC API Records endpoint
114+
catalog_ids (list[str]): List of catalog/collection IDs to search for
115+
datetime_interval (str | None, optional): Datetime interval to search. ISO8601
116+
datetime or interval Defaults to None.
117+
bbox (list[float, float, float, float] | None, optional): Bounding box to search.
118+
filter (str, optional): CQL filter to apply. Defaults to None.
119+
limit (int | None, optional): Limit query to given number. Defaults to None.
120+
121+
Yields:
122+
Iterator[Item]: OGC API Records Items
123+
"""
124+
125+
records = Records(url)
126+
for catalog_id in catalog_ids:
127+
for record in records.collection_items(
128+
catalog_id,
129+
bbox=bbox,
130+
datetime_=datetime_interval,
131+
filter=filter,
132+
limit=limit,
133+
)["features"]:
134+
yield record

tests/test_ogcapi_records.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from eodm.extract import extract_ogcapi_records, extract_ogcapi_records_catalogs
2+
3+
4+
def test_extract_ogcapi_records_catalogs():
5+
url = "https://resource-catalogue.apx.develop.eoepca.org"
6+
for i in extract_ogcapi_records_catalogs(url):
7+
assert i["type"] == "catalog"
8+
9+
10+
def test_extract_ogcapi_records():
11+
url = "https://resource-catalogue.apx.develop.eoepca.org"
12+
catalog_ids = ["S2MSI1C"]
13+
datetime_interval = "2018-01-01/2020-01-01"
14+
bbox = [15.7308, 47.4577, 17.2709, 48.2459]
15+
for i in extract_ogcapi_records(url, catalog_ids, datetime_interval, bbox):
16+
assert i["type"] == "Feature"

0 commit comments

Comments
 (0)