From 605f153d52c91ff5724c84c476bf3a8b957b63e0 Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Fri, 7 Jun 2024 19:59:08 +0200 Subject: [PATCH] Issue #288/#229 add TODO notes about wrong MultiPolygon usage --- openeo_driver/ProcessGraphDeserializer.py | 2 +- openeo_driver/datacube.py | 5 ++++- openeo_driver/dry_run.py | 3 ++- openeo_driver/util/geometry.py | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/openeo_driver/ProcessGraphDeserializer.py b/openeo_driver/ProcessGraphDeserializer.py index ec3febf4..20507cea 100644 --- a/openeo_driver/ProcessGraphDeserializer.py +++ b/openeo_driver/ProcessGraphDeserializer.py @@ -856,7 +856,7 @@ def apply_polygon(args: ProcessArgs, env: EvalEnv) -> DriverDataCube: context = args.get_optional("context", default=None) # TODO #114 EP-3981 normalize first to vector cube and simplify logic - # TODO: this logic (copied from original chunk_polygon implementation) coerces the input polygons + # TODO #288: this logic (copied from original chunk_polygon implementation) coerces the input polygons # to a single MultiPolygon of pure (non-multi) polygons, which is conceptually wrong. # Instead it should normalize to a feature collection or vector cube. if isinstance(polygons, DelayedVector): diff --git a/openeo_driver/datacube.py b/openeo_driver/datacube.py index 4da4f1ab..bb8f1d47 100644 --- a/openeo_driver/datacube.py +++ b/openeo_driver/datacube.py @@ -122,6 +122,8 @@ def chunk_polygon( self, *, reducer: dict, + # TODO #288:` chunks` should be an explicit collection of geometries (e.g a FeatureCollection, vector cube base class or an iterable of geometries) + # Note that subclass implementations even wrongly retype this to `MultiPolygon`. chunks: Union[shapely.geometry.base.BaseGeometry], mask_value: Union[float, None], env: EvalEnv, @@ -133,7 +135,8 @@ def chunk_polygon( def apply_polygon( self, *, - # TODO #229 better type for `polygons` arg: should be vector cube or feature collection like construct + # TODO #229/#288 better type for `polygons` arg: should be vector cube or something alike + # TODO #288: use `geometries` argument instead of confusing `polygons` argument (https://github.com/Open-EO/openeo-processes/issues/511) polygons: shapely.geometry.base.BaseGeometry, process: dict, mask_value: Optional[float] = None, diff --git a/openeo_driver/dry_run.py b/openeo_driver/dry_run.py index ef3bb5b6..cf818fca 100644 --- a/openeo_driver/dry_run.py +++ b/openeo_driver/dry_run.py @@ -644,9 +644,10 @@ def ndvi(self, nir: str = "nir", red: str = "red", target_band: str = None) -> ' return self def chunk_polygon( + # TODO #288: `chunks`: MultiPolygon should not be abused as collection of separate geometries. self, reducer, chunks: MultiPolygon, mask_value: float, env: EvalEnv, context: Optional[dict] = None ) -> "DryRunDataCube": - # TODO: rename/update `chunk_polygon` to `apply_polygon` (https://github.com/Open-EO/openeo-processes/pull/298) + # TODO #229: rename/update `chunk_polygon` to `apply_polygon` (https://github.com/Open-EO/openeo-processes/pull/298) polygons: List[Polygon] = chunks.geoms # TODO #71 #114 Deprecate/avoid usage of GeometryCollection geometries, bbox = self._normalize_geometry(GeometryCollection(polygons)) diff --git a/openeo_driver/util/geometry.py b/openeo_driver/util/geometry.py index 3f373eeb..7886e6e8 100644 --- a/openeo_driver/util/geometry.py +++ b/openeo_driver/util/geometry.py @@ -169,6 +169,7 @@ def geojson_to_multipolygon( """ # TODO: option to also force conversion of Polygon to MultiPolygon? # TODO: #71 #114 migrate/centralize all this kind of logic to vector cubes + # TODO #288 this function supports/promotes wrong usage of MultiPolygons (when FeatureCollections or VectorCubes should be used instead) validate_geojson_coordinates(geojson) if geojson["type"] == "Feature": geojson = geojson["geometry"]