macrostrat.raster_layers
Serve the layers in a macrostrat.raster_index database as
mosaicked map tiles, as FastAPI routes mountable in any application.
Given a tile, the index says which COGs cover it and in what order; this package
reads them, composites them, and renders the result. It is titiler's
MosaicTilerFactory with the assets coming from a live spatial query instead of
a MosaicJSON document, so tiling, rescaling, colormaps and output formats are all
inherited rather than reimplemented.
Usage
from fastapi import FastAPI
from macrostrat.raster_index import RasterIndex
from macrostrat.raster_layers import RasterLayerConfig, register_raster_layers
app = FastAPI()
index = RasterIndex("postgresql://localhost:5432/macrostrat")
register_raster_layers(
app,
index,
[
# A unified layer over several indexed collections, composited in order.
RasterLayerConfig(
slug="mineral-maps",
layers=["emit-minerals", "aviris-minerals"],
resampling="nearest", # categorical data
),
RasterLayerConfig(slug="elevation", resampling="bilinear"),
],
prefix="/rasters",
)
Each layer gets titiler's full mosaic route set — /tiles/{tileMatrixSetId}/{z}/{x}/{y},
/{tileMatrixSetId}/tilejson.json, /info, /point/{lon},{lat}, the
/assets lookups — plus two of its own:
/footprints/{z}/{x}/{y}— coverage as a vector tile, MVT layerraster_footprints. The raster counterpart to a map-footprints layer: where the data is, without reading a pixel./footprints— the same thing as GeoJSON, for small layers and diagnostics.
register_raster_layers installs its own exception handlers, so a host
application needs no extra setup. Don't register titiler's MOSAIC_STATUS_CODES
after mounting — it would replace the no-coverage handler with one that
returns a body-carrying 204 (see below).
Behavior worth knowing
- Overscaled tiles keep rendering. Zooming past a raster's native
resolution magnifies it rather than making the layer vanish, which is what
every other raster service does. Set
allow_overscaled=Falseinbackend_optionsfor the opposite;raster_layers.should_generate_tilein the index is the right tool for deciding what to cache. - No coverage is a bodyless
204, with an explicitContent-Length: 0. Both details matter: titiler's stock handler returns a 204 carrying a JSON body, and Starlette omits the length header entirely — either one makes Varnish fail the fetch and turn ordinary panning into 503s. Watch out for compression middleware too: gzipping an empty body re-attaches acontent-lengthand reintroduces the same failure. - Colormaps default per layer, and ride along with the assets. Categorical
rasters are unreadable without their palette, so when a request doesn't send
one, the layer's
colormapfrom the index is used. It comes back on the same query that decides which rasters to read — one database round trip per tile, no cache to invalidate — soset-colormapand later edits take effect immediately. An explicitcolormap/colormap_namequery parameter always wins. Because the colormap travels per asset, per-raster rendering (leveling fromrescale_range) has somewhere to live later. - Whole-mosaic operations are unsupported.
/info,/statistics,/previewand friends would mean reading every raster in a layer; layer-wide metadata belongs to the index. - No tile caching. Left to the host application's caching layer.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file macrostrat_raster_layers-0.2.1.tar.gz.
File metadata
- Download URL: macrostrat_raster_layers-0.2.1.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6042d861a206ec4956191231466cff97afb3dbc4885e92623112375906fecd63
|
|
| MD5 |
56411101118d3b9c8564c084d0b04901
|
|
| BLAKE2b-256 |
eacdae44702bef0cb868acf269fd78681b9de9590b9eb60c99f80283f78af9be
|
File details
Details for the file macrostrat_raster_layers-0.2.1-py3-none-any.whl.
File metadata
- Download URL: macrostrat_raster_layers-0.2.1-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.11.29 {"installer":{"name":"uv","version":"0.11.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ae8c6119ff627fa0d7130189175b8653c41e962fa608355bb7cf2db28c28396
|
|
| MD5 |
2eb38109ed26efa48fd94a574629af63
|
|
| BLAKE2b-256 |
487403467091ed3024d408cc329c148c051587c2026267f6aa696b5c3653e74d
|