Hello,
I am trying to write a UDF that takes an xr.DataArray as input and returns a geopandas.GeoDataFrame.
I have been experimenting with apply_udf_data, and my current implementation looks like this:
def apply_udf_data(data: UdfData) -> UdfData:
inspect(data=[data], message="Input UDFData inspection")
cube = data.get_datacube_list()[0].get_array()
inspect(data=[list(cube.dims), list(cube.shape)], message="Input UDF cube dims/shape")
gdf = waterline_from_land_water_raster(
da=cube,
crs=data.user_context.get("crs"),
simplify_tolerance=data.user_context.get("simplify_tolerance"),
time_dim=data.user_context.get("time_dim", "time"),
)
inspect(data=[gdf], message="Output gdf")
feature_collection = FeatureCollection(
id=DEFAULT_OUT_LAYER,
data=gdf,
)
data.set_feature_collection_list([feature_collection])
inspect(data=[data], message="Output UDFData inspection")
return data
I then execute the UDF like this:
from openeo import UDF
path_to_udf = Path("udf_waterlines_from_water_land_mask.py")
udf = UDF.from_file(path_to_udf, context={"from_parameter": "context"})
waterlines_cube = mask.apply_dimension(process=udf, dimension="t", context={"crs": "EPSG:3857", "time_dim": "t"})
job = waterlines_cube.create_job(title="waterlines", auto_add_save_result=True)
job.start_and_wait()
The job completes successfully. However, when I inspect the metadata or download the results, I only see the GeoTIFF outputs. The FeatureCollection produced by the UDF does not seem to be included in the job results.
My question is: how should I run or configure the job so that I can access, read, or download the FeatureCollection output from the UDF?
I would really appreciate help, as I was unable to find any example of apply_udf_data usage and there is not a lot of documentation available.
