@@ -1193,11 +1193,11 @@ def reduce_spatial(
11931193 metadata = self .metadata .reduce_spatial (),
11941194 )
11951195
1196- # @openeo_process
1196+ @ deprecated ( "Use :py:meth:`apply_polygon`." , version = "0.26.0" )
11971197 def chunk_polygon (
11981198 self ,
11991199 chunks : Union [shapely .geometry .base .BaseGeometry , dict , str , pathlib .Path , Parameter , VectorCube ],
1200- process : Union [str , PGNode , typing .Callable ],
1200+ process : Union [str , PGNode , typing .Callable , UDF ],
12011201 mask_value : float = None ,
12021202 context : Optional [dict ] = None ,
12031203 ) -> DataCube :
@@ -1237,6 +1237,45 @@ def chunk_polygon(
12371237 ),
12381238 )
12391239
1240+ @openeo_process
1241+ def apply_polygon (
1242+ self ,
1243+ polygons : Union [shapely .geometry .base .BaseGeometry , dict , str , pathlib .Path , Parameter , VectorCube ],
1244+ process : Union [str , PGNode , typing .Callable , UDF ],
1245+ mask_value : Optional [float ] = None ,
1246+ context : Optional [dict ] = None ,
1247+ ) -> DataCube :
1248+ """
1249+ Apply a process to segments of the data cube that are defined by the given polygons.
1250+ For each polygon provided, all pixels for which the point at the pixel center intersects
1251+ with the polygon (as defined in the Simple Features standard by the OGC) are collected into sub data cubes.
1252+ If a pixel is part of multiple of the provided polygons (e.g., when the polygons overlap),
1253+ the GeometriesOverlap exception is thrown.
1254+ Each sub data cube is passed individually to the given process.
1255+
1256+ .. warning:: experimental process: not generally supported, API subject to change.
1257+
1258+ :param polygons: Polygons, provided as a shapely geometry, a GeoJSON-style dictionary,
1259+ a public GeoJSON URL, or a path (that is valid for the back-end) to a GeoJSON file.
1260+ :param process: "child callback" function, see :ref:`callbackfunctions`
1261+ :param mask_value: The value used for pixels outside the polygon.
1262+ :param context: Additional data to be passed to the process.
1263+ """
1264+ process = build_child_callback (process , parent_parameters = ["data" ], connection = self .connection )
1265+ valid_geojson_types = ["Polygon" , "MultiPolygon" , "Feature" , "FeatureCollection" ]
1266+ polygons = self ._get_geometry_argument (polygons , valid_geojson_types = valid_geojson_types )
1267+ mask_value = float (mask_value ) if mask_value is not None else None
1268+ return self .process (
1269+ process_id = "apply_polygon" ,
1270+ data = THIS ,
1271+ polygons = polygons ,
1272+ process = process ,
1273+ arguments = dict_no_none (
1274+ mask_value = mask_value ,
1275+ context = context ,
1276+ ),
1277+ )
1278+
12401279 def reduce_bands (self , reducer : Union [str , PGNode , typing .Callable , UDF ]) -> DataCube :
12411280 """
12421281 Shortcut for :py:meth:`reduce_dimension` along the band dimension
0 commit comments