Skip to content

Commit 477a301

Browse files
committed
fixup! fixup! Issue #114/#211/#197 from_geodataframe: add dummy cube when no properties are specified
1 parent 2c89fb0 commit 477a301

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

openeo_driver/datacube.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ class DriverVectorCube:
224224
DIM_PROPERTIES = "properties"
225225
COLUMN_SELECTION_ALL = "all"
226226
COLUMN_SELECTION_NUMERICAL = "numerical"
227-
VECTOR_CUBE_DUMMY = "vector_cube_dummy"
227+
228+
# Xarray cube attribute to indicate that it is a dummy cube
229+
CUBE_ATTR_VECTOR_CUBE_DUMMY = "vector_cube_dummy"
228230

229231
def __init__(
230232
self,
@@ -325,7 +327,7 @@ def from_geodataframe(
325327
data=numpy.full(shape=[data.shape[0]], fill_value=numpy.nan),
326328
dims=[cls.DIM_GEOMETRIES],
327329
coords={cls.DIM_GEOMETRIES: data.geometry.index.to_list()},
328-
attrs={cls.VECTOR_CUBE_DUMMY: True},
330+
attrs={cls.CUBE_ATTR_VECTOR_CUBE_DUMMY: True},
329331
)
330332
return cls(geometries=data, cube=cube)
331333

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

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

0 commit comments

Comments
 (0)