From cdcfb170c7b4479e4e9d3599646a269c96ffa1cc Mon Sep 17 00:00:00 2001 From: Jeroen Dries Date: Thu, 25 Jul 2024 13:35:34 +0200 Subject: [PATCH] allow using udp parameter for spatial/temporal extents --- src/openeo_gfmap/fetching/commons.py | 10 ++++++---- src/openeo_gfmap/spatial.py | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/openeo_gfmap/fetching/commons.py b/src/openeo_gfmap/fetching/commons.py index 1ce6bb0..ff09232 100644 --- a/src/openeo_gfmap/fetching/commons.py +++ b/src/openeo_gfmap/fetching/commons.py @@ -113,7 +113,7 @@ def _load_collection( bands: list, collection_name: str, spatial_extent: SpatialContext, - temporal_extent: Optional[TemporalContext], + temporal_extent: Optional[Union[TemporalContext,Parameter]], fetch_type: FetchType, is_stac: bool = False, **params, @@ -126,16 +126,18 @@ def _load_collection( _load_collection_hybrid, is_stac=is_stac, collection_id_or_url=collection_name ) + spatial_is_param = isinstance(spatial_extent, Parameter) + if ( - temporal_extent is not None + temporal_extent is not None and not isinstance(temporal_extent, Parameter) ): # Can be ignored for intemporal collections such as DEM temporal_extent = [temporal_extent.start_date, temporal_extent.end_date] if fetch_type == FetchType.TILE: assert isinstance( spatial_extent, BoundingBoxExtent - ), "Please provide only a bounding box for tile based fetching." - spatial_extent = dict(spatial_extent) + ) or spatial_is_param, "Please provide only a bounding box for tile based fetching." + spatial_extent = spatial_extent if spatial_is_param else dict(spatial_extent) cube = load_collection_method( connection=connection, bands=bands, diff --git a/src/openeo_gfmap/spatial.py b/src/openeo_gfmap/spatial.py index 613d1d9..3008c53 100644 --- a/src/openeo_gfmap/spatial.py +++ b/src/openeo_gfmap/spatial.py @@ -5,6 +5,7 @@ from geojson import GeoJSON from shapely.geometry import Polygon, box +from openeo.rest.udp import Parameter @dataclass @@ -50,4 +51,4 @@ def to_geojson(self) -> GeoJSON: return self.to_geometry().__geo_interface__ -SpatialContext = Union[GeoJSON, BoundingBoxExtent, str] +SpatialContext = Union[GeoJSON, BoundingBoxExtent, str, Parameter]