1
+ import textwrap
2
+
1
3
import geopandas as gpd
2
4
import numpy .testing
3
5
import pyproj
9
11
from openeo_driver .datacube import DriverVectorCube
10
12
from openeo_driver .testing import DictSubSet , ApproxGeometry
11
13
from openeo_driver .util .geometry import as_geojson_feature_collection
14
+ from openeo_driver .utils import EvalEnv
12
15
13
16
from .data import get_path
14
17
@@ -22,6 +25,10 @@ def gdf(self) -> gpd.GeoDataFrame:
22
25
df = gpd .read_file (path )
23
26
return df
24
27
28
+ @pytest .fixture
29
+ def vc (self , gdf ) -> DriverVectorCube :
30
+ return DriverVectorCube (geometries = gdf )
31
+
25
32
def test_basic (self , gdf ):
26
33
vc = DriverVectorCube (gdf )
27
34
assert vc .get_bounding_box () == (1 , 1 , 5 , 4 )
@@ -446,3 +453,50 @@ def test_buffer_points(self):
446
453
],
447
454
}
448
455
)
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