Skip to content

Commit

Permalink
EP-3934: add chunk_polygon process
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenVerstraelen committed Dec 21, 2021
1 parent 875c589 commit a411109
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
23 changes: 22 additions & 1 deletion openeo_driver/ProcessGraphDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import openeo_processes
import requests
from dateutil.relativedelta import relativedelta
from shapely.geometry import shape, mapping
from shapely.geometry import shape, mapping, MultiPolygon

import openeo.udf
from openeo.capabilities import ComparableVersion
Expand Down Expand Up @@ -597,6 +597,27 @@ def reduce_dimension(args: dict, env: EvalEnv) -> DriverDataCube:
return data_cube.reduce_dimension(reducer=reduce_pg, dimension=dimension, env=env)


@process_registry_100.add_function
def chunk_polygon(args: dict, env: EvalEnv) -> DriverDataCube:
reduce_pg = extract_deep(args, "process", "process_graph")
chunks = extract_arg(args, 'chunks')
data_cube = extract_arg(args, 'data')

if isinstance(chunks, DelayedVector):
polygons = list(chunks.geometries)
for p in polygons:
reason = "{m!s} is not a polygon.".format(m=p)
raise ProcessParameterInvalidException(parameter='chunks', process='chunk_polygon', reason=reason)
polygon = MultiPolygon(polygons)
else:
polygon = geojson_to_multipolygon(chunks)

if polygon.area == 0:
reason = "polygon {m!s} has an area of {a!r}".format(m=polygon, a=polygon.area)
raise ProcessParameterInvalidException(parameter='chunks', process='chunk_polygon', reason=reason)
return data_cube.chunk_polygon(reducer=reduce_pg, chunks=polygon, env=env)


@process
def add_dimension(args: dict, env: EvalEnv) -> DriverDataCube:
data_cube = extract_arg(args, 'data')
Expand Down
3 changes: 3 additions & 0 deletions openeo_driver/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def apply_tiles_spatiotemporal(self, process, context={}) -> 'DriverDataCube':
def reduce_dimension(self, reducer, dimension: str, env: EvalEnv) -> 'DriverDataCube':
self._not_implemented()

def chunk_polygon(self, reducer, chunks, env: EvalEnv, context={}) -> 'DriverDataCube':
self._not_implemented()

def add_dimension(self, name: str, label, type: str = "other") -> 'DriverDataCube':
self._not_implemented()

Expand Down
3 changes: 3 additions & 0 deletions openeo_driver/dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ def reduce_dimension(self, reducer, dimension: str, env: EvalEnv) -> 'DryRunData

return dc._process_metadata(self.metadata.reduce_dimension(dimension_name=dimension))

def chunk_polygon(self, reducer, chunks, env: EvalEnv, context={}) -> 'DryRunDataCube':
return self.filter_spatial(chunks)

def add_dimension(self, name: str, label, type: str = "other") -> 'DryRunDataCube':
return self._process_metadata(self.metadata.add_dimension(name=name, label=label, type=type))

Expand Down

0 comments on commit a411109

Please sign in to comment.