Skip to content

Commit

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

def __init__(
self,
Expand Down Expand Up @@ -324,7 +325,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={"vector_cube_dummy": True},
attrs={cls.VECTOR_CUBE_DUMMY: True},
)
return cls(geometries=data, cube=cube)

Expand Down Expand Up @@ -418,7 +419,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:
if self._cube is not None and not self._cube.attrs.get(self.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
2 changes: 1 addition & 1 deletion tests/test_vectorcube.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_to_internal_json_defaults(self, gdf):
"geometries": {"attrs": {}, "data": [0, 1], "dims": ("geometries",)},
},
"data": [IsNan(), IsNan()],
"attrs": {},
"attrs": {"vector_cube_dummy": True},
},
),
(
Expand Down

0 comments on commit 2c89fb0

Please sign in to comment.