Preview Images (Thumbnails-STAC)¶
Titiler¶
The following Documentation is a step by step guide for how to create stac-thumbnails with titiler.
Titiler API¶
You can test the Titiler API.
Query Parameters¶
The Query parameters are documented under this link.
Example Thumbnail¶
In this example a thumbnail will be created from a GeoTIFF in output format PNG. Furthermore, the GeoTIFF will be reprojected to a different CRS.
import requests
from pyproj import CRS
# Define the endpoint
endpoint = "https://titiler.services.eodc.eu/cog/preview"
# Define the url of the GeoTIFF
url = "https://objectstore.eodc.eu:2222/88346baf22914e828ad2c1763e5e01ff:greenness-austria/2022/greenness_max_id66904_2022.tiff"
# Define input and output CRS
crs_input = CRS.from_epsg(3035).to_wkt()
crs_output = CRS.from_epsg(4326).to_wkt()
# Define the query parameters as a dictionary
# Define "rescale": min, max (min, max values of a Band, e.g. with rasterio --> .min(), .max())
# --> rescale is used to normalize image bands, e.g.: bidx: 1, ranges from 0-19, which is not color encoded.
# Titiler uses this rescaling information to normalize the band values from their original range (0-19) to the 0-255 range,
# making the image ready for proper visualization.
# Define "nodata": str, int, float (Overwrite internal Nodata value.)
# Define "colormap_name": rio-tiler color map name
# Define "dst_crs": wkt
# Define "coord_crs": wkt
query_parameters = {
"format": "png",
"url": url, #required
"rescale": "1,19",
"nodata": "-9999",
"colormap_name": "greens_r",
"dst_crs": crs_output,
"coord_crs": crs_input
}
# Create a Request object
request = requests.Request('GET', endpoint, params=query_parameters)
# Prepare the request
href = request.prepare()
# Print the full URL with the query parameters
print(href.url)
Output¶
Create Asset¶
Finally add the created titiler url to an asset and add the asset to an item.
import pystac
asset = pystac.Asset(
href=href,
media_type=pystac.MediaType.PNG,
roles=["overview"]
)
item.add_asset(key=asset, asset=asset)