跳转到主要内容

一个基于PostGIS的轻量级动态矢量瓦片服务器。

项目描述

一个基于PostGIS的轻量级动态矢量瓦片服务器。

Test Coverage Package version License


文档: https://developmentseed.org/timvt/

源码: https://github.com/developmentseed/timvt


TiMVT(发音为 tee-MVT),是一个Python包,它帮助从PostGIS数据库创建轻量级的矢量瓦片服务

timvt基于 现代且快速FastAPI 框架,使用Python的async/await异步代码编写,以提升性能并处理高负载。

TiMVT 主要受 urbica/martinCrunchyData/pg_tileserv 项目的启发。

特性

  • 通过 morecantile 支持多个TileMatrixSets。默认设置为WebMercatorQuad,这是大多数Web地图库中使用的常用Web Mercator投影。
  • 使用 FastAPI 构建
  • 表和函数图层
  • 使用 asyncpg 实现的异步API

安装

从PyPI安装 TiMVT

# update pip (optional)
python -m pip install pip -U

# install timvt
python -m pip install timvt

或从源码安装

$ git clone https://github.com/developmentseed/timvt.git
$ cd timvt
$ python -m pip install -e .

PostGIS/Postgres

TiMVT 主要依赖于 ST_AsMVT 函数,并且需要PostGIS >= 2.5。

如果您想了解更多关于 ST_AsMVT 函数或从 PostGIS 创建矢量瓦片的信息,请阅读 Paul Ramsey 的这篇优秀文章:https://info.crunchydata.com/blog/dynamic-vector-tiles-from-postgis

配置

要创建矢量瓦片,应用程序需要访问 PostGIS 数据库。 TiMVT 使用 pydantic 的配置模式,该模式利用环境变量和/或 .env 文件将变量传递给应用程序。

.env 文件的示例可以在 .env.example 中找到。

POSTGRES_USER=username
POSTGRES_PASS=password
POSTGRES_DBNAME=postgis
POSTGRES_HOST=0.0.0.0
POSTGRES_PORT=5432

# Or you can also define the DATABASE_URL directly
DATABASE_URL=postgresql://username:password@0.0.0.0:5432/postgis

最小化应用程序

from timvt.db import close_db_connection, connect_to_db
from timvt.factory import VectorTilerFactory
from timvt.layer import FunctionRegistry
from fastapi import FastAPI, Request

# Create Application.
app = FastAPI()

# Add Function registry to the application state
app.state.function_catalog = FunctionRegistry()

# Register Start/Stop application event handler to setup/stop the database connection
# and populate `app.state.table_catalog`
@app.on_event("startup")
async def startup_event():
    """Application startup: register the database connection and create table list."""
    await connect_to_db(app)


@app.on_event("shutdown")
async def shutdown_event():
    """Application shutdown: de-register the database connection."""
    await close_db_connection(app)

# Register endpoints.
mvt_tiler = VectorTilerFactory(
    with_tables_metadata=True,
    with_functions_metadata=True,  # add Functions metadata endpoints (/functions.json, /{function_name}.json)
    with_viewer=True,
)
app.include_router(mvt_tiler.router, tags=["Tiles"])

默认应用程序

虽然我们鼓励用户使用 TiMVT 包编写自己的应用程序,但我们还提供了一个默认的 生产就绪 应用程序。

# Install timvt dependencies and Uvicorn (a lightning-fast ASGI server)
$ pip install timvt 'uvicorn[standard]>=0.12.0,<0.14.0'

# Set Database URL environment variable so TiMVT can access it
$ export DATABASE_URL=postgresql://username:password@0.0.0.0:5432/postgis

# Launch Demo Application
$ uvicorn timvt.main:app --reload

您还可以使用官方的 Docker 镜像。

$ docker run \
    -p 8081:8081 \
    -e PORT=8081 \
    -e DATABASE_URL=postgresql://username:password@0.0.0.0:5432/postgis \
    ghcr.io/developmentseed/timvt:latest

:endpoint:/docs

贡献与发展

请参阅 CONTRIBUTING.md

许可证

请参阅 LICENSE

作者

Development Seed 创建。

变更

请参阅 CHANGES.md

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源代码分发

timvt-0.7.0.tar.gz (24.6 kB 查看哈希)

上传时间 源代码

构建分发

timvt-0.7.0-py3-none-any.whl (24.8 kB 查看哈希)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面