Skip to content

Commit ee7941a

Browse files
committed
Issue #706 Show warning on GeometryCollection usage
preparation for fully dropping support in a future release
1 parent 0794610 commit ee7941a

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
### Changed
2020

2121
- Raise exception when providing empty bands array to `load_collection`/`load_stac` ([#424](https://github.com/Open-EO/openeo-python-client/issues/424), [Open-EO/openeo-processes#372](https://github.com/Open-EO/openeo-processes/issues/372))
22+
- Start showing deprecation warnings on usage of GeoJSON "GeometryCollection" (in `filter_spatial`, `aggregate_spatial`, `chunk_polygon`, `mask_polygon`). Use a GeoJSON FeatureCollection instead. ([#706](https://github.com/Open-EO/openeo-python-client/issues/706), [Open-EO/openeo-processes#389](https://github.com/Open-EO/openeo-processes/issues/389))
2223

2324
### Removed
2425

openeo/rest/datacube.py

+27-6
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ def filter_spatial(
676676
"MultiLineString",
677677
"Polygon",
678678
"MultiPolygon",
679-
"GeometryCollection",
679+
"GeometryCollection", # TODO #706 stop allowing GeometryCollection
680680
"FeatureCollection",
681681
]
682682
geometries = _get_geometry_argument(geometries, valid_geojson_types=valid_geojson_types, connection=self.connection, crs=None)
@@ -1174,8 +1174,15 @@ def aggregate_spatial(
11741174
(which will be loaded client-side to get the geometries as GeoJSON construct).
11751175
"""
11761176
valid_geojson_types = [
1177-
"Point", "MultiPoint", "LineString", "MultiLineString",
1178-
"Polygon", "MultiPolygon", "GeometryCollection", "Feature", "FeatureCollection"
1177+
"Point",
1178+
"MultiPoint",
1179+
"LineString",
1180+
"MultiLineString",
1181+
"Polygon",
1182+
"MultiPolygon",
1183+
"GeometryCollection", # TODO #706 stop allowing GeometryCollection
1184+
"Feature",
1185+
"FeatureCollection",
11791186
]
11801187
geometries = _get_geometry_argument(geometries, valid_geojson_types=valid_geojson_types, connection= self.connection, crs=crs)
11811188
reducer = build_child_callback(reducer, parent_parameters=["data"])
@@ -1453,7 +1460,7 @@ def chunk_polygon(
14531460
valid_geojson_types = [
14541461
"Polygon",
14551462
"MultiPolygon",
1456-
"GeometryCollection",
1463+
"GeometryCollection", # TODO #706 stop allowing GeometryCollection
14571464
"Feature",
14581465
"FeatureCollection",
14591466
]
@@ -2034,8 +2041,16 @@ def mask_polygon(
20342041
Instead, it's possible to provide a client-side path to a GeoJSON file
20352042
(which will be loaded client-side to get the geometries as GeoJSON construct).
20362043
"""
2037-
valid_geojson_types = ["Polygon", "MultiPolygon", "GeometryCollection", "Feature", "FeatureCollection"]
2038-
mask = _get_geometry_argument(mask, valid_geojson_types=valid_geojson_types, connection=self.connection, crs=srs)
2044+
valid_geojson_types = [
2045+
"Polygon",
2046+
"MultiPolygon",
2047+
"GeometryCollection", # TODO #706 stop allowing GeometryCollection
2048+
"Feature",
2049+
"FeatureCollection",
2050+
]
2051+
mask = _get_geometry_argument(
2052+
mask, valid_geojson_types=valid_geojson_types, connection=self.connection, crs=srs
2053+
)
20392054
return self.process(
20402055
process_id="mask_polygon",
20412056
arguments=dict_no_none(
@@ -2971,6 +2986,12 @@ def _get_geometry_argument(
29712986
raise OpenEoClientException("Invalid geometry type {t!r}, must be one of {s}".format(
29722987
t=geometry.get("type"), s=valid_geojson_types
29732988
))
2989+
if geometry.get("type") == "GeometryCollection":
2990+
# TODO #706 Fully drop GeometryCollection support
2991+
warnings.warn(
2992+
"Usage of GeoJSON type 'GeometryCollection' is deprecated/invalid. Support in openEO Python client will be dropped. Use a FeatureCollection instead.",
2993+
category=DeprecationWarning,
2994+
)
29742995
if crs:
29752996
# TODO: don't warn when the crs is Lon-Lat like EPSG:4326?
29762997
warnings.warn(f"Geometry with non-Lon-Lat CRS {crs!r} is only supported by specific back-ends.")

tests/rest/datacube/test_datacube100.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
{"type": "MultiPolygon", "coordinates": [[[[1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [0.0, 0.0], [1.0, 0.0]]]]},
4949
),
5050
(
51+
# TODO #706 Stop allowing GeometryCollection
5152
shapely.geometry.GeometryCollection([shapely.geometry.box(0, 0, 1, 1)]),
5253
{
5354
"type": "GeometryCollection",
@@ -450,8 +451,9 @@ def test_aggregate_spatial_basic(con100: Connection):
450451
(
451452
shapely.geometry.MultiPolygon([shapely.geometry.box(0, 0, 1, 1)]),
452453
{"type": "MultiPolygon", "coordinates": [(((1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0), (1.0, 0.0)),)]},
453-
),
454-
(
454+
),
455+
(
456+
# TODO #706 Stop allowing GeometryCollection
455457
shapely.geometry.GeometryCollection([shapely.geometry.box(0, 0, 1, 1)]),
456458
{"type": "GeometryCollection", "geometries": [
457459
{"type": "Polygon", "coordinates": (((1.0, 0.0), (1.0, 1.0), (0.0, 1.0), (0.0, 0.0), (1.0, 0.0)),)}

0 commit comments

Comments
 (0)