From 3976d65b40638c2aa4924aa32b5beef49af8c449 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Sun, 29 Sep 2024 09:21:20 -0400 Subject: [PATCH 1/2] OAProc: add support for process execution --- docs/source/usage.rst | 5 +++ owslib/ogcapi/processes.py | 41 +++++++++++++++++++++++-- tests/test_ogcapi_processes_pygeoapi.py | 15 +++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 00ab05e8..da839e04 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -341,6 +341,11 @@ OGC API - Processes - Part 1: Core 1.0 >>> hello_world['title'] 'Hello World' + >>> result = p.execute('hello-world', inputs={'name': 'World', 'message': 'Testing from OWSLib'}) + >>> result + {'outputs': [{'id': 'echo', 'value': 'Hello World! Testing from OWSLib'}]} + + OGC API - Maps - Part 1: Core 1.0 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/owslib/ogcapi/processes.py b/owslib/ogcapi/processes.py index f5cd50f5..5f6a12d2 100644 --- a/owslib/ogcapi/processes.py +++ b/owslib/ogcapi/processes.py @@ -34,13 +34,50 @@ def processes(self) -> list: def process(self, process_id: str) -> dict: """ - implements /processs/{processId} + implements /processses/{processId} @type process_id: string @param process_id: id of process - @returns: `dict` of process desceription + @returns: `dict` of process description """ path = f'processes/{process_id}' return self._request(path=path) + + def execute(self, process_id: str, inputs: dict, outputs: dict = {}, + response: str = 'document', async_: bool = False) -> dict: + """ + implements /processes/{processId}/execution + + @type process_id: string + @param process_id: id of process + @type data: string + @param data: request payload + @type inputs: inputs + @param inputs: input parameters + @type outputs: outputs + @param outputs: output parameters + @type async_: bool + @param outputs: whether to execute request in asychronous mode + + @returns: `dict` of response or URL reference to job + """ + + data = {} + + if inputs: + data['inputs'] = inputs + if outputs: + data['outputs'] = outputs + + data['response'] = response + + if async_: + self.headers['Prefer'] = 'respond-async' + else: + self.headers['Prefer'] = 'respond-sync' + + path = f'processes/{process_id}/execution' + + return self._request(method='POST', path=path, data=data) diff --git a/tests/test_ogcapi_processes_pygeoapi.py b/tests/test_ogcapi_processes_pygeoapi.py index 680aef2b..6d53bd89 100644 --- a/tests/test_ogcapi_processes_pygeoapi.py +++ b/tests/test_ogcapi_processes_pygeoapi.py @@ -34,3 +34,18 @@ def test_ogcapi_processes_pygeoapi(): hello_world = p.process('hello-world') assert hello_world['id'] == 'hello-world' assert hello_world['title'] == 'Hello World' + + inputs = { + 'name': 'World', + 'message': 'Testing from OWSLib' + } + + execution = p.execute('hello-world', inputs=inputs) + + assert execution['outputs'][0]['id'] == 'echo' + assert execution['outputs'][0]['value'] == 'Hello World! Testing from OWSLib' # noqa + + execution = p.execute('hello-world', inputs=inputs, response='raw') + + assert execution['id'] == 'echo' + assert execution['value'] == 'Hello World! Testing from OWSLib' From 306c3482e0de5dd5f80374af4fe1632c1ab8cd05 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Sun, 29 Sep 2024 09:52:53 -0400 Subject: [PATCH 2/2] fix WFS 1.1.0 logging --- owslib/feature/wfs110.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/owslib/feature/wfs110.py b/owslib/feature/wfs110.py index 92066e20..882ceaab 100644 --- a/owslib/feature/wfs110.py +++ b/owslib/feature/wfs110.py @@ -48,6 +48,8 @@ def get_namespaces(): namespaces = get_namespaces() +LOGGER = logging.getLogger(__name__) + class WebFeatureService_1_1_0(WebFeatureService_): """Abstraction for OGC Web Feature Service (WFS).