From 7acf9c7d1ac50fa3b4353e5716257c226b2fd3a3 Mon Sep 17 00:00:00 2001 From: Elien Vandermaesen Date: Mon, 16 Dec 2024 08:55:39 +0100 Subject: [PATCH] issue #678 support shapely and local path in load collection spatial extent --- CHANGELOG.md | 2 +- openeo/rest/connection.py | 1 + openeo/rest/datacube.py | 14 +++++++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76b158e6a..bd63f78bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add support for `log_level` in `create_job()` and `execute_job()` ([#704](https://github.com/Open-EO/openeo-python-client/issues/704)) - Add initial support for "geometry" dimension type in `CubeMetadata` ([#705](https://github.com/Open-EO/openeo-python-client/issues/705)) - Add support for parameterized `bands` argument in `load_stac()` -- Argument `spatial_extent` in `load_collection` supports type `shapely` and loading geometry from a local path. +- Argument `spatial_extent` in `load_collection` supports Shapely objects and loading GeoJSON from a local path. ### Changed diff --git a/openeo/rest/connection.py b/openeo/rest/connection.py index e33e99b1d..bc19b9ac5 100644 --- a/openeo/rest/connection.py +++ b/openeo/rest/connection.py @@ -1275,6 +1275,7 @@ def load_collection( - a path (:py:class:`str` or :py:class:`~pathlib.Path`) to a local, client-side GeoJSON file, which will be loaded automatically to get the geometries as GeoJSON construct. - a :py:class:`~openeo.api.process.Parameter` instance. + - a bounding box dictionary :param temporal_extent: limit data to specified temporal interval. Typically, just a two-item list or tuple containing start and end date. See :ref:`filtering-on-temporal-extent-section` for more details on temporal extent handling and shorthand notation. diff --git a/openeo/rest/datacube.py b/openeo/rest/datacube.py index 5e80d23da..385d224f9 100644 --- a/openeo/rest/datacube.py +++ b/openeo/rest/datacube.py @@ -164,6 +164,7 @@ def load_collection( - a path (:py:class:`str` or :py:class:`~pathlib.Path`) to a local, client-side GeoJSON file, which will be loaded automatically to get the geometries as GeoJSON construct. - a :py:class:`~openeo.api.process.Parameter` instance. + - a bounding box dictionary :param temporal_extent: limit data to specified temporal interval. Typically, just a two-item list or tuple containing start and end date. See :ref:`filtering-on-temporal-extent-section` for more details on temporal extent handling and shorthand notation. @@ -192,11 +193,14 @@ def load_collection( "Unexpected parameterized `spatial_extent` in `load_collection`:" f" expected schema compatible with type 'object' but got {spatial_extent.schema!r}." ) - valid_geojson_types = [ - "Polygon", "MultiPolygon", "Feature", "FeatureCollection" - ] - if spatial_extent and not (isinstance(spatial_extent, dict) and spatial_extent.keys() & {"west", "east", "north", "south"}): - spatial_extent = _get_geometry_argument(argument=spatial_extent,valid_geojson_types=valid_geojson_types,connection=connection) + elif not spatial_extent or (isinstance(spatial_extent, dict) and spatial_extent.keys() & {"west", "east", "north", "south"}): + pass + else: + valid_geojson_types = [ + "Polygon", "MultiPolygon", "Feature", "FeatureCollection" + ] + spatial_extent = _get_geometry_argument(argument=spatial_extent, valid_geojson_types=valid_geojson_types, + connection=connection) arguments = { 'id': collection_id,