Skip to content

Commit

Permalink
add support for passing dimensions to WMS requests
Browse files Browse the repository at this point in the history
add support for arbitrary time interval of SH layers without concept of locations
  • Loading branch information
lubojr committed Aug 5, 2024
1 parent 8dc997f commit 552899c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
48 changes: 39 additions & 9 deletions src/eodash_catalog/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ def handle_SH_WMS_endpoint(
catalog_config: dict, endpoint_config: dict, collection_config: dict, catalog: Catalog
) -> Collection:
# create collection and subcollections (based on locations)
root_collection = get_or_create_collection(
catalog, collection_config["Name"], collection_config, catalog_config, endpoint_config
)
if "Locations" in collection_config:
root_collection = get_or_create_collection(
catalog, collection_config["Name"], collection_config, catalog_config, endpoint_config
)
for location in collection_config["Locations"]:
# create and populate location collections based on times
# TODO: Should we add some new description per location?
Expand Down Expand Up @@ -373,6 +373,26 @@ def handle_SH_WMS_endpoint(
for c_child in root_collection.get_children():
if isinstance(c_child, Collection):
root_collection.extent.spatial.bboxes.append(c_child.extent.spatial.bboxes[0])
else:
# if locations are not provided, treat the collection as a
# general proxy to the sentinel hub layer
times = get_collection_times_from_config(endpoint_config)
bbox = endpoint_config.get("Bbox", [-180, -85, 180, 85])
for time in times:
item = Item(
id=time,
bbox=bbox,
properties={},
geometry=None,
datetime=parser.isoparse(time),
stac_extensions=[
"https://stac-extensions.github.io/web-map-links/v1.1.0/schema.json",
],
)
add_projection_info(endpoint_config, item)
add_visualization_info(item, collection_config, endpoint_config, time=time)
item_link = root_collection.add_item(item)
item_link.extra_fields["datetime"] = time
# eodash v4 compatibility
add_collection_information(catalog_config, root_collection, collection_config)
add_visualization_info(root_collection, collection_config, endpoint_config)
Expand Down Expand Up @@ -606,16 +626,22 @@ def add_visualization_info(
"role": ["data"],
}
)
dimensions = {}
if dimensions_config := endpoint_config.get("Dimensions", {}):
for key, value in dimensions_config.items():
dimensions[key] = value
if time is not None:
if endpoint_config["Name"] == "Sentinel Hub WMS":
# SH WMS for public collections needs time interval, we use full day here
datetime_object = datetime.strptime(time, "%Y-%m-%d")
datetime_object = datetime.fromisoformat(time)
start = datetime_object.isoformat()
end = (datetime_object + timedelta(days=1) - timedelta(milliseconds=1)).isoformat()
time_interval = f"{start}/{end}"
extra_fields["wms:dimensions"] = {"TIME": time_interval}
dimensions["TIME"] = time_interval
if endpoint_config["Name"] == "Sentinel Hub":
extra_fields["wms:dimensions"] = {"TIME": time}
dimensions["TIME"] = time
if dimensions != {}:
extra_fields["wms:dimensions"] = dimensions
stac_object.add_link(
Link(
rel="wms",
Expand All @@ -632,10 +658,14 @@ def add_visualization_info(
"role": ["data"],
}
)
dimensions = {}
if dimensions_config := endpoint_config.get("Dimensions", {}):
for key, value in dimensions_config.items():
dimensions[key] = value
if time is not None:
extra_fields["wms:dimensions"] = {
"TIME": time,
}
dimensions["TIME"] = time
if dimensions != {}:
extra_fields["wms:dimensions"] = dimensions
if "Styles" in endpoint_config:
extra_fields["wms:styles"] = endpoint_config["Styles"]
media_type = endpoint_config.get("MediaType", "image/jpeg")
Expand Down
4 changes: 2 additions & 2 deletions src/eodash_catalog/stac_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_or_create_collection(
)
times: list[str] = []
temporal_extent = TemporalExtent([[datetime.now(), None]])
if endpoint_config and endpoint_config.get("Type") == "OverwriteTimes":
if endpoint_config:
if endpoint_config.get("Times"):
times = list(endpoint_config.get("Times", []))
times_datetimes = sorted([parser.isoparse(time) for time in times])
Expand Down Expand Up @@ -389,7 +389,7 @@ def add_extra_fields(stac_object: Collection | Link, collection_config: dict) ->

def get_collection_times_from_config(endpoint_config: dict) -> list[str]:
times: list[str] = []
if endpoint_config and endpoint_config.get("Type") == "OverwriteTimes":
if endpoint_config:
if endpoint_config.get("Times"):
times = list(endpoint_config.get("Times", []))
elif endpoint_config.get("DateTimeInterval"):
Expand Down

0 comments on commit 552899c

Please sign in to comment.