From 529d8641a2065a37ef9b4eb893544aeafa37decb Mon Sep 17 00:00:00 2001 From: Emmanuel Mathot Date: Tue, 19 Nov 2024 17:45:58 +0100 Subject: [PATCH] Render Extension Render extension started during STAC render sprint in SatSummit Lisbon 2024. - listing (or showing to please Vincent) Please contribute to complete the feature to - generate the final XYZ link for rendering following the rules in STAC extensions - add a dedicated endpoint for render XYZ --- item.json | 1 + .../application/titiler/application/main.py | 2 ++ .../extensions/titiler/extensions/__init__.py | 1 + .../extensions/titiler/extensions/render.py | 34 +++++++++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 item.json create mode 100644 src/titiler/extensions/titiler/extensions/render.py diff --git a/item.json b/item.json new file mode 100644 index 00000000..2f8a2b75 --- /dev/null +++ b/item.json @@ -0,0 +1 @@ +{"id":"bs_to_save","bbox":[-120.61338752166166,38.54940283865057,-119.91905658168675,38.90577651328637],"type":"Feature","links":[{"rel":"collection","type":"application/json","href":"https://openveda.cloud/api/stac/collections/caldor-fire-burn-severity"},{"rel":"parent","type":"application/json","href":"https://openveda.cloud/api/stac/collections/caldor-fire-burn-severity"},{"rel":"root","type":"application/json","href":"https://openveda.cloud/api/stac/"},{"rel":"self","type":"application/geo+json","href":"https://openveda.cloud/api/stac/collections/caldor-fire-burn-severity/items/bs_to_save"},{"title":"Map of Item","href":"https://openveda.cloud/api/raster/collections/caldor-fire-burn-severity/items/bs_to_save/map?assets=cog_default&rescale=0%2C5&colormap_name=inferno_r","rel":"preview","type":"text/html"}],"assets":{"cog_default":{"href":"s3://veda-data-store/caldor-fire-burn-severity/bs_to_save.tif","type":"image/tiff; application=geotiff","roles":["data","layer"],"title":"Default COG Layer","proj:bbox":[-120.61338752166166,38.54940283865057,-119.91905658168675,38.90577651328637],"proj:epsg":4326,"proj:wkt2":"GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9122\"]],AXIS[\"Latitude\",NORTH],AXIS[\"Longitude\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]","proj:shape":[1103,2149],"description":"Cloud optimized default layer to display on map","raster:bands":[{"scale":1.0,"nodata":-100.0,"offset":0.0,"sampling":"area","data_type":"float64","histogram":{"max":4.0,"min":1.0,"count":11,"buckets":[10233,0,0,67409,0,0,71518,0,0,24232]},"statistics":{"mean":2.63295307741995,"stddev":0.7936384596443959,"maximum":4.0,"minimum":1.0,"valid_percent":32.191658745247146}}],"proj:geometry":{"type":"Polygon","coordinates":[[[-120.61338752166166,38.54940283865057],[-119.91905658168675,38.54940283865057],[-119.91905658168675,38.90577651328637],[-120.61338752166166,38.90577651328637],[-120.61338752166166,38.54940283865057]]]},"proj:projjson":{"id":{"code":4326,"authority":"EPSG"},"name":"WGS 84","type":"GeographicCRS","datum":{"name":"World Geodetic System 1984","type":"GeodeticReferenceFrame","ellipsoid":{"name":"WGS 84","semi_major_axis":6378137,"inverse_flattening":298.257223563}},"$schema":"https://proj.org/schemas/v0.4/projjson.schema.json","coordinate_system":{"axis":[{"name":"Geodetic latitude","unit":"degree","direction":"north","abbreviation":"Lat"},{"name":"Geodetic longitude","unit":"degree","direction":"east","abbreviation":"Lon"}],"subtype":"ellipsoidal"}},"proj:transform":[0.0003230948999417961,0.0,-120.61338752166166,0.0,-0.00032309489994179427,38.90577651328637,0.0,0.0,1.0]},"rendered_preview":{"title":"Rendered preview","href":"https://openveda.cloud/api/raster/collections/caldor-fire-burn-severity/items/bs_to_save/preview.png?assets=cog_default&rescale=0%2C5&colormap_name=inferno_r","rel":"preview","roles":["overview"],"type":"image/png"}},"geometry":{"type":"Polygon","coordinates":[[[-120.61338752166166,38.54940283865057],[-119.91905658168675,38.54940283865057],[-119.91905658168675,38.90577651328637],[-120.61338752166166,38.90577651328637],[-120.61338752166166,38.54940283865057]]]},"collection":"caldor-fire-burn-severity","properties":{"end_datetime":"2021-10-21T12:00:00+00:00","start_datetime":"2021-08-15T00:00:00+00:00"},"stac_version":"1.0.0","stac_extensions":["https://stac-extensions.github.io/raster/v1.1.0/schema.json","https://stac-extensions.github.io/projection/v1.1.0/schema.json"]} \ No newline at end of file diff --git a/src/titiler/application/titiler/application/main.py b/src/titiler/application/titiler/application/main.py index 0d3690d1..367b4b02 100644 --- a/src/titiler/application/titiler/application/main.py +++ b/src/titiler/application/titiler/application/main.py @@ -34,6 +34,7 @@ cogViewerExtension, stacExtension, stacViewerExtension, + renderExtension, ) from titiler.mosaic.errors import MOSAIC_STATUS_CODES from titiler.mosaic.factory import MosaicTilerFactory @@ -122,6 +123,7 @@ def validate_access_token(access_token: str = Security(api_key_query)): router_prefix="/stac", extensions=[ stacViewerExtension(), + renderExtension(), ], ) diff --git a/src/titiler/extensions/titiler/extensions/__init__.py b/src/titiler/extensions/titiler/extensions/__init__.py index 443753a3..326c2460 100644 --- a/src/titiler/extensions/titiler/extensions/__init__.py +++ b/src/titiler/extensions/titiler/extensions/__init__.py @@ -6,3 +6,4 @@ from .stac import stacExtension # noqa from .viewer import cogViewerExtension, stacViewerExtension # noqa from .wms import wmsExtension # noqa +from .render import renderExtension # noqa \ No newline at end of file diff --git a/src/titiler/extensions/titiler/extensions/render.py b/src/titiler/extensions/titiler/extensions/render.py new file mode 100644 index 00000000..83e294be --- /dev/null +++ b/src/titiler/extensions/titiler/extensions/render.py @@ -0,0 +1,34 @@ +"""render Extension.""" + +from typing import Any, Dict, List, Literal, Optional + +from attrs import define +from fastapi import Depends + +from titiler.core.factory import FactoryExtension, MultiBaseTilerFactory + +import pystac + + +@define +class renderExtension(FactoryExtension): + """Add /stac endpoint to a COG TilerFactory.""" + + ''' + ''' + def register(self, factory: MultiBaseTilerFactory): + """Register endpoint to the tiler factory.""" + + @factory.router.get("/renders", response_model=Dict, name="List STAC renders") + def show_renders( + src_path=Depends(factory.path_dependency) + ): + with factory.reader(src_path) as src: + renders = {} + # if hasattr(src.item, "ext") and src.item.ext.has("renders"): + # renders = src.item.ext.renders + + if src.item.properties.get("renders"): + renders = src.item.properties.get("renders") + + return {"renders": renders} \ No newline at end of file