Skip to content

Commit b1b5474

Browse files
jdriessoxofaan
authored andcommitted
allow creating a vectorcube from uploaded files
1 parent 9c39c44 commit b1b5474

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

openeo/rest/connection.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from openeo.rest.rest_capabilities import RESTCapabilities
3838
from openeo.rest.service import Service
3939
from openeo.rest.udp import RESTUserDefinedProcess, Parameter
40+
from openeo.rest.vectorcube import VectorCube
4041
from openeo.util import ensure_list, dict_no_none, rfc3339, load_json_resource, LazyLoadCache, \
4142
ContextTimer, str_truncate
4243

@@ -899,6 +900,19 @@ def _api_version(self) -> ComparableVersion:
899900
# TODO make this a public property (it's also useful outside the Connection class)
900901
return self.capabilities().api_version_check
901902

903+
def vectorcube_from_paths(self, paths:List[str], format:str, options:dict={}) -> VectorCube:
904+
"""
905+
Loads one or more files referenced by url or path that is accessible by the backend.
906+
907+
:param paths: The files to read.
908+
:param format: The file format to read from. It must be one of the values that the server reports as supported input file formats.
909+
: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.
910+
911+
:return: A :py:class:`VectorCube`.
912+
"""
913+
graph = PGNode("load_uploaded_files", arguments=dict(paths=paths,format=format,options=options))
914+
return VectorCube(graph=graph, connection=self)
915+
902916
def datacube_from_process(self, process_id: str, namespace: str = None, **kwargs) -> DataCube:
903917
"""
904918
Load a data cube from a (custom) process.

tests/rest/test_connection.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,6 +2402,16 @@ def test_version_info(requests_mock, capabilities, expected):
24022402
con = Connection(API_URL)
24032403
assert con.version_info() == expected
24042404

2405+
def test_vectorcube_from_paths(requests_mock):
2406+
requests_mock.get("https://oeo.test/", json={"api_version": "1.1.0"})
2407+
con = Connection(API_URL)
2408+
vc = con.vectorcube_from_paths(["mydata.pq"],format="parquet")
2409+
assert {'loaduploadedfiles1': {'arguments': {'format': 'parquet',
2410+
'options': {},
2411+
'paths': ['mydata.pq']},
2412+
'process_id': 'load_uploaded_files',
2413+
'result': True}} == vc.flat_graph()
2414+
24052415

24062416
class TestExecute:
24072417
# Dummy process graphs

0 commit comments

Comments
 (0)