Accessing and viewing imagery RGB bands data as separate COG files #720
Unanswered
nicolasvila
asked this question in
Q&A
Replies: 1 comment 1 reply
-
@nicolasvila this is absolutely possible but not with the default titiler application you'll need to do something like https://github.com/developmentseed/rio-viz/blob/main/rio_viz/io/reader.py#L14-L54 and titiler from typing import Any, Dict, List, Type
import attr
from braceexpand import braceexpand
from fastapi import FastAPI
from morecantile import TileMatrixSet
from rio_tiler.constants import WEB_MERCATOR_TMS
from rio_tiler.errors import InvalidBandName
from rio_tiler.io import BaseReader, MultiBandReader, Reader
from titiler.core.factory import MultiBandTilerFactory
@attr.s
class MultiFilesBandsReader(MultiBandReader):
"""Multiple Files as Bands."""
input: Any = attr.ib()
tms: TileMatrixSet = attr.ib(default=WEB_MERCATOR_TMS)
reader_options: Dict = attr.ib(factory=dict)
reader: Type[BaseReader] = attr.ib(default=Reader)
files: List[str] = attr.ib(init=False)
minzoom: int = attr.ib()
maxzoom: int = attr.ib()
@minzoom.default
def _minzoom(self):
return self.tms.minzoom
@maxzoom.default
def _maxzoom(self):
return self.tms.maxzoom
def __attrs_post_init__(self):
"""Fetch Reference band to get the bounds."""
self.files = list(braceexpand(self.input))
self.bands = [f"b{ix + 1}" for ix in range(len(self.files))]
with self.reader(self.files[0], tms=self.tms, **self.reader_options) as cog:
self.bounds = cog.bounds
self.crs = cog.crs
self.minzoom = cog.minzoom
self.maxzoom = cog.maxzoom
def _get_band_url(self, band: str) -> str:
"""Validate band's name and return band's url."""
if band not in self.bands:
raise InvalidBandName(f"{band} is not valid")
index = self.bands.index(band)
return self.files[index]
app = FastAPI()
endpoints = MultiBandTilerFactory(reader=MultiFilesBandsReader)
app.include_router(endpoints.router) then you'll be able to pass You'll also need to pass To be honest, for this it might just be easier to use STAC 😅 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I would like to serve RGB and display images from independent COG files stored on a S3 cloud storage.
Here are below some test COG files:
Is that possible using titiler to stream RGB image tiles generated from independent bands URLs?
That would also be great to pass a list of URL bands to the "map" viewer instead of a single COG URL.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions