Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion openeo_driver/delayed_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,6 @@ def _read_geojson_crs(geojson: Dict) -> pyproj.CRS:
crs = geojson.get("crs", {}).get("properties", {}).get("name")
return pyproj.CRS("epsg:4326") if crs is None else pyproj.CRS(crs)

def to_driver_vector_cube(self):
def to_driver_vector_cube(self) -> DriverVectorCube:
gdf = self.as_geodataframe()
return DriverVectorCube.from_geodataframe(gdf, dimension_name="bands")
10 changes: 6 additions & 4 deletions openeo_driver/save_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import xarray

from openeo.metadata import CollectionMetadata
from typeguard import typechecked

from openeo_driver.datacube import DriverDataCube, DriverVectorCube, DriverMlModel
from openeo_driver.datastructs import StacAsset
from openeo_driver.delayed_vector import DelayedVector
Expand Down Expand Up @@ -299,12 +301,12 @@ class AggregatePolygonResult(JSONResult): # TODO: if it supports NetCDF and CSV
"""

# TODO #71 #114 EP-3981 port this to proper vector cube support

@typechecked
def __init__(
self,
timeseries: Dict[int, List[List[Any]]],
timeseries: Optional[Dict[str, List[List[Any]]]],
regions: Union[GeometryCollection, DriverVectorCube],
metadata: CollectionMetadata = None,
metadata: Optional[CollectionMetadata] = None,
):
"""
:param timeseries: {timestamp: [geometries, bands]}
Expand Down Expand Up @@ -1010,7 +1012,7 @@ def to_save_result(data: Any, format: Optional[str] = None, options: Optional[di
return JSONResult(data.geojson, format="geojson", options=options)
else:
data = data.to_driver_vector_cube()
elif isinstance(data, DriverDataCube):
if isinstance(data, DriverDataCube):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JeroenVerstraelen I found this while checking with mypy. This makes sure the 'data' used in the object that is returned

return ImageCollectionResult(data, format=format, options=options)
elif isinstance(data, DriverVectorCube):
return VectorCubeResult(cube=data, format=format, options=options)
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"pyarrow>=10.0.0",
"jsonschema",
"dirty-equals>=0.6",
"typeguard",
]

typing_require = [
Expand Down
12 changes: 11 additions & 1 deletion tests/test_save_result_parquet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pytest

from openeo_driver.datacube import DriverVectorCube
from openeo_driver.save_result import AggregatePolygonSpatialResult
from openeo_driver.delayed_vector import DelayedVector
from openeo_driver.save_result import AggregatePolygonSpatialResult, to_save_result, VectorCubeResult
from .data import get_path

import geopandas as gpd
Expand Down Expand Up @@ -48,3 +49,12 @@ def test_write_driver_vector_cube_to_parquet(tmp_path):
vector_cube.write_assets(tmp_path / "dummy", format="Parquet")

assert gpd.read_parquet(tmp_path / "vectorcube.parquet").shape == (2, 3)


def test_write_delayed_vector_cube_to_parquet(tmp_path):
dv = DelayedVector(str(get_path("geojson/FeatureCollection02.json")))
vector_cube = to_save_result(dv, format="parquet")
assert isinstance(vector_cube, VectorCubeResult)
vector_cube.write_assets(tmp_path / "dummy")
# TODO: Why are id and pop columns missing here?
assert gpd.read_parquet(tmp_path / "vectorcube.parquet").shape == (2, 1)