diff --git a/README.md b/README.md index c567901..63c4c97 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,10 @@ This repository contains the edr-pydantic Python package. It provides [Pydantic] for the [OGC Environmental Data Retrieval (EDR) API](https://ogcapi.ogc.org/edr/). This can, for example, be used to help develop an EDR API using FastAPI. +## EDR GeoJSON +The EDR spec adds [optional fields](https://docs.ogc.org/is/19-086r4/19-086r4.html#toc9) to GeoJSON to help the user discover EDR resources. Therefore, there is an EDR Feature collection model in this repository which is a limited implementation of the [EDRFeatureCollection implementation](https://schemas.opengis.net/ogcapi/edr/1.1/openapi/schemas/edr-geojson/edrFeatureCollectionGeoJSON.yaml). The model extends [GeoJSON Pydantic](https://github.com/developmentseed/geojson-pydantic) by adding the optional properties. + + ## Install ```shell pip install edr-pydantic @@ -185,6 +189,7 @@ This library is used to build an OGC Environmental Data Retrieval (EDR) API, ser Help is wanted in the following areas to fully implement the EDR spec: * See TODOs in code listing various small inconsistencies in the spec * In various places there could be more validation on content +* In the future all the [EDR GeoJSON schemas](https://schemas.opengis.net/ogcapi/edr/1.1/openapi/schemas/edr-geojson/) should be in this repository. ## License diff --git a/pyproject.toml b/pyproject.toml index fc3dab1..3faf384 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,8 +19,8 @@ classifiers = [ "Topic :: Scientific/Engineering :: GIS", "Typing :: Typed", ] -version = "0.2.1" -dependencies = ["pydantic>=2.3,<3"] +version = "0.3.0" +dependencies = ["pydantic>=2.3,<3", "geojson-pydantic>1.0,<2.0", "covjson-pydantic>=0.2.1,<0.3.0"] [project.optional-dependencies] test = ["pytest", "pytest-cov"] diff --git a/src/edr_pydantic/edr_feature_collection.py b/src/edr_pydantic/edr_feature_collection.py new file mode 100644 index 0000000..d58fa68 --- /dev/null +++ b/src/edr_pydantic/edr_feature_collection.py @@ -0,0 +1,10 @@ +from typing import Dict +from typing import Optional + +from covjson_pydantic.parameter import Parameter # type: ignore +from edr_pydantic.base_model import EdrBaseModel +from geojson_pydantic import FeatureCollection # type: ignore + + +class EDRFeatureCollection(EdrBaseModel, FeatureCollection): + parameters: Optional[Dict[str, Parameter]] = None diff --git a/tests/test_data/edr-geojson-feature-collection.json b/tests/test_data/edr-geojson-feature-collection.json new file mode 100644 index 0000000..b189776 --- /dev/null +++ b/tests/test_data/edr-geojson-feature-collection.json @@ -0,0 +1,112 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + 5.1797, + 52.0989, + 1.9 + ] + }, + "properties": { + "name": "DE BILT AWS", + "parameter-name": [ + "air_temperature_1.5_maximum_PT10M", + "dew_point_temperature_1.5_mean_PT1M", + "duration_of_sunshine_2.0_point_PT0S", + "wind_speed_10_mean_PT10M" + ] + }, + "id": "06260" + } + ], + "parameters": { + "tx_dryb_10": { + "type": "Parameter", + "description": { + "en": "Temperature, air, maximum, 10" + }, + "observedProperty": { + "id": "https://vocab.nerc.ac.uk/standard_name/air_temperature", + "label": { + "en": "Air temperature maximum" + } + }, + "unit": { + "label": { + "en": "degree Celsius" + }, + "symbol": { + "value": "°C", + "type": "http://www.opengis.net/def/uom/UCUM/" + } + } + }, + "t_dewp_10": { + "type": "Parameter", + "description": { + "en": "Temperature air dewpoint 10" + }, + "observedProperty": { + "id": "https://vocab.nerc.ac.uk/standard_name/dew_point_temperature", + "label": { + "en": "Dew Point Temperature" + } + }, + "unit": { + "label": { + "en": "degree Celsius" + }, + "symbol": { + "value": "°C", + "type": "http://www.opengis.net/def/uom/UCUM/" + } + } + }, + "sq_10": { + "type": "Parameter", + "description": { + "en": "Sunshine duration, duration derived from radiation, 10" + }, + "observedProperty": { + "id": "https://vocab.nerc.ac.uk/standard_name/duration_of_sunshine", + "label": { + "en": "Sunshine duration" + } + }, + "unit": { + "label": { + "en": "minute" + }, + "symbol": { + "value": "min", + "type": "http://www.opengis.net/def/uom/UCUM/" + } + } + }, + "ff_10m_10": { + "type": "Parameter", + "description": { + "en": "Wind, speed, average, converted to 10 metres, 10" + }, + "observedProperty": { + "id": "https://vocab.nerc.ac.uk/standard_name/wind_speed", + "label": { + "en": "wind_speed_10_mean_PT10M" + } + }, + "unit": { + "label": { + "en": "metre per second" + }, + "symbol": { + "value": "m/s", + "type": "http://www.opengis.net/def/uom/UCUM/" + } + } + } + } +} diff --git a/tests/test_edr.py b/tests/test_edr.py index 0376f71..cf06bd6 100644 --- a/tests/test_edr.py +++ b/tests/test_edr.py @@ -5,6 +5,7 @@ from edr_pydantic.capabilities import LandingPageModel from edr_pydantic.collections import Collections from edr_pydantic.collections import Instance +from edr_pydantic.edr_feature_collection import EDRFeatureCollection from edr_pydantic.unit import Unit from pydantic import ValidationError @@ -13,6 +14,7 @@ ("doc-example-collections.json", Collections), ("simple-instance.json", Instance), ("landing-page.json", LandingPageModel), + ("edr-geojson-feature-collection.json", EDRFeatureCollection), ]