Skip to content

Commit

Permalink
implement filtering STAC API by querying times
Browse files Browse the repository at this point in the history
  • Loading branch information
lubojr committed Jul 15, 2024
1 parent 761f4d5 commit 758ed33
Showing 1 changed file with 29 additions and 42 deletions.
71 changes: 29 additions & 42 deletions src/eodash_catalog/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,29 +106,17 @@ def handle_STAC_based_endpoint(
catalog, collection_config["Name"], collection_config, catalog_config, endpoint_config
)
for location in collection_config["Locations"]:
if "FilterDates" in location:
collection = process_STACAPI_Endpoint(
catalog_config=catalog_config,
endpoint_config=endpoint_config,
collection_config=collection_config,
catalog=catalog,
options=options,
headers=headers,
bbox=",".join(map(str, location["Bbox"])),
filter_dates=location["FilterDates"],
root_collection=root_collection,
)
else:
collection = process_STACAPI_Endpoint(
catalog_config=catalog_config,
endpoint_config=endpoint_config,
collection_config=collection_config,
catalog=catalog,
options=options,
headers=headers,
bbox=",".join(map(str, location["Bbox"])),
root_collection=root_collection,
)
collection = process_STACAPI_Endpoint(
catalog_config=catalog_config,
endpoint_config=endpoint_config,
collection_config=collection_config,
catalog=catalog,
options=options,
headers=headers,
filter_dates=location.get("FilterDates"),
bbox=",".join(map(str, location["Bbox"])),
root_collection=root_collection,
)
# Update identifier to use location as well as title
# TODO: should we use the name as id? it provides much more
# information in the clients
Expand Down Expand Up @@ -159,25 +147,18 @@ def handle_STAC_based_endpoint(
if isinstance(c_child, Collection):
root_collection.extent.spatial.bboxes.append(c_child.extent.spatial.bboxes[0])
else:
bbox = None
if "Bbox" in endpoint_config:
root_collection = process_STACAPI_Endpoint(
catalog_config=catalog_config,
endpoint_config=endpoint_config,
collection_config=collection_config,
catalog=catalog,
options=options,
headers=headers,
bbox=",".join(map(str, endpoint_config["Bbox"])),
)
else:
root_collection = process_STACAPI_Endpoint(
catalog_config=catalog_config,
endpoint_config=endpoint_config,
collection_config=collection_config,
catalog=catalog,
options=options,
headers=headers,
)
bbox = ",".join(map(str, endpoint_config["Bbox"]))
root_collection = process_STACAPI_Endpoint(
catalog_config=catalog_config,
endpoint_config=endpoint_config,
collection_config=collection_config,
catalog=catalog,
options=options,
headers=headers,
bbox=bbox,
)

add_example_info(root_collection, collection_config, endpoint_config, catalog_config)
return root_collection
Expand All @@ -199,14 +180,20 @@ def process_STACAPI_Endpoint(
collection = get_or_create_collection(
catalog, endpoint_config["CollectionId"], collection_config, catalog_config, endpoint_config
)
datetime_query = ["1900-01-01T00:00:00Z", "3000-01-01T00:00:00Z"]
if query := endpoint_config.get("Query"):
if start := query.get("Start"):
datetime_query[0] = start
if end := query.get("End"):
datetime_query[1] = end

api = Client.open(endpoint_config["EndPoint"], headers=headers)
if bbox is None:
bbox = [-180, -90, 180, 90]
results = api.search(
collections=[endpoint_config["CollectionId"]],
bbox=bbox,
datetime=["1900-01-01T00:00:00Z", "3000-01-01T00:00:00Z"],
datetime=datetime_query, # type: ignore
)
# We keep track of potential duplicate times in this list
added_times = {}
Expand Down

0 comments on commit 758ed33

Please sign in to comment.