This repository has been archived on 2026-03-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
mars-titiler/app.py
2026-02-25 11:38:05 +08:00

64 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Titiler-based Mars tile server for MGS MOLA ClrShade global basemap"""
import math
from fastapi import FastAPI
from pyproj import CRS
from morecantile import tms, TileMatrixSet
from rio_tiler.io import Reader
from titiler.core.factory import TilerFactory
# Mars SimpleCylindrical CRS (equidistant cylindrical projection in meters)
MARS_CRS = CRS.from_proj4(
"+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 "
"+a=3396190 +b=3396190 +units=m +no_defs"
)
# Mars extent in equidistant cylindrical projection
# x = R × lon_rad, y = R × lat_rad
_R = 3396190
_MAX_X = _R * math.pi # ≈ 10,669,442 m (corresponds to ±180°)
_MAX_Y = _R * math.pi / 2 # ≈ 5,334,721 m (corresponds to ±90°)
# Custom TMS for Mars with matrix_scale=[2, 1] to match Cesium GeographicTilingScheme
MARS_TMS = TileMatrixSet.custom(
crs=MARS_CRS,
extent=(-_MAX_X, -_MAX_Y, _MAX_X, _MAX_Y),
identifier="MarsCylindrical",
matrix_scale=[2, 1],
)
# Register custom TMS
tms = tms.register({"MarsCylindrical": MARS_TMS})
# Create FastAPI app
app = FastAPI(
title="Titiler Mars",
description="Mars MGS MOLA Color-Shaded Relief global tile server powered by Titiler",
)
# Create COG Tiler with Mars TMS support
cog = TilerFactory(
reader=Reader,
supported_tms=tms,
)
app.include_router(cog.router, tags=["Cloud Optimized GeoTIFF"])
@app.get("/", include_in_schema=False)
def landing():
"""Landing page."""
return {
"title": "Titiler Mars Tile Server",
"description": "Mars MGS MOLA Color-Shaded Relief global tile server",
"endpoints": {
"tiles": "/tiles/MarsCylindrical/{z}/{x}/{y}?url=<data_url>",
"tilejson": "/MarsCylindrical/tilejson.json?url=<data_url>",
"info": "/info?url=<data_url>",
"preview": "/preview.png?url=<data_url>&max_size=512",
"docs": "/docs",
},
}