Package: titiler.extensions
titiler.extensionsExtent TiTiler Tiler FactoriesInstallation$python-mpipinstall-Upip# From Pypi$python-mpipinstalltitiler.extensions# Or from sources$gitclonehttps://github.com/developmentseed/titiler.git
$cdtitiler&&python-mpipinstall-esrc/titiler/core-esrc/titiler/extensionsAvailable extensionscogValidateExtensionGoal: adds a/validateendpoint which return the content of rio-cogeoinfomethodAdditional requirements:titiler.extensions["cogeo"]cogViewerExtensionGoal: adds a/viewerendpoint which return an HTML viewer for simple COGsstacViewerExtensionGoal: adds a/viewerendpoint which return an HTML viewer for STAC itemwmsExtensionGoal: adds a/wmsendpoint to support OGC Web Map Service (GetTileandGetCapabilities) specificationUse extensionsExtensions must be set at TilerFactory's creation using theextensions=options.fromfastapiimportFastAPIfromtitiler.core.factoryimportTilerFactoryfromtitiler.extensionsimportcogValidateExtension# Create a FastAPI applicationapp=FastAPI(description="A lightweight Cloud Optimized GeoTIFF tile server")# Create a set of endpoints using TiTiler TilerFactorytiler=TilerFactory(router_prefix="/cog",extensions=[cogValidateExtension()# the cogeoExtension will add a rio-cogeo /validate endpoint])# Register endpoints to the applicationapp.include_router(tiler.router,prefix="/cog")Seetitiler.applicationfor a full example.Create your ownfromdataclassesimportdataclass,fieldfromtypingimportTuple,List,Optionalfromstarlette.responsesimportResponsefromfastapiimportDepends,FastAPI,Queryfromtitiler.core.factoryimportBaseTilerFactory,FactoryExtension,TilerFactoryfromtitiler.core.dependenciesimportRescalingParamsfromtitiler.core.factoryimportTilerFactoryfromtitiler.core.resources.enumsimportImageType@dataclassclassthumbnailExtension(FactoryExtension):"""Add endpoint to a TilerFactory."""# Set some optionsmax_size:int=field(default=128)# Register method is mandatory and must take a BaseTilerFactory object as inputdefregister(self,factory:BaseTilerFactory):"""Register endpoint to the tiler factory."""# register an endpoint to the factory's router@factory.router.get("/thumbnail",responses={200:{"content":{"image/png":{},"image/jpeg":{},},"description":"Return an image.",}},response_class=Response,)defthumbnail(# we can reuse the factory dependencysrc_path:str=Depends(factory.path_dependency),layer_params=Depends(factory.layer_dependency),dataset_params=Depends(factory.dataset_dependency),post_process=Depends(factory.process_dependency),rescale:Optional[List[Tuple[float,...]]]=Depends(RescalingParams),color_formula:Optional[str]=Query(None,title="Color Formula",description="rio-color formula (info: https://github.com/mapbox/rio-color)",),colormap=Depends(factory.colormap_dependency),render_params=Depends(factory.render_dependency),reader_params=Depends(factory.reader_dependency),env=Depends(factory.environment_dependency),):withrasterio.Env(**env):withfactory.reader(src_path,**reader_params)assrc:image=src.preview(max_size=self.max_size,**layer_params,**dataset_params,)ifpost_process:image=post_process(image)ifrescale:image.rescale(rescale)ifcolor_formula:image.apply_color_formula(color_formula)format=ImageType.jpegifimage.mask.all()elseImageType.pngcontent=image.render(img_format=format.driver,colormap=colormap,**format.profile,**render_params,)returnResponse(content,media_type=format.mediatype)# Use itapp=FastAPI()tiler=TilerFactory(extensions=[thumbnailExtension(max_size=64)])app.include_router(tiler.router)