Skip to content

Commit ed997a7

Browse files
author
Guillermo Tesoro Calvo
committed
Added bbox filter support for collections search
1 parent 50da55f commit ed997a7

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

eodag/rest/core.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ async def all_collections(
370370
instrument: Optional[str] = None,
371371
constellation: Optional[str] = None,
372372
datetime: Optional[str] = None,
373+
bbox: Optional[str] = None,
373374
) -> dict[str, Any]:
374375
"""Build STAC collections
375376
@@ -395,6 +396,7 @@ async def _fetch() -> dict[str, Any]:
395396
instrument=instrument,
396397
constellation=constellation,
397398
datetime=datetime,
399+
bbox=bbox,
398400
)
399401

400402
# # parse f-strings

eodag/rest/server.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ async def collections(
437437
request: Request,
438438
provider: Optional[str] = None,
439439
q: Optional[str] = None,
440+
bbox: Optional[str] = None,
440441
platform: Optional[str] = None,
441442
instrument: Optional[str] = None,
442443
constellation: Optional[str] = None,
@@ -450,8 +451,9 @@ async def collections(
450451
logger.info(f"{request.method} {request.state.url}")
451452

452453
collections = await all_collections(
453-
request, provider, q, platform, instrument, constellation, datetime
454+
request, provider, q, platform, instrument, constellation, datetime, bbox
454455
)
456+
455457
return ORJSONResponse(collections)
456458

457459

eodag/rest/stac.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@
3434

3535
import geojson
3636
from jsonpath_ng.jsonpath import Child
37+
from shapely.geometry import Polygon
3738

3839
from eodag.api.product.metadata_mapping import (
3940
DEFAULT_METADATA_MAPPING,
4041
format_metadata,
4142
get_metadata_path,
4243
)
4344
from eodag.rest.config import Settings
45+
from eodag.rest.types.stac_search import SearchPostRequest
4446
from eodag.rest.utils.rfc3339 import str_to_interval
4547
from eodag.utils import (
4648
deepcopy,
@@ -818,6 +820,7 @@ def get_collection_list(
818820
instrument: Optional[str] = None,
819821
constellation: Optional[str] = None,
820822
datetime: Optional[str] = None,
823+
bbox: Optional[str] = None,
821824
) -> list[dict[str, Any]]:
822825
"""Build STAC collections list
823826
@@ -852,13 +855,26 @@ def get_collection_list(
852855
else:
853856
product_types = all_pt
854857

858+
if bbox:
859+
bbox = [float(x) for x in bbox.split(",")]
860+
SearchPostRequest.validate_bbox(bbox)
861+
bbox = Polygon.from_bounds(*bbox)
862+
855863
# list product types with all metadata using guessed ids
856864
collection_list: list[dict[str, Any]] = []
857865
for product_type in product_types:
858866
stac_collection = self.__generate_stac_collection(
859867
collection_model, product_type
860868
)
861-
collection_list.append(stac_collection)
869+
# Apply bbox filter
870+
if bbox:
871+
_bbox = Polygon.from_bounds(
872+
*stac_collection["extent"]["spatial"]["bbox"][0]
873+
)
874+
if bbox.intersects(_bbox):
875+
collection_list.append(stac_collection)
876+
else:
877+
collection_list.append(stac_collection)
862878

863879
return collection_list
864880

0 commit comments

Comments
 (0)