Skip to content

apply_polygon (previously known as chunk_polygon) abuses MultiPolygon as collection of polygons in its internal API #288

Open
Open-EO/openeo-geopyspark-driver
#801
@soxofaan

Description

@soxofaan

Stumbled on this while working on #287:

The apply_polygon process implementation (originally added as chunk_polygon in a411109) coerces the provided geometries into a MultiPolygon :

# TODO: 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):
polygons = list(polygons.geometries)
for p in polygons:
if not isinstance(p, shapely.geometry.Polygon):
reason = "{m!s} is not a polygon.".format(m=p)
raise ProcessParameterInvalidException(parameter="polygons", process="apply_polygon", reason=reason)
polygon = MultiPolygon(polygons)
elif isinstance(polygons, shapely.geometry.base.BaseGeometry):
polygon = MultiPolygon(polygons)
elif isinstance(polygons, dict):
polygon = geojson_to_multipolygon(polygons)
if isinstance(polygon, shapely.geometry.Polygon):
polygon = MultiPolygon([polygon])

and pushes this API through into geopyspark driver, e.g.
https://github.com/Open-EO/openeo-geopyspark-driver/blob/1f22c0da34535e986908480673ad341c9f89324d/openeogeotrellis/geopysparkdatacube.py#L572-L575

MultiPolygon should not be abused as a collection of polygons. Instead the API should use something like a FeatureCollection or vector cube abstraction

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions