diff --git a/openeo/rest/connection.py b/openeo/rest/connection.py index 5da173ef4..d892d9669 100644 --- a/openeo/rest/connection.py +++ b/openeo/rest/connection.py @@ -37,6 +37,7 @@ from openeo.rest.rest_capabilities import RESTCapabilities from openeo.rest.service import Service from openeo.rest.udp import RESTUserDefinedProcess, Parameter +from openeo.rest.vectorcube import VectorCube from openeo.util import ensure_list, dict_no_none, rfc3339, load_json_resource, LazyLoadCache, \ ContextTimer, str_truncate @@ -899,6 +900,19 @@ def _api_version(self) -> ComparableVersion: # TODO make this a public property (it's also useful outside the Connection class) return self.capabilities().api_version_check + def vectorcube_from_paths(self, paths:List[str], format:str, options:dict={}) -> VectorCube: + """ + Loads one or more files referenced by url or path that is accessible by the backend. + + :param paths: The files to read. + :param format: The file format to read from. It must be one of the values that the server reports as supported input file formats. + :param options: The file format parameters to be used to read the files. Must correspond to the parameters that the server reports as supported parameters for the chosen format. + + :return: A :py:class:`VectorCube`. + """ + graph = PGNode("load_uploaded_files", arguments=dict(paths=paths,format=format,options=options)) + return VectorCube(graph=graph, connection=self) + def datacube_from_process(self, process_id: str, namespace: str = None, **kwargs) -> DataCube: """ Load a data cube from a (custom) process. diff --git a/tests/rest/test_connection.py b/tests/rest/test_connection.py index a7e941b03..a7eda760a 100644 --- a/tests/rest/test_connection.py +++ b/tests/rest/test_connection.py @@ -2402,6 +2402,16 @@ def test_version_info(requests_mock, capabilities, expected): con = Connection(API_URL) assert con.version_info() == expected +def test_vectorcube_from_paths(requests_mock): + requests_mock.get("https://oeo.test/", json={"api_version": "1.1.0"}) + con = Connection(API_URL) + vc = con.vectorcube_from_paths(["mydata.pq"],format="parquet") + assert {'loaduploadedfiles1': {'arguments': {'format': 'parquet', + 'options': {}, + 'paths': ['mydata.pq']}, + 'process_id': 'load_uploaded_files', + 'result': True}} == vc.flat_graph() + class TestExecute: # Dummy process graphs