Skip to content

Commit dff2247

Browse files
gtesoroGuillermo Tesoro Calvo
andauthored
bug: Collection bbox filter now works when collection bbox is a point (#41)
Collection bbox search filter was not working when the collection bbox was defined as a single point. This PR fixes it. --------- Co-authored-by: Guillermo Tesoro Calvo <guillermo.tesoro@c-ssystems.de>
1 parent 479330c commit dff2247

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies = [
2424
"brotli-asgi",
2525
"starlette",
2626
"typing_extensions",
27+
"shapely"
2728
]
2829

2930
[project.urls]
@@ -59,6 +60,7 @@ dev = [
5960
"stdlib-list",
6061
"tox",
6162
"tox-uv",
63+
"types-shapely"
6264
]
6365

6466
[tool.mypy]

stac_fastapi/eodag/core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
get_sortby_to_post,
6464
)
6565
from stac_fastapi.eodag.utils import (
66+
check_poly_is_point,
6667
dt_range_to_eodag,
6768
format_datetime_range,
6869
is_dict_str_any,
@@ -276,12 +277,15 @@ async def all_collections(
276277
# bbox filter
277278
if bbox:
278279
bbox_geom = get_geometry_from_various(geometry=bbox)
280+
279281
default_extent = [[-180.0, -90.0, 180.0, 90.0]]
280282
collections = [
281283
c
282284
for c in collections
283-
if get_geometry_from_various(
284-
geometry=c.get("extent", {}).get("spatial", {}).get("bbox", default_extent)[0]
285+
if check_poly_is_point(
286+
get_geometry_from_various( # type: ignore
287+
geometry=c.get("extent", {}).get("spatial", {}).get("bbox", default_extent)[0]
288+
)
285289
).intersection(bbox_geom)
286290
]
287291

stac_fastapi/eodag/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from urllib.parse import unquote_plus
2525

2626
import orjson
27+
from shapely.geometry import Point, Polygon
2728

2829
if TYPE_CHECKING:
2930
from typing import Any, Optional, Union
@@ -119,3 +120,17 @@ def dt_range_to_eodag(
119120
end = end.isoformat().replace("+00:00", "Z") if end else None
120121

121122
return start, end
123+
124+
125+
def check_poly_is_point(poly: Polygon) -> Union[Point, Polygon]:
126+
"""
127+
Check if the polygon is a Point and returns it if so.
128+
129+
:param poly: A Shapely polygon.
130+
:returns: Either a `Point` or the unchanged `poly`.
131+
"""
132+
133+
if poly.area == 0 and poly.area == 0 and poly.bounds[0] == poly.bounds[2] and poly.bounds[1] == poly.bounds[3]:
134+
return Point(poly.exterior.coords[0])
135+
else:
136+
return poly

0 commit comments

Comments
 (0)