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/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). 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'