Combine MVT and Features


Please checkout the developmentseed/tipg which is the result of the merge between tifeatures and timvt.

TiFeatures and TiMVT share a lot of in common and it's possible to create a unique FastAPI application with both Features and MVT endpoints:

"""Features and MVT app."""

from tifeatures.db import close_db_connection, connect_to_db, register_table_catalog
from tifeatures.factory import Endpoints
from timvt.factory import VectorTilerFactory
from fastapi import FastAPI
from starlette_cramjam.middleware import CompressionMiddleware

app = FastAPI(
    title="Features and MVT",

# Register endpoints.
endpoints = Endpoints()
app.include_router(endpoints.router, tags=["Features"])

# By default the VectorTilerFactory will only create tiles/ and tilejson.json endpoints
mvt_endpoints = VectorTilerFactory()


async def startup_event() -> None:
    """Connect to database on startup."""
    await connect_to_db(app)
    # TiMVT and TiFeatures share the same `Table_catalog` format
    # see
    await register_table_catalog(app)

async def shutdown_event() -> None:
    """Close database connection."""
    await close_db_connection(app)


To run the example, copy the code to a file, and start uvicorn with:

uvicorn main:app --reload