Skip to content

Commit

Permalink
Merge branch 'issue678-load_collection-support-shapely-geometry-input'
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Jan 17, 2025
2 parents a907e38 + e1fa369 commit 0794610
Show file tree
Hide file tree
Showing 9 changed files with 699 additions and 112 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +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()`/`load_stac()`: add support for Shapely objects, loading GeoJSON from a local path and loading geometry from GeoJSON/GeoParquet URL. ([#678](https://github.com/Open-EO/openeo-python-client/issues/678))

### Changed

Expand Down
3 changes: 3 additions & 0 deletions openeo/api/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ def schema_supports(schema: Union[dict, List[dict]], type: str, subtype: Optiona
elif isinstance(actual_type, list):
if type not in actual_type:
return False
elif actual_type is None:
# Without explicit "type", anything is accepted
return True
else:
raise ValueError(actual_type)
if subtype:
Expand Down
2 changes: 1 addition & 1 deletion openeo/rest/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def setup_collection(
json={
"id": collection_id,
# define temporal and band dim
"cube:dimensions": {"t": {"type": "temporal"}, "bands": {"type": "bands"}},
"cube:dimensions": cube_dimensions,
},
)
return self
Expand Down
21 changes: 17 additions & 4 deletions openeo/rest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ def datacube_from_json(self, src: Union[str, Path], parameters: Optional[dict] =
def load_collection(
self,
collection_id: Union[str, Parameter],
spatial_extent: Union[Dict[str, float], Parameter, None] = None,
spatial_extent: Union[dict, Parameter, shapely.geometry.base.BaseGeometry, str, Path, None] = None,
temporal_extent: Union[Sequence[InputDate], Parameter, str, None] = None,
bands: Union[Iterable[str], Parameter, str, None] = None,
properties: Union[
Expand All @@ -1269,7 +1269,14 @@ def load_collection(
Load a DataCube by collection id.
:param collection_id: image collection identifier
:param spatial_extent: limit data to specified bounding box or polygons
:param spatial_extent: limit data to specified bounding box or polygons. Can be provided in different ways:
- a bounding box dictionary
- a Shapely geometry object
- a GeoJSON-style dictionary
- a path (as :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 URL to a publicly accessible GeoJSON document
- a :py:class:`~openeo.api.process.Parameter` instance.
: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.
Expand All @@ -1288,6 +1295,9 @@ def load_collection(
.. versionchanged:: 0.26.0
Add :py:func:`~openeo.rest.graph_building.collection_property` support to ``properties`` argument.
.. versionchanged:: 0.37.0
Argument ``spatial_extent``: add support for passing a Shapely geometry or a local path to a GeoJSON file.
"""
return DataCube.load_collection(
collection_id=collection_id,
Expand Down Expand Up @@ -1346,7 +1356,7 @@ def load_result(
def load_stac(
self,
url: str,
spatial_extent: Union[Dict[str, float], Parameter, None] = None,
spatial_extent: Union[dict, Parameter, shapely.geometry.base.BaseGeometry, str, Path, None] = None,
temporal_extent: Union[Sequence[InputDate], Parameter, str, None] = None,
bands: Union[Iterable[str], Parameter, str, None] = None,
properties: Optional[Dict[str, Union[str, PGNode, Callable]]] = None,
Expand Down Expand Up @@ -1448,6 +1458,9 @@ def load_stac(
.. versionchanged:: 0.23.0
Argument ``temporal_extent``: add support for year/month shorthand notation
as discussed at :ref:`date-shorthand-handling`.
.. versionchanged:: 0.37.0
Argument ``spatial_extent``: add support for passing a Shapely geometry or a local path to a GeoJSON file.
"""
return DataCube.load_stac(
url=url,
Expand Down Expand Up @@ -1553,7 +1566,7 @@ def load_geojson(
return VectorCube.load_geojson(connection=self, data=data, properties=properties)

@openeo_process
def load_url(self, url: str, format: str, options: Optional[dict] = None):
def load_url(self, url: str, format: str, options: Optional[dict] = None) -> VectorCube:
"""
Loads a file from a URL
Expand Down
Loading

0 comments on commit 0794610

Please sign in to comment.