Skip to content

Commit aebdf69

Browse files
ElienVandermaesenVITOsoxofaan
authored andcommitted
issue #678 support shapely and local path in load collection spatial extent
1 parent 1b9d9fc commit aebdf69

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Add support for `log_level` in `create_job()` and `execute_job()` ([#704](https://github.com/Open-EO/openeo-python-client/issues/704))
1515
- Add initial support for "geometry" dimension type in `CubeMetadata` ([#705](https://github.com/Open-EO/openeo-python-client/issues/705))
1616
- Add support for parameterized `bands` argument in `load_stac()`
17+
- Argument `spatial_extent` in `load_collection` supports type `shapely` and loading geometry from a local path.
1718

1819
### Changed
1920

openeo/rest/connection.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ def datacube_from_json(self, src: Union[str, Path], parameters: Optional[dict] =
12561256
def load_collection(
12571257
self,
12581258
collection_id: Union[str, Parameter],
1259-
spatial_extent: Union[Dict[str, float], Parameter, None] = None,
1259+
spatial_extent: Union[Dict[str, float], Parameter, shapely.geometry.base.BaseGeometry, None] = None,
12601260
temporal_extent: Union[Sequence[InputDate], Parameter, str, None] = None,
12611261
bands: Union[Iterable[str], Parameter, str, None] = None,
12621262
properties: Union[
@@ -1269,7 +1269,12 @@ def load_collection(
12691269
Load a DataCube by collection id.
12701270
12711271
:param collection_id: image collection identifier
1272-
:param spatial_extent: limit data to specified bounding box or polygons
1272+
:param spatial_extent: limit data to specified bounding box or polygons. Can be provided in different ways:
1273+
- a shapely geometry
1274+
- a GeoJSON-style dictionary,
1275+
- a path (:py:class:`str` or :py:class:`~pathlib.Path`) to a local, client-side GeoJSON file,
1276+
which will be loaded automatically to get the geometries as GeoJSON construct.
1277+
- a :py:class:`~openeo.api.process.Parameter` instance.
12731278
:param temporal_extent: limit data to specified temporal interval.
12741279
Typically, just a two-item list or tuple containing start and end date.
12751280
See :ref:`filtering-on-temporal-extent-section` for more details on temporal extent handling and shorthand notation.

openeo/rest/datacube.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,12 @@ def load_collection(
158158
:param collection_id: image collection identifier
159159
:param connection: The backend connection to use.
160160
Can be ``None`` to work without connection and collection metadata.
161-
:param spatial_extent: limit data to specified bounding box or polygons
161+
:param spatial_extent: limit data to specified bounding box or polygons. Can be provided in different ways:
162+
- a shapely geometry
163+
- a GeoJSON-style dictionary,
164+
- a path (:py:class:`str` or :py:class:`~pathlib.Path`) to a local, client-side GeoJSON file,
165+
which will be loaded automatically to get the geometries as GeoJSON construct.
166+
- a :py:class:`~openeo.api.process.Parameter` instance.
162167
:param temporal_extent: limit data to specified temporal interval.
163168
Typically, just a two-item list or tuple containing start and end date.
164169
See :ref:`filtering-on-temporal-extent-section` for more details on temporal extent handling and shorthand notation.
@@ -188,7 +193,7 @@ def load_collection(
188193
f" expected schema compatible with type 'object' but got {spatial_extent.schema!r}."
189194
)
190195
valid_geojson_types = [
191-
"Polygon", "MultiPolygon", "GeometryCollection", "FeatureCollection"
196+
"Polygon", "MultiPolygon", "Feature", "FeatureCollection"
192197
]
193198
if spatial_extent and not (isinstance(spatial_extent, dict) and spatial_extent.keys() & {"west", "east", "north", "south"}):
194199
spatial_extent = _get_geometry_argument(argument=spatial_extent,valid_geojson_types=valid_geojson_types,connection=connection)

tests/rest/datacube/test_datacube.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ def test_load_collection_connectionless_shapely_spatial_extent(self):
150150
}
151151
}
152152

153+
@pytest.mark.parametrize("path_factory", [str, pathlib.Path])
154+
def test_load_collection_connectionless_local_path_spatial_extent(self, path_factory, test_data):
155+
path = path_factory(test_data.get_path("geojson/polygon02.json"))
156+
cube = DataCube.load_collection("T3", spatial_extent=path)
157+
assert cube.flat_graph() == {
158+
"loadcollection1": {
159+
"arguments": {"id": "T3", "spatial_extent":
160+
{"type": "Polygon", "coordinates": [[[3, 50], [4, 50], [4, 51], [3, 50]]]},
161+
"temporal_extent": None},
162+
"process_id": "load_collection",
163+
"result": True,
164+
}
165+
}
166+
153167
def test_load_collection_connectionless_save_result(self):
154168
cube = DataCube.load_collection("T3").save_result(format="GTiff")
155169
assert cube.flat_graph() == {

0 commit comments

Comments
 (0)