Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cube:dimensions and overriding of colormap/expression #26

Merged
merged 9 commits into from
Aug 20, 2024
47 changes: 42 additions & 5 deletions titiler/stacapi/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,10 +629,20 @@ def get_layer_from_collections( # noqa: C901
tms_id: None for tms_id in tilematrixsets
}

# TODO: handle multiple intervals
# Check datacube extension
# https://github.com/stac-extensions/datacube?tab=readme-ov-file#temporal-dimension-object
if intervals := temporal_extent.intervals:
if (
"cube:dimensions" in collection.extra_fields
and "time" in collection.extra_fields["cube:dimensions"]
):
layer["time"] = [
python_datetime.datetime.strptime(
t,
"%Y-%m-%dT%H:%M:%SZ",
).strftime("%Y-%m-%d")
for t in collection.extra_fields["cube:dimensions"]["time"][
"values"
]
]
elif intervals := temporal_extent.intervals:
start_date = intervals[0][0]
end_date = (
intervals[0][1]
Expand Down Expand Up @@ -793,6 +803,11 @@ def get_tile( # noqa: C901
] = f"{start_datetime.strftime('%Y-%m-%dT%H:%M:%SZ')}/{end_datetime.strftime('%Y-%m-%dT%H:%M:%SZ')}"

query_params = layer.get("render") or {}
if "color_formula" in req:
query_params["color_formula"] = req["color_formula"]
if "expression" in req:
query_params["expression"] = req["expression"]

layer_params = get_dependency_params(
dependency=self.layer_dependency,
query_params=query_params,
Expand Down Expand Up @@ -959,6 +974,26 @@ def register_routes(self): # noqa: C901
"name": "TileCol",
"in": "query",
},
{
"required": False,
"schema": {
"title": "Color Formula",
"description": "rio-color formula (info: https://github.com/mapbox/rio-color)",
"type": "string",
},
"name": "color_formula",
"in": "query",
},
{
"required": False,
"schema": {
"title": "Colormap name",
"description": "JSON encoded custom Colormap",
"type": "string",
},
"name": "colormap",
"in": "query",
},
################
# GetFeatureInfo
# InfoFormat
Expand Down Expand Up @@ -1126,7 +1161,9 @@ def web_map_tile_service( # noqa: C901

colormap = get_dependency_params(
dependency=self.colormap_dependency,
query_params=layer.get("render") or {},
query_params={"colormap": req["colormap"]}
if "colormap" in req
else layer.get("render") or {},
)

content, media_type = render_image(
Expand Down
2 changes: 1 addition & 1 deletion titiler/stacapi/templates/wmts-getcapabilities_1.0.0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<TileMatrixSet>
<ows:Identifier>{{ tms.id }}</ows:Identifier>
{% if tms.crs.to_epsg() %}
<ows:SupportedCRS>urn:ogc:def:crs:epsg::{{tms.crs.to_epsg()}}</ows:SupportedCRS>
<ows:SupportedCRS>urn:ogc:def:crs:EPSG::{{tms.crs.to_epsg()}}</ows:SupportedCRS>
{% else %}
<ows:SupportedCRS>{{ tms.crs.srs.replace("http://www.opengis.net/def/", "urn:ogc:def:").replace("/", ":")}} </ows:SupportedCRS>
{% endif %}
Expand Down