Skip to content

Commit 0510fef

Browse files
committed
move add bbox shape, check if extension enabled
1 parent 3aafba0 commit 0510fef

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

stac_fastapi/core/stac_fastapi/core/serializers.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,11 @@ def stac_to_db(
139139
Returns:
140140
stac_types.Collection: The database-ready STAC Collection object.
141141
"""
142-
from stac_fastapi.sfeos_helpers.database import add_bbox_shape_to_collection
143-
144142
collection = deepcopy(collection)
145143
collection["links"] = resolve_links(
146144
collection.get("links", []), str(request.base_url)
147145
)
148146

149-
# Convert bbox to bbox_shape for geospatial queries (ES/OS specific)
150-
add_bbox_shape_to_collection(collection)
151-
152147
if get_bool_env("STAC_INDEX_ASSETS"):
153148
collection["assets"] = [
154149
{"es_key": k, **v} for k, v in collection.get("assets", {}).items()

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
)
3030
from stac_fastapi.sfeos_helpers import filter as filter_module
3131
from stac_fastapi.sfeos_helpers.database import (
32+
add_bbox_shape_to_collection,
3233
apply_collections_bbox_filter_shared,
3334
apply_collections_datetime_filter_shared,
3435
apply_free_text_filter_shared,
@@ -1349,6 +1350,12 @@ async def create_collection(self, collection: Collection, **kwargs: Any):
13491350
if await self.client.exists(index=COLLECTIONS_INDEX, id=collection_id):
13501351
raise ConflictError(f"Collection {collection_id} already exists")
13511352

1353+
if get_bool_env("ENABLE_COLLECTIONS_SEARCH") or get_bool_env(
1354+
"ENABLE_COLLECTIONS_SEARCH_ROUTE"
1355+
):
1356+
# Convert bbox to bbox_shape for geospatial queries (ES/OS specific)
1357+
add_bbox_shape_to_collection(collection)
1358+
13521359
# Index the collection in the database
13531360
await self.client.index(
13541361
index=COLLECTIONS_INDEX,
@@ -1452,6 +1459,12 @@ async def update_collection(
14521459
await self.delete_collection(collection_id)
14531460

14541461
else:
1462+
if get_bool_env("ENABLE_COLLECTIONS_SEARCH") or get_bool_env(
1463+
"ENABLE_COLLECTIONS_SEARCH_ROUTE"
1464+
):
1465+
# Convert bbox to bbox_shape for geospatial queries (ES/OS specific)
1466+
add_bbox_shape_to_collection(collection)
1467+
14551468
# Update the existing collection
14561469
await self.client.index(
14571470
index=COLLECTIONS_INDEX,

stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from stac_fastapi.opensearch.config import OpensearchSettings as SyncSearchSettings
3030
from stac_fastapi.sfeos_helpers import filter as filter_module
3131
from stac_fastapi.sfeos_helpers.database import (
32+
add_bbox_shape_to_collection,
3233
apply_collections_bbox_filter_shared,
3334
apply_collections_datetime_filter_shared,
3435
apply_free_text_filter_shared,
@@ -1339,6 +1340,12 @@ async def create_collection(self, collection: Collection, **kwargs: Any):
13391340
if await self.client.exists(index=COLLECTIONS_INDEX, id=collection_id):
13401341
raise ConflictError(f"Collection {collection_id} already exists")
13411342

1343+
if get_bool_env("ENABLE_COLLECTIONS_SEARCH") or get_bool_env(
1344+
"ENABLE_COLLECTIONS_SEARCH_ROUTE"
1345+
):
1346+
# Convert bbox to bbox_shape for geospatial queries (ES/OS specific)
1347+
add_bbox_shape_to_collection(collection)
1348+
13421349
await self.client.index(
13431350
index=COLLECTIONS_INDEX,
13441351
id=collection_id,
@@ -1430,6 +1437,12 @@ async def update_collection(
14301437
await self.delete_collection(collection_id=collection_id, **kwargs)
14311438

14321439
else:
1440+
if get_bool_env("ENABLE_COLLECTIONS_SEARCH") or get_bool_env(
1441+
"ENABLE_COLLECTIONS_SEARCH_ROUTE"
1442+
):
1443+
# Convert bbox to bbox_shape for geospatial queries (ES/OS specific)
1444+
add_bbox_shape_to_collection(collection)
1445+
14331446
await self.client.index(
14341447
index=COLLECTIONS_INDEX,
14351448
id=collection_id,

0 commit comments

Comments
 (0)