Skip to content

Commit 7447267

Browse files
committed
fixes, update tests
1 parent 385e310 commit 7447267

File tree

16 files changed

+16
-638
lines changed

16 files changed

+16
-638
lines changed

CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
### Added
1111

12-
- Spatial search support for collections via `bbox` parameter on `/collections` endpoint. Collections are now indexed with a `bbox_shape` field (GeoJSON polygon) derived from their spatial extent for efficient geospatial queries.
13-
- Migration scripts (`update_collections_mapping.py` and `recreate_collections_index.py`) to help add `bbox_shape` field to existing deployments.
14-
1512
### Changed
1613

1714
### Fixed
1815

16+
[v6.5.1] - 2025-09-30
17+
18+
### Fixed
19+
1920
- Issue where token, query param was not being passed to POST collections search logic
2021
- Issue where datetime param was not being passed from POST collections search logic to Elasticsearch
2122
- Collections search tests to ensure both GET /collections and POST /collections-search endpoints are tested
@@ -554,7 +555,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
554555
- Use genexp in execute_search and get_all_collections to return results.
555556
- Added db_to_stac serializer to item_collection method in core.py.
556557

557-
[Unreleased]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v6.5.0...main
558+
[Unreleased]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v6.5.1...main
559+
[v6.5.1]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v6.5.0...v6.5.1
558560
[v6.5.0]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v6.4.0...v6.5.0
559561
[v6.4.0]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v6.3.0...v6.4.0
560562
[v6.3.0]: https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/compare/v6.2.1...v6.3.0

recreate_collections_index.py

Lines changed: 0 additions & 121 deletions
This file was deleted.

stac_fastapi/core/stac_fastapi/core/base_database_logic.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import abc
44
from typing import Any, Dict, Iterable, List, Optional, Tuple
55

6-
from stac_pydantic.shared import BBox
7-
86

97
class BaseDatabaseLogic(abc.ABC):
108
"""
@@ -21,7 +19,6 @@ async def get_all_collections(
2119
limit: int,
2220
request: Any = None,
2321
sort: Optional[List[Dict[str, Any]]] = None,
24-
bbox: Optional[BBox] = None,
2522
) -> Tuple[List[Dict[str, Any]], Optional[str]]:
2623
"""Retrieve a list of collections from the database, supporting pagination.
2724
@@ -30,7 +27,6 @@ async def get_all_collections(
3027
limit (int): The number of results to return.
3128
request (Any, optional): The FastAPI request object. Defaults to None.
3229
sort (Optional[List[Dict[str, Any]]], optional): Optional sort parameter. Defaults to None.
33-
bbox (Optional[BBox], optional): Bounding box to filter collections by spatial extent. Defaults to None.
3430
3531
Returns:
3632
A tuple of (collections, next pagination token if any).

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ async def landing_page(self, **kwargs) -> stac_types.LandingPage:
241241
async def all_collections(
242242
self,
243243
limit: Optional[int] = None,
244-
bbox: Optional[BBox] = None,
245244
datetime: Optional[str] = None,
246245
fields: Optional[List[str]] = None,
247246
sortby: Optional[Union[str, List[str]]] = None,
@@ -402,7 +401,6 @@ async def all_collections(
402401
limit=limit,
403402
request=request,
404403
sort=sort,
405-
bbox=bbox,
406404
q=q_list,
407405
filter=parsed_filter,
408406
query=parsed_query,
@@ -504,7 +502,6 @@ async def post_all_collections(
504502
# Pass all parameters from search_request to all_collections
505503
return await self.all_collections(
506504
limit=search_request.limit if hasattr(search_request, "limit") else None,
507-
bbox=search_request.bbox if hasattr(search_request, "bbox") else None,
508505
datetime=search_request.datetime
509506
if hasattr(search_request, "datetime")
510507
else None,

stac_fastapi/core/stac_fastapi/core/serializers.py

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from stac_fastapi.core.datetime_utils import now_to_rfc3339_str
1212
from stac_fastapi.core.models.links import CollectionLinks
13-
from stac_fastapi.core.utilities import bbox2polygon, get_bool_env
13+
from stac_fastapi.core.utilities import get_bool_env
1414
from stac_fastapi.types import stac as stac_types
1515
from stac_fastapi.types.links import ItemLinks, resolve_links
1616

@@ -144,53 +144,6 @@ def stac_to_db(
144144
collection.get("links", []), str(request.base_url)
145145
)
146146

147-
# Convert bbox to bbox_shape for geospatial queries
148-
if "extent" in collection and "spatial" in collection["extent"]:
149-
spatial_extent = collection["extent"]["spatial"]
150-
if "bbox" in spatial_extent and spatial_extent["bbox"]:
151-
# Get the first bbox (collections can have multiple bboxes, but we use the first one)
152-
bbox = (
153-
spatial_extent["bbox"][0]
154-
if isinstance(spatial_extent["bbox"][0], list)
155-
else spatial_extent["bbox"]
156-
)
157-
collection_id = collection.get("id", "unknown")
158-
logger.debug(
159-
f"Converting bbox to bbox_shape for collection '{collection_id}': bbox={bbox}"
160-
)
161-
162-
if len(bbox) >= 4:
163-
# Extract 2D coordinates (bbox can be 2D [minx, miny, maxx, maxy] or 3D [minx, miny, minz, maxx, maxy, maxz])
164-
# For 2D polygon, we only need the x,y coordinates and discard altitude (z) values
165-
minx, miny = bbox[0], bbox[1]
166-
if len(bbox) == 4:
167-
# 2D bbox: [minx, miny, maxx, maxy]
168-
maxx, maxy = bbox[2], bbox[3]
169-
logger.debug(
170-
f"Collection '{collection_id}': Processing 2D bbox"
171-
)
172-
else:
173-
# 3D bbox: [minx, miny, minz, maxx, maxy, maxz]
174-
# Extract indices 3,4 for maxx,maxy - discarding altitude at indices 2 (minz) and 5 (maxz)
175-
maxx, maxy = bbox[3], bbox[4]
176-
logger.debug(
177-
f"Collection '{collection_id}': Processing 3D bbox, discarding altitude values at indices 2 and 5"
178-
)
179-
180-
# Convert bbox to GeoJSON polygon
181-
bbox_polygon_coords = bbox2polygon(minx, miny, maxx, maxy)
182-
collection["bbox_shape"] = {
183-
"type": "Polygon",
184-
"coordinates": bbox_polygon_coords,
185-
}
186-
logger.info(
187-
f"Collection '{collection_id}': Created bbox_shape from bbox [{minx}, {miny}, {maxx}, {maxy}]"
188-
)
189-
else:
190-
logger.warning(
191-
f"Collection '{collection_id}': bbox has insufficient coordinates (length={len(bbox)}), expected at least 4"
192-
)
193-
194147
if get_bool_env("STAC_INDEX_ASSETS"):
195148
collection["assets"] = [
196149
{"es_key": k, **v} for k, v in collection.get("assets", {}).items()
@@ -218,9 +171,6 @@ def db_to_stac(
218171
# Avoid modifying the input dict in-place ... doing so breaks some tests
219172
collection = deepcopy(collection)
220173

221-
# Remove internal bbox_shape field (not part of STAC spec)
222-
collection.pop("bbox_shape", None)
223-
224174
# Set defaults
225175
collection_id = collection.get("id")
226176
collection.setdefault("type", "Collection")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""library version."""
2-
__version__ = "6.5.0"
2+
__version__ = "6.5.1"

stac_fastapi/elasticsearch/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
desc = f.read()
77

88
install_requires = [
9-
"stac-fastapi-core==6.5.0",
10-
"sfeos-helpers==6.5.0",
9+
"stac-fastapi-core==6.5.1",
10+
"sfeos-helpers==6.5.1",
1111
"elasticsearch[async]~=8.18.0",
1212
"uvicorn~=0.23.0",
1313
"starlette>=0.35.0,<0.36.0",

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ async def get_all_collections(
175175
limit: int,
176176
request: Request,
177177
sort: Optional[List[Dict[str, Any]]] = None,
178-
bbox: Optional[List[float]] = None,
179178
q: Optional[List[str]] = None,
180179
filter: Optional[Dict[str, Any]] = None,
181180
query: Optional[Dict[str, Dict[str, Any]]] = None,
@@ -188,7 +187,6 @@ async def get_all_collections(
188187
limit (int): The number of results to return.
189188
request (Request): The FastAPI request object.
190189
sort (Optional[List[Dict[str, Any]]]): Optional sort parameter from the request.
191-
bbox (Optional[List[float]]): Bounding box to filter collections by spatial extent.
192190
q (Optional[List[str]]): Free text search terms.
193191
query (Optional[Dict[str, Dict[str, Any]]]): Query extension parameters.
194192
filter (Optional[Dict[str, Any]]): Structured query in CQL2 format.
@@ -316,44 +314,6 @@ async def get_all_collections(
316314
query_parts.append({"bool": {"must_not": {"match_all": {}}}})
317315
raise
318316

319-
# Apply bbox filter if provided
320-
if bbox:
321-
# Parse bbox if it's a string (from GET requests)
322-
if isinstance(bbox, str):
323-
try:
324-
bbox = [float(x.strip()) for x in bbox.split(",")]
325-
except (ValueError, AttributeError) as e:
326-
logger.error(f"Invalid bbox format: {bbox}, error: {e}")
327-
bbox = None
328-
329-
if bbox and len(bbox) >= 4:
330-
# Extract 2D coordinates (bbox can be 2D [minx, miny, maxx, maxy] or 3D [minx, miny, minz, maxx, maxy, maxz])
331-
# For geospatial queries, we discard altitude (z) values
332-
minx, miny = bbox[0], bbox[1]
333-
if len(bbox) == 4:
334-
# 2D bbox
335-
maxx, maxy = bbox[2], bbox[3]
336-
else:
337-
# 3D bbox - extract indices 3,4 for maxx,maxy, discarding altitude at indices 2 (minz) and 5 (maxz)
338-
maxx, maxy = bbox[3], bbox[4]
339-
340-
# Convert bbox to a polygon for geo_shape query
341-
bbox_polygon = {
342-
"type": "Polygon",
343-
"coordinates": bbox2polygon(minx, miny, maxx, maxy),
344-
}
345-
# Add geo_shape query to filter collections by bbox_shape field
346-
query_parts.append(
347-
{
348-
"geo_shape": {
349-
"bbox_shape": {
350-
"shape": bbox_polygon,
351-
"relation": "intersects",
352-
}
353-
}
354-
}
355-
)
356-
357317
# Combine all query parts with AND logic if there are multiple
358318
datetime_filter = None
359319
if datetime:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
"""library version."""
2-
__version__ = "6.5.0"
2+
__version__ = "6.5.1"

stac_fastapi/opensearch/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
desc = f.read()
77

88
install_requires = [
9-
"stac-fastapi-core==6.5.0",
10-
"sfeos-helpers==6.5.0",
9+
"stac-fastapi-core==6.5.1",
10+
"sfeos-helpers==6.5.1",
1111
"opensearch-py~=2.8.0",
1212
"opensearch-py[async]~=2.8.0",
1313
"uvicorn~=0.23.0",

0 commit comments

Comments
 (0)