Skip to content

Commit 161916b

Browse files
committed
fix: stac search query dependency [GDD-3825]
1 parent 3f0fd9c commit 161916b

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

Diff for: titiler/stacapi/dependencies.py

+18-9
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,7 @@ def ItemIdParams(
152152
)
153153

154154

155-
def STACSearchParams(
156-
request: Request,
157-
collection_id: Annotated[
158-
str,
159-
Path(description="STAC Collection Identifier"),
160-
],
161-
ids: Annotated[Optional[str], Query(description="Filter by Ids.")] = None,
155+
def STACQueryParams(
162156
bbox: Annotated[
163157
Optional[str],
164158
Query(description="Spatial Filter."),
@@ -191,8 +185,6 @@ def STACSearchParams(
191185
) -> Dict:
192186
"""Dependency to construct STAC API Search Query."""
193187
return {
194-
"collections": [collection_id],
195-
"ids": ids.split(",") if ids else None,
196188
"bbox": list(map(float, bbox.split(","))) if bbox else None,
197189
"datetime": datetime,
198190
"sortby": sortby,
@@ -201,3 +193,20 @@ def STACSearchParams(
201193
"limit": limit or 10,
202194
"max_items": max_items or 100,
203195
}
196+
197+
198+
def STACSearchParams(
199+
request: Request,
200+
collection_id: Annotated[
201+
str,
202+
Path(description="STAC Collection Identifier"),
203+
],
204+
ids: Annotated[Optional[str], Query(description="Filter by Ids.")] = None,
205+
query_params=Depends(STACQueryParams),
206+
) -> Dict:
207+
"""Dependency to construct STAC API Search Query."""
208+
return {
209+
"collections": [collection_id],
210+
"ids": ids.split(",") if ids else None,
211+
**query_params,
212+
}

Diff for: titiler/stacapi/factory.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,12 @@
4545
from titiler.core.utils import render_image
4646
from titiler.mosaic.factory import PixelSelectionParams
4747
from titiler.stacapi.backend import STACAPIBackend
48-
from titiler.stacapi.dependencies import APIParams, STACApiParams, STACSearchParams
48+
from titiler.stacapi.dependencies import (
49+
APIParams,
50+
STACApiParams,
51+
STACQueryParams,
52+
STACSearchParams,
53+
)
4954
from titiler.stacapi.models import FeatureInfo, LayerDict
5055
from titiler.stacapi.pystac import Client
5156
from titiler.stacapi.settings import CacheSettings, RetrySettings
@@ -723,12 +728,12 @@ class OGCWMTSFactory(BaseTilerFactory):
723728

724729
path_dependency: Callable[..., APIParams] = STACApiParams
725730

726-
search_dependency: Callable[..., Dict] = STACSearchParams
727-
728731
# In this factory, `reader` should be a Mosaic Backend
729732
# https://developmentseed.org/cogeo-mosaic/advanced/backends/
730733
reader: Type[BaseBackend] = STACAPIBackend
731734

735+
query_dependency: Callable[..., Any] = STACQueryParams
736+
732737
# Because the endpoints should work with STAC Items,
733738
# the `layer_dependency` define which query parameters are mandatory/optional to `display` images
734739
# Defaults to `titiler.core.dependencies.AssetsBidxExprParams`, `assets=` or `expression=` is required
@@ -806,7 +811,6 @@ def get_tile( # noqa: C901
806811
# STAC Query parameter provided by the the render extension and QueryParameters
807812
###########################################################
808813
query_params = copy(layer.get("render")) or {}
809-
query_params["collections"] = [layer["collection"]]
810814

811815
if req_time:
812816
start_datetime = python_datetime.datetime.strptime(
@@ -825,9 +829,10 @@ def get_tile( # noqa: C901
825829
query_params["expression"] = req["expression"]
826830

827831
search_query = get_dependency_params(
828-
dependency=self.search_dependency,
832+
dependency=self.query_dependency,
829833
query_params=query_params,
830834
)
835+
search_query["collections"] = [layer["collection"]]
831836

832837
layer_params = get_dependency_params(
833838
dependency=self.layer_dependency,

0 commit comments

Comments
 (0)