@@ -225,6 +225,9 @@ class DriverVectorCube:
225
225
COLUMN_SELECTION_ALL = "all"
226
226
COLUMN_SELECTION_NUMERICAL = "numerical"
227
227
228
+ # Xarray cube attribute to indicate that it is a dummy cube
229
+ CUBE_ATTR_VECTOR_CUBE_DUMMY = "vector_cube_dummy"
230
+
228
231
def __init__ (
229
232
self ,
230
233
geometries : gpd .GeoDataFrame ,
@@ -319,8 +322,14 @@ def from_geodataframe(
319
322
return cls (geometries = geometries_df , cube = cube )
320
323
321
324
else :
322
- # TODO: add a dummy 1D no-data cube?
323
- return cls (geometries = data )
325
+ # Use 1D dummy cube of NaN values
326
+ cube : xarray .DataArray = xarray .DataArray (
327
+ data = numpy .full (shape = [data .shape [0 ]], fill_value = numpy .nan ),
328
+ dims = [cls .DIM_GEOMETRIES ],
329
+ coords = {cls .DIM_GEOMETRIES : data .geometry .index .to_list ()},
330
+ attrs = {cls .CUBE_ATTR_VECTOR_CUBE_DUMMY : True },
331
+ )
332
+ return cls (geometries = data , cube = cube )
324
333
325
334
@classmethod
326
335
def from_fiona (
@@ -412,7 +421,7 @@ def _as_geopandas_df(
412
421
"""Join geometries and cube as a geopandas dataframe"""
413
422
# TODO: avoid copy?
414
423
df = self ._geometries .copy (deep = True )
415
- if self ._cube is not None :
424
+ if self ._cube is not None and not self . _cube . attrs . get ( self . CUBE_ATTR_VECTOR_CUBE_DUMMY ) :
416
425
assert self ._cube .dims [0 ] == self .DIM_GEOMETRIES
417
426
# TODO: better way to combine cube with geometries
418
427
# Flatten multiple (non-geometry) dimensions from cube to new properties in geopandas dataframe
@@ -507,7 +516,7 @@ def to_legacy_save_result(self) -> Union["AggregatePolygonResult", "JSONResult"]
507
516
# TODO: eliminate these legacy, non-standard formats?
508
517
from openeo_driver .save_result import AggregatePolygonResult , JSONResult
509
518
510
- if self ._cube is None :
519
+ if self ._cube is None or self . _cube . attrs . get ( self . CUBE_ATTR_VECTOR_CUBE_DUMMY ) :
511
520
# No cube: no real data to return (in legacy style), so let's just return a `null` per geometry.
512
521
return JSONResult (data = [None ] * self .geometry_count ())
513
522
0 commit comments