Skip to content

Commit 4633c61

Browse files
OGC Connected Systems API (#928)
* [CSAPI] add systems * [CSAPI] add procedures and deployments * [CSAPI] add properties and samplingFeatures * [CSAPI] add datastreams and observations * [CSAPI] add controlchannels.py and commands.py * [CSAPI] add systemevents.py and systemhistory.py * [CSAPI] consolidate all files into one * [CSAPI] reorganize sections to fit docs * [CSAPI] add query parameters to methods for part 1 and 2 * [CSAPI] update _request method to use headers for PUTs * [CSAPI] add tests for most parts of CSAPI, fix bugs encountered * move repeatedly referenced data to fixtures in test * fix and annotate remaining possible tests * add a response handler option to and default to PUT, POST, and DELETE methods for more positive control over response results * update tests to take advantage to response handler function data where needed * combine system tests into a single one to remove potential ordering issues * update systems, datastreams observations, and system history tests. Add headers to PUT method in ogcapi base class * update sampling features tests and combine to help ensure repeatability * remove unnecessary print statements in test * remove unused import * remove unused default response handlers * remove redundant observation deletion test and move functionality into comprehensive observation test that cleans up after itself * remove intentionally skipped tests * remove more fixture deps for datastream test, use individual instances in utility functions * rename test_connectedsystems_osh.py to test_ogcapi_connectedsystems_osh.py * add noqa to allow "unused" doc local variable same as parent ogcapi files * add Connected Systems API info to the docs * clean up import order, fix small error in doc example * fix a grammar issue * add readonly tests and skip transactional ones
1 parent 6dfa506 commit 4633c61

File tree

6 files changed

+1762
-2
lines changed

6 files changed

+1762
-2
lines changed

docs/source/features.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ OGC API Support
6666
+--------------------------------------------------------------------------------------+------------+
6767
| `OGC API - Processes - Part 1: Core`_ | 1.0 |
6868
+--------------------------------------------------------------------------------------+------------+
69+
| `OGC API - Connected Systems - Part 1: Feature Resources`_ | draft |
70+
+--------------------------------------------------------------------------------------+------------+
71+
| `OGC API - Connected Systems - Part 2: Dynamic Data`_ | draft |
72+
+--------------------------------------------------------------------------------------+------------+
6973

7074
.. _`OGC WMS`: https://www.opengeospatial.org/standards/wms
7175
.. _`OGC WFS`: https://www.opengeospatial.org/standards/wfs
@@ -97,4 +101,6 @@ OGC API Support
97101
.. _`OGC API - Features - Part 4: Create, Replace, Update and Delete`: https://docs.ogc.org/DRAFTS/20-002.html
98102
.. _`OGC API - Coverages - Part 1: Core`: https://docs.ogc.org/DRAFTS/19-087.html
99103
.. _`OGC API - Processes - Part 1: Core`: https://docs.ogc.org/is/18-062r2/18-062r2.html
104+
.. _`OGC API - Connected Systems - Part 1: Feature Resources`: https://docs.ogc.org/DRAFTS/23-001r0.html
105+
.. _`OGC API - Connected Systems - Part 2: Dynamic Data`: https://docs.ogc.org/DRAFTS/23-002r0.html
100106
.. _`OpenSearch`: https://github.com/dewitt/opensearch

docs/source/usage.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,86 @@ OGC API - Environmental Data Retrieval - Part 1: Core 1.0
363363
>>> icoads_sst = m.collection('icoads-sst')
364364
>>> data = e.query_data('icoads_sst', 'position', coords='POINT(-75 45)', parameter_names=['SST', 'AIRT'])
365365
366+
OGC API - Connected Systems - Part 1: Feature Resources & Part 2: Dynamic Data
367+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
368+
369+
.. note::
370+
The library covers all of parts 1 and 2, the example below is a short overview of the functionality.
371+
All CRUD operations are performed in a very similar manner. Please see the Connected Systems API docs
372+
for the full lists of properties, encoding requirements and expected responses.
373+
374+
.. code-block:: python
375+
376+
>>> from owslib.ogcapi.connectedsystems import Systems, Datastreams, Observations
377+
>>> s = Systems('http://localhost:5000', auth=('user', 'password'), headers={'Content-Type': 'application/sml+json'})
378+
>>> ds = Datastreams('http://localhost:5000', auth=('user', 'password'), headers={'Content-Type': 'application/json'})
379+
>>> obs = Observations('http://localhost:5000', auth=('user', 'password'), headers={'Content-Type': 'application/json'})
380+
# insert a new system, datastream and observation
381+
>>> system_info = {
382+
>>> "type": "SimpleProcess",
383+
>>> "uniqueId": "urn:osh:sensor:testsmlsensor:001",
384+
>>> "label": "Test SML Sensor",
385+
>>> "description": "A Sensor created from an SML document",
386+
>>> "definition": "http://www.w3.org/ns/ssn/Sensor"
387+
>>> }
388+
>>> ds_definition = {
389+
>>> "name": "Test Datastream",
390+
>>> "outputName": "Test Output #1",
391+
>>> "schema": {
392+
>>> "obsFormat": "application/swe+json",
393+
>>> "encoding": {
394+
>>> "type": "JSONEncoding",
395+
>>> "vectorAsArrays": False
396+
>>> },
397+
>>> "recordSchema": {
398+
>>> "type": "DataRecord",
399+
>>> "label": "Test Datastream Record",
400+
>>> "updatable": False,
401+
>>> "optional": False,
402+
>>> "definition": "http://test.com/Record",
403+
>>> "fields": [
404+
>>> {
405+
>>> "type": "Time",
406+
>>> "label": "Test Datastream Time",
407+
>>> "updatable": False,
408+
>>> "optional": False,
409+
>>> "definition": "http://test.com/Time",
410+
>>> "name": "timestamp",
411+
>>> "uom": {
412+
>>> "href": "http://test.com/TimeUOM"
413+
>>> }
414+
>>> },
415+
>>> {
416+
>>> "type": "Boolean",
417+
>>> "label": "Test Datastream Boolean",
418+
>>> "updatable": False,
419+
>>> "optional": False,
420+
>>> "definition": "http://test.com/Boolean",
421+
>>> "name": "testboolean"
422+
>>> }
423+
>>> ]
424+
>>> }
425+
>>> }
426+
>>> }
427+
>>> observation = {
428+
>>> "phenomenonTime": the_time,
429+
>>> "resultTime": the_time,
430+
>>> "result": {
431+
>>> "timestamp": datetime.now().timestamp() * 1000,
432+
>>> "testboolean": True
433+
>>> }
434+
>>> }
435+
>>> s.create_system(system_info)
436+
>>> system_id = s.resource_headers['Location'][0].split('/')[-1]
437+
>>> ds.create_datastream(system_id, ds_definition)
438+
>>> ds_id = ds.resource_headers['Location'][0].split('/')[-1]
439+
>>> obs.create_observation(ds_id, observation)
440+
>>> obs_id = obs.resource_headers['Location'][0].split('/')[-1]
441+
>>> # retrieve the observations of our datastream
442+
>>> observations = obs.get_observations(ds_id)['items']
443+
>>>
444+
445+
366446
367447
WCS
368448
---

owslib/ogcapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def _request(self, method: str = 'GET', path: str = None,
179179
response = http_post(url, headers=self.headers, request=data,
180180
auth=self.auth)
181181
elif method == 'PUT':
182-
response = http_put(url, data=data, auth=self.auth)
182+
response = http_put(url, headers=self.headers, data=data, auth=self.auth)
183183
elif method == 'DELETE':
184184
response = http_delete(url, auth=self.auth)
185185

0 commit comments

Comments
 (0)