Skip to content

Tiler Factories

Mosaics: titiler.pgstac.factory.MosaicTilerFactory

TiTiler.PgSTAC provides a MosaicTilerFactory factory which is an helper functions to create FastAPI router (fastapi.APIRouter) with a minimal set of endpoints.

# Minimal PgSTAC Mosaic Application
from contextlib import asynccontextmanager

from fastapi import FastAPI
from titiler.pgstac.db import close_db_connection, connect_to_db
from titiler.pgstac.factory import MosaicTilerFactory

@asynccontextmanager
async def lifespan(app: FastAPI):
    """FastAPI Lifespan."""
    # Create Connection Pool
    await connect_to_db(app)
    yield
    # Close the Connection Pool
    await close_db_connection(app)


app = FastAPI(lifespan=lifespan)

mosaic = MosaicTilerFactory(
    path_dependency=lambda: "aaaaaaaaaaaaaaaaaaaaa",
)
app.include_router(mosaic.router)

Important

The MosaicTilerFactory requires a path_dependency, which should be a Callable that return a search_id (PgSTAC Search Hash).

For the /searches/{search_id} endpoints the path_dependency is set to titiler.pgstac.dependencies.SearchIdParams and to titiler.pgstac.dependencies.CollectionIdParams for the /collections/{collection_id} endpoints.

`

Method URL Output Description
GET /tiles JSON List of OGC Tilesets available
GET /tiles/{tileMatrixSetId} JSON OGC Tileset metadata
GET /tiles/{TileMatrixSetId}/{z}/{x}/{Y}/assets JSON Return a list of assets which overlap a given tile
GET /tiles/{TileMatrixSetId}/{z}/{x}/{y}[@{scale}x][.{format}] image/bin Create a web map tile image for a search query and a tile index
GET /{TileMatrixSetId}/map HTML Simple map viewer OPTIONAL
GET /{TileMatrixSetId}/tilejson.json JSON (TileJSON) Return a Mapbox TileJSON document
GET /{TileMatrixSetId}/WMTSCapabilities.xml XML Return OGC WMTS Get Capabilities
GET /point/{lon}x{lat} JSON (Point) Return pixel values from assets intersecting with a given point
GET /point/{lon},{lat}/assets JSON Return a list of assets which overlap a given point
GET /bbox/{minx},{miny},{maxx},{maxy}[/{width}x{height}].{format} image/bin Create an image from part of a dataset OPTIONAL
POST /feature[/{width}x{height}][.{format}] image/bin Create an image from a GeoJSON feature OPTIONAL
POST /statistics GeoJSON (Statistics) Return statistics for geojson features OPTIONAL

Extensions

searchInfoExtension

Method URL Output Description
GET /info JSON (Infos) Return list of Search entries with Mosaic type OPTIONAL
app = FastAPI()
mosaic = MosaicTilerFactory(
    path_dependency=lambda: "aaaaaaaaaaaaaaaaaaaaa",
    extensions=[
        searchInfoExtension(),
    ],
)
app.include_router(mosaic.router)

register and list

Method URL Output Description
POST /register JSON (Register) Register Search query OPTIONAL
GET /list JSON (Info) Return Search query infos OPTIONAL
app = FastAPI()
mosaic = MosaicTilerFactory(
    path_dependency=lambda: "aaaaaaaaaaaaaaaaaaaaa",
)
app.include_router(mosaic.router)

add_search_register_route(app)
add_search_list_route(app)

Items: titiler.core.factory.MultiBaseTilerFactory

For the single STAC item endpoints we use TiTiler's MultiBaseTilerFactory with a custom path_dependency to use item_id and collection_id path parameter (instead of the default url query param).

This custom path_dependency will connect to PgSTAC directly to fetch the STAC Item and pass it to a custom Reader.

# Minimal PgSTAC Item Application
from contextlib import asynccontextmanager

from fastapi import FastAPI

from titiler.core.factory import MultiBaseTilerFactory

from titiler.pgstac.db import close_db_connection, connect_to_db
from titiler.pgstac.dependencies import ItemPathParams
from titiler.pgstac.reader import PgSTACReader


@asynccontextmanager
async def lifespan(app: FastAPI):
    """FastAPI Lifespan."""
    # Create Connection Pool
    await connect_to_db(app)
    yield
    # Close the Connection Pool
    await close_db_connection(app)


app = FastAPI(lifespan=lifespan)

item = MultiBaseTilerFactory(
    reader=PgSTACReader,
    path_dependency=ItemPathParams,
    router_prefix="/collections/{collection_id}/items/{item_id}",
)
app.include_router(item.router, prefix="/collections/{collection_id}/items/{item_id}")