Skip to content

Commit

Permalink
Merge pull request #133 from geopython/issue-113
Browse files Browse the repository at this point in the history
add OWSLib client exercise (#113)
  • Loading branch information
doublebyte1 authored Dec 19, 2023
2 parents 06b66c4 + 37fecf8 commit d217f4e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
55 changes: 30 additions & 25 deletions workshop/content/docs/publishing/ogcapi-edr.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,41 +65,46 @@ Let's try publishing some ICOADS data via the EDR xarray plugin. The sample ICOA

Save the configuration and restart Docker Compose. Navigate to <http://localhost:5000/collections> to evaluate whether the new dataset has been published.

At first glance, the `icoads-sst` collection appears as a normal OGC API - Coverages collection. Let's look a bit closer at the collection description:
At first glance, the `icoads-sst` collection appears as a normal OGC API - Coverages collection. Look a bit closer at the collection description, and notice
that there is a `parameter_names' key that describes EDR parameter names for the collection queries.

# Client access
### OWSLib - Advanced

!!! question "Interact with OGC API - Environmental Data Retrieval via Python requests"
[OWSLib](https://owslib.readthedocs.io) is a Python library to interact with OGC Web Services and supports a number of OGC APIs including OGC API - Environmental Data Retrieval.

!!! question "Interact with OGC API - Environmental Data Retrieval via OWSLib"

If you do not have Python installed, consider running this exercise in a Docker container. See the [Setup Chapter](../setup.md#using-docker-for-python-clients).

<div class="termy">
```bash
pip3 install requests
```
pip3 install owslib
```
</div>

Then start a Python console session with: `python3` (stop the session by typing `exit()`).

Currently there is limited client support for EDR. The example below provides a generic workflow using the [Python requests library](https://requests.readthedocs.io):

<div class="termy">
```python
>>> import requests
>>> collection = requests.get('http://localhost:5000/collections/icoads-sst').json()
>>> collection['id']
'icoads-sst'
>>> collection['title']
'International Comprehensive Ocean-Atmosphere Data Set (ICOADS)'
>>> collection['description']
'International Comprehensive Ocean-Atmosphere Data Set (ICOADS)'
>>> collection['parameter-names'].keys()
dict_keys(['SST', 'AIRT', 'UWND', 'VWND'])
>>> params = {'coords': 'POINT(-28 14)', 'parameter-name': 'SST'}
>>> position_query = requests.get('http://localhost:5000/collections/icoads-sst/position', params=params).json()
>>> position_query['ranges']['SST']['values']
[26.755414962768555, 26.303892135620117, 26.512916564941406, 26.799564361572266, 27.48826026916504, 28.04759979248047, 28.745832443237305, 28.5635986328125, 28.272104263305664, 28.526521682739258, 28.25160026550293, 27.074399948120117]
```
</div>
<div class="termy">
```python
>>> from owslib.ogcapi.edr import EnvironmentalDataRetrieval
>>> w = EnvironmentalDataRetrieval('https://demo.pygeoapi.io/master')
>>> w.url
'https://demo.pygeoapi.io/master'
>>> api = w.api() # OpenAPI document
>>> collections = w.collections()
>>> len(collections['collections'])
13
>>> icoads_sst = w.collection('icoads-sst')
>>> icoads_sst['parameter-names'].keys()
dict_keys(['SST', 'AIRT', 'UWND', 'VWND'])
>>> data = w.query_data('icoads_sst', 'position', coords='POINT(-75 45)', parameter_names=['SST', 'AIRT'])
>>> data # CoverageJSON data
```
</div>

!!! note

See the official [OWSLib documentation](https://owslib.readthedocs.io/en/latest/usage.html#ogc-api) for more examples.

# Summary

Expand Down
2 changes: 1 addition & 1 deletion workshop/content/docs/publishing/ogcapi-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ QGIS is one of the first GIS Desktop clients which added support for OGC API - F
'https://demo.pygeoapi.io/master'
>>> conformance = w.conformance()
{u'conformsTo': [u'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core', u'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/oas30', u'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/html', u'http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson']}
>>> api = w.api() # OpenAPI document/
>>> api = w.api() # OpenAPI document
>>> collections = w.collections()
>>> len(collections['collections'])
13
Expand Down

0 comments on commit d217f4e

Please sign in to comment.