Skip to content

Commit

Permalink
OGC Connected Systems API (geopython#928)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
ChainReaction31 authored Jun 11, 2024
1 parent 6dfa506 commit 4633c61
Show file tree
Hide file tree
Showing 6 changed files with 1,762 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/source/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ OGC API Support
+--------------------------------------------------------------------------------------+------------+
| `OGC API - Processes - Part 1: Core`_ | 1.0 |
+--------------------------------------------------------------------------------------+------------+
| `OGC API - Connected Systems - Part 1: Feature Resources`_ | draft |
+--------------------------------------------------------------------------------------+------------+
| `OGC API - Connected Systems - Part 2: Dynamic Data`_ | draft |
+--------------------------------------------------------------------------------------+------------+

.. _`OGC WMS`: https://www.opengeospatial.org/standards/wms
.. _`OGC WFS`: https://www.opengeospatial.org/standards/wfs
Expand Down Expand Up @@ -97,4 +101,6 @@ OGC API Support
.. _`OGC API - Features - Part 4: Create, Replace, Update and Delete`: https://docs.ogc.org/DRAFTS/20-002.html
.. _`OGC API - Coverages - Part 1: Core`: https://docs.ogc.org/DRAFTS/19-087.html
.. _`OGC API - Processes - Part 1: Core`: https://docs.ogc.org/is/18-062r2/18-062r2.html
.. _`OGC API - Connected Systems - Part 1: Feature Resources`: https://docs.ogc.org/DRAFTS/23-001r0.html
.. _`OGC API - Connected Systems - Part 2: Dynamic Data`: https://docs.ogc.org/DRAFTS/23-002r0.html
.. _`OpenSearch`: https://github.com/dewitt/opensearch
80 changes: 80 additions & 0 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,86 @@ OGC API - Environmental Data Retrieval - Part 1: Core 1.0
>>> icoads_sst = m.collection('icoads-sst')
>>> data = e.query_data('icoads_sst', 'position', coords='POINT(-75 45)', parameter_names=['SST', 'AIRT'])
OGC API - Connected Systems - Part 1: Feature Resources & Part 2: Dynamic Data
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. note::
The library covers all of parts 1 and 2, the example below is a short overview of the functionality.
All CRUD operations are performed in a very similar manner. Please see the Connected Systems API docs
for the full lists of properties, encoding requirements and expected responses.

.. code-block:: python
>>> from owslib.ogcapi.connectedsystems import Systems, Datastreams, Observations
>>> s = Systems('http://localhost:5000', auth=('user', 'password'), headers={'Content-Type': 'application/sml+json'})
>>> ds = Datastreams('http://localhost:5000', auth=('user', 'password'), headers={'Content-Type': 'application/json'})
>>> obs = Observations('http://localhost:5000', auth=('user', 'password'), headers={'Content-Type': 'application/json'})
# insert a new system, datastream and observation
>>> system_info = {
>>> "type": "SimpleProcess",
>>> "uniqueId": "urn:osh:sensor:testsmlsensor:001",
>>> "label": "Test SML Sensor",
>>> "description": "A Sensor created from an SML document",
>>> "definition": "http://www.w3.org/ns/ssn/Sensor"
>>> }
>>> ds_definition = {
>>> "name": "Test Datastream",
>>> "outputName": "Test Output #1",
>>> "schema": {
>>> "obsFormat": "application/swe+json",
>>> "encoding": {
>>> "type": "JSONEncoding",
>>> "vectorAsArrays": False
>>> },
>>> "recordSchema": {
>>> "type": "DataRecord",
>>> "label": "Test Datastream Record",
>>> "updatable": False,
>>> "optional": False,
>>> "definition": "http://test.com/Record",
>>> "fields": [
>>> {
>>> "type": "Time",
>>> "label": "Test Datastream Time",
>>> "updatable": False,
>>> "optional": False,
>>> "definition": "http://test.com/Time",
>>> "name": "timestamp",
>>> "uom": {
>>> "href": "http://test.com/TimeUOM"
>>> }
>>> },
>>> {
>>> "type": "Boolean",
>>> "label": "Test Datastream Boolean",
>>> "updatable": False,
>>> "optional": False,
>>> "definition": "http://test.com/Boolean",
>>> "name": "testboolean"
>>> }
>>> ]
>>> }
>>> }
>>> }
>>> observation = {
>>> "phenomenonTime": the_time,
>>> "resultTime": the_time,
>>> "result": {
>>> "timestamp": datetime.now().timestamp() * 1000,
>>> "testboolean": True
>>> }
>>> }
>>> s.create_system(system_info)
>>> system_id = s.resource_headers['Location'][0].split('/')[-1]
>>> ds.create_datastream(system_id, ds_definition)
>>> ds_id = ds.resource_headers['Location'][0].split('/')[-1]
>>> obs.create_observation(ds_id, observation)
>>> obs_id = obs.resource_headers['Location'][0].split('/')[-1]
>>> # retrieve the observations of our datastream
>>> observations = obs.get_observations(ds_id)['items']
>>>
WCS
---
Expand Down
2 changes: 1 addition & 1 deletion owslib/ogcapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _request(self, method: str = 'GET', path: str = None,
response = http_post(url, headers=self.headers, request=data,
auth=self.auth)
elif method == 'PUT':
response = http_put(url, data=data, auth=self.auth)
response = http_put(url, headers=self.headers, data=data, auth=self.auth)
elif method == 'DELETE':
response = http_delete(url, auth=self.auth)

Expand Down
Loading

0 comments on commit 4633c61

Please sign in to comment.