Skip to content

Commit 26c7c1a

Browse files
committed
fixup! PR #200 finetune VectorCube.apply_dimension
1 parent 3c2f0e9 commit 26c7c1a

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

openeo_driver/datacube.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def apply_dimension(
519519

520520
if single_run_udf:
521521
# Process with single "run_udf" node
522-
if self._cube is None and dimension == self.DIM_GEOMETRIES and target_dimension is Non:
522+
if self._cube is None and dimension == self.DIM_GEOMETRIES and target_dimension is None:
523523
# TODO: this is non-standard special case: vector cube with only geometries, but no "cube" data
524524
feature_collection = openeo.udf.FeatureCollection(id="_", data=self._as_geopandas_df())
525525
udf_data = openeo.udf.UdfData(

tests/test_vectorcube.py

+54
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import textwrap
2+
13
import geopandas as gpd
24
import numpy.testing
35
import pyproj
@@ -9,6 +11,7 @@
911
from openeo_driver.datacube import DriverVectorCube
1012
from openeo_driver.testing import DictSubSet, ApproxGeometry
1113
from openeo_driver.util.geometry import as_geojson_feature_collection
14+
from openeo_driver.utils import EvalEnv
1215

1316
from .data import get_path
1417

@@ -22,6 +25,10 @@ def gdf(self) -> gpd.GeoDataFrame:
2225
df = gpd.read_file(path)
2326
return df
2427

28+
@pytest.fixture
29+
def vc(self, gdf) -> DriverVectorCube:
30+
return DriverVectorCube(geometries=gdf)
31+
2532
def test_basic(self, gdf):
2633
vc = DriverVectorCube(gdf)
2734
assert vc.get_bounding_box() == (1, 1, 5, 4)
@@ -446,3 +453,50 @@ def test_buffer_points(self):
446453
],
447454
}
448455
)
456+
457+
def test_apply_dimension_run_udf(self, vc, backend_implementation):
458+
udf = textwrap.dedent(
459+
"""
460+
from openeo.udf import UdfData, FeatureCollection
461+
def process_geometries(udf_data: UdfData) -> UdfData:
462+
[feature_collection] = udf_data.get_feature_collection_list()
463+
gdf = feature_collection.data
464+
gdf["geometry"] = gdf["geometry"].buffer(distance=1, resolution=2)
465+
udf_data.set_feature_collection_list([
466+
FeatureCollection(id="_", data=gdf),
467+
])
468+
"""
469+
)
470+
callback = {
471+
"runudf1": {
472+
"process_id": "run_udf",
473+
"arguments": {"data": {"from_parameter": "data"}, "udf": udf, "runtime": "Python"},
474+
"result": True,
475+
}
476+
}
477+
env = EvalEnv({"backend_implementation": backend_implementation})
478+
result = vc.apply_dimension(process=callback, dimension="geometries", env=env)
479+
assert isinstance(result, DriverVectorCube)
480+
feature_collection = result.to_geojson()
481+
assert feature_collection == DictSubSet(
482+
{
483+
"type": "FeatureCollection",
484+
"bbox": pytest.approx((0, 0, 6, 5), abs=0.1),
485+
"features": [
486+
{
487+
"type": "Feature",
488+
"bbox": pytest.approx((0, 0, 4, 4), abs=0.1),
489+
"geometry": DictSubSet({"type": "Polygon"}),
490+
"id": "0",
491+
"properties": {"id": "first", "pop": 1234},
492+
},
493+
{
494+
"type": "Feature",
495+
"bbox": pytest.approx((2, 1, 6, 5), abs=0.1),
496+
"geometry": DictSubSet({"type": "Polygon"}),
497+
"id": "1",
498+
"properties": {"id": "second", "pop": 5678},
499+
},
500+
],
501+
}
502+
)

0 commit comments

Comments
 (0)