Skip to content

Commit d217f4e

Browse files
authored
Merge pull request #133 from geopython/issue-113
add OWSLib client exercise (#113)
2 parents 06b66c4 + 37fecf8 commit d217f4e

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

workshop/content/docs/publishing/ogcapi-edr.md

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -65,41 +65,46 @@ Let's try publishing some ICOADS data via the EDR xarray plugin. The sample ICOA
6565

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

68-
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:
68+
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
69+
that there is a `parameter_names' key that describes EDR parameter names for the collection queries.
6970

70-
# Client access
71+
### OWSLib - Advanced
7172

72-
!!! question "Interact with OGC API - Environmental Data Retrieval via Python requests"
73+
[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.
74+
75+
!!! question "Interact with OGC API - Environmental Data Retrieval via OWSLib"
7376

7477
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).
7578

7679
<div class="termy">
7780
```bash
78-
pip3 install requests
79-
```
81+
pip3 install owslib
82+
```
8083
</div>
8184

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

83-
Currently there is limited client support for EDR. The example below provides a generic workflow using the [Python requests library](https://requests.readthedocs.io):
84-
85-
<div class="termy">
86-
```python
87-
>>> import requests
88-
>>> collection = requests.get('http://localhost:5000/collections/icoads-sst').json()
89-
>>> collection['id']
90-
'icoads-sst'
91-
>>> collection['title']
92-
'International Comprehensive Ocean-Atmosphere Data Set (ICOADS)'
93-
>>> collection['description']
94-
'International Comprehensive Ocean-Atmosphere Data Set (ICOADS)'
95-
>>> collection['parameter-names'].keys()
96-
dict_keys(['SST', 'AIRT', 'UWND', 'VWND'])
97-
>>> params = {'coords': 'POINT(-28 14)', 'parameter-name': 'SST'}
98-
>>> position_query = requests.get('http://localhost:5000/collections/icoads-sst/position', params=params).json()
99-
>>> position_query['ranges']['SST']['values']
100-
[26.755414962768555, 26.303892135620117, 26.512916564941406, 26.799564361572266, 27.48826026916504, 28.04759979248047, 28.745832443237305, 28.5635986328125, 28.272104263305664, 28.526521682739258, 28.25160026550293, 27.074399948120117]
101-
```
102-
</div>
87+
<div class="termy">
88+
```python
89+
>>> from owslib.ogcapi.edr import EnvironmentalDataRetrieval
90+
>>> w = EnvironmentalDataRetrieval('https://demo.pygeoapi.io/master')
91+
>>> w.url
92+
'https://demo.pygeoapi.io/master'
93+
>>> api = w.api() # OpenAPI document
94+
>>> collections = w.collections()
95+
>>> len(collections['collections'])
96+
13
97+
>>> icoads_sst = w.collection('icoads-sst')
98+
>>> icoads_sst['parameter-names'].keys()
99+
dict_keys(['SST', 'AIRT', 'UWND', 'VWND'])
100+
>>> data = w.query_data('icoads_sst', 'position', coords='POINT(-75 45)', parameter_names=['SST', 'AIRT'])
101+
>>> data # CoverageJSON data
102+
```
103+
</div>
104+
105+
!!! note
106+
107+
See the official [OWSLib documentation](https://owslib.readthedocs.io/en/latest/usage.html#ogc-api) for more examples.
103108

104109
# Summary
105110

workshop/content/docs/publishing/ogcapi-features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ QGIS is one of the first GIS Desktop clients which added support for OGC API - F
249249
'https://demo.pygeoapi.io/master'
250250
>>> conformance = w.conformance()
251251
{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']}
252-
>>> api = w.api() # OpenAPI document/
252+
>>> api = w.api() # OpenAPI document
253253
>>> collections = w.collections()
254254
>>> len(collections['collections'])
255255
13

0 commit comments

Comments
 (0)