Skip to content

Commit

Permalink
fixup! fixup! Issue #114/#211/#197 from_geodataframe: add dummy cube …
Browse files Browse the repository at this point in the history
…when no properties are specified
  • Loading branch information
soxofaan committed Aug 4, 2023
1 parent 2c89fb0 commit 477a301
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions openeo_driver/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,9 @@ class DriverVectorCube:
DIM_PROPERTIES = "properties"
COLUMN_SELECTION_ALL = "all"
COLUMN_SELECTION_NUMERICAL = "numerical"
VECTOR_CUBE_DUMMY = "vector_cube_dummy"

# Xarray cube attribute to indicate that it is a dummy cube
CUBE_ATTR_VECTOR_CUBE_DUMMY = "vector_cube_dummy"

def __init__(
self,
Expand Down Expand Up @@ -325,7 +327,7 @@ def from_geodataframe(
data=numpy.full(shape=[data.shape[0]], fill_value=numpy.nan),
dims=[cls.DIM_GEOMETRIES],
coords={cls.DIM_GEOMETRIES: data.geometry.index.to_list()},
attrs={cls.VECTOR_CUBE_DUMMY: True},
attrs={cls.CUBE_ATTR_VECTOR_CUBE_DUMMY: True},
)
return cls(geometries=data, cube=cube)

Expand Down Expand Up @@ -419,7 +421,7 @@ def _as_geopandas_df(
"""Join geometries and cube as a geopandas dataframe"""
# TODO: avoid copy?
df = self._geometries.copy(deep=True)
if self._cube is not None and not self._cube.attrs.get(self.VECTOR_CUBE_DUMMY):
if self._cube is not None and not self._cube.attrs.get(self.CUBE_ATTR_VECTOR_CUBE_DUMMY):
assert self._cube.dims[0] == self.DIM_GEOMETRIES
# TODO: better way to combine cube with geometries
# Flatten multiple (non-geometry) dimensions from cube to new properties in geopandas dataframe
Expand Down Expand Up @@ -514,7 +516,7 @@ def to_legacy_save_result(self) -> Union["AggregatePolygonResult", "JSONResult"]
# TODO: eliminate these legacy, non-standard formats?
from openeo_driver.save_result import AggregatePolygonResult, JSONResult

if self._cube is None:
if self._cube is None or self._cube.attrs.get(self.CUBE_ATTR_VECTOR_CUBE_DUMMY):
# No cube: no real data to return (in legacy style), so let's just return a `null` per geometry.
return JSONResult(data=[None] * self.geometry_count())

Expand Down

0 comments on commit 477a301

Please sign in to comment.