diff --git a/openeo_driver/datacube.py b/openeo_driver/datacube.py index eaed398f..7edb49db 100644 --- a/openeo_driver/datacube.py +++ b/openeo_driver/datacube.py @@ -217,6 +217,7 @@ class DriverVectorCube: """ DIM_GEOMETRIES = "geometries" DIM_BANDS = "bands" + DIM_PROPERTIES = "properties" FLATTEN_PREFIX = "vc" COLUMN_SELECTION_ALL = "all" COLUMN_SELECTION_NUMERICAL = "numerical" @@ -254,8 +255,7 @@ def from_geodataframe( data: gpd.GeoDataFrame, *, columns_for_cube: Union[List[str], str] = COLUMN_SELECTION_NUMERICAL, - # TODO: change default band name to "properties" (per `load_geojson` spec introduced by https://github.com/Open-EO/openeo-processes/pull/427) - dimension_name: str = DIM_BANDS, + dimension_name: str = DIM_PROPERTIES, ) -> "DriverVectorCube": """ Build a DriverVectorCube from given GeoPandas data frame, @@ -600,7 +600,8 @@ def apply_dimension( if single_run_udf: # Process with single "run_udf" node - if dimension == self.DIM_BANDS and target_dimension is None: + # TODO: check provided dimension with actual dimension of the cube + if dimension in (self.DIM_BANDS, self.DIM_PROPERTIES) and target_dimension is None: log.warning( f"Using experimental feature: DriverVectorCube.apply_dimension along dim {dimension} and empty cube" ) diff --git a/tests/test_vectorcube.py b/tests/test_vectorcube.py index 0647c87d..c3ce62ba 100644 --- a/tests/test_vectorcube.py +++ b/tests/test_vectorcube.py @@ -188,20 +188,20 @@ def test_from_geodataframe_default(self, gdf): } ) cube = vc.get_cube() - assert cube.dims == ("geometries", "bands") + assert cube.dims == ("geometries", "properties") assert cube.shape == (2, 1) - assert {k: list(v.values) for k, v in cube.coords.items()} == {"geometries": [0, 1], "bands": ["pop"]} + assert {k: list(v.values) for k, v in cube.coords.items()} == {"geometries": [0, 1], "properties": ["pop"]} @pytest.mark.parametrize( ["columns_for_cube", "expected"], [ - ("numerical", {"shape": (2, 1), "coords": {"geometries": [0, 1], "bands": ["pop"]}}), - ("all", {"shape": (2, 2), "coords": {"geometries": [0, 1], "bands": ["id", "pop"]}}), + ("numerical", {"shape": (2, 1), "coords": {"geometries": [0, 1], "properties": ["pop"]}}), + ("all", {"shape": (2, 2), "coords": {"geometries": [0, 1], "properties": ["id", "pop"]}}), ([], None), - (["id"], {"shape": (2, 1), "coords": {"geometries": [0, 1], "bands": ["id"]}}), - (["pop", "id"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "bands": ["pop", "id"]}}), + (["id"], {"shape": (2, 1), "coords": {"geometries": [0, 1], "properties": ["id"]}}), + (["pop", "id"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "properties": ["pop", "id"]}}), # TODO: test specifying non-existent column (to be filled with no-data): - # (["pop", "nopenope"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "bands": ["pop", "nopenope"]}}), + # (["pop", "nopenope"], {"shape": (2, 2), "coords": {"geometries": [0, 1], "properties": ["pop", "nopenope"]}}), ], ) def test_from_geodataframe_columns_for_cube(self, gdf, columns_for_cube, expected): @@ -237,7 +237,7 @@ def test_from_geodataframe_columns_for_cube(self, gdf, columns_for_cube, expecte if expected is None: assert cube is None else: - assert cube.dims == ("geometries", "bands") + assert cube.dims == ("geometries", "properties") assert cube.shape == expected["shape"] assert {k: list(v.values) for k, v in cube.coords.items()} == expected["coords"] @@ -571,7 +571,9 @@ def test_buffer_points(self): } ) - def test_apply_dimension_run_udf_change_geometry(self, vc, backend_implementation): + @pytest.mark.parametrize("dimension", ["bands", "properties"]) + def test_apply_dimension_run_udf_change_geometry(self, gdf, backend_implementation, dimension): + vc = DriverVectorCube.from_geodataframe(gdf, dimension_name=dimension) udf = textwrap.dedent( """ from openeo.udf import UdfData, FeatureCollection @@ -592,7 +594,7 @@ def process_geometries(udf_data: UdfData) -> UdfData: } } env = EvalEnv({"backend_implementation": backend_implementation}) - result = vc.apply_dimension(process=callback, dimension="bands", env=env) + result = vc.apply_dimension(process=callback, dimension=dimension, env=env) assert isinstance(result, DriverVectorCube) feature_collection = result.to_geojson() assert feature_collection == DictSubSet(