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.
Metadata
Release files for macrostrat.raster_layers 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| macrostrat_raster_layers-0.3.3.tar.gz | 13.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| macrostrat_raster_layers-0.3.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.7 kB
Release files / macrostrat_raster_layers-0.3.3.tar.gz
| Download URL | macrostrat_raster_layers-0.3.3.tar.gz |
|---|---|
| Size | 13.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f4182332dde75e477a39bcdb20c453870edc86f760f8619177e4b22c7e44a7b
|
|
BLAKE2b-256 checksum How to use checksums |
9f262f3638b203046a22b2ca3d78f1d33ee4f411e0332d71b156d8f4b162bc38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / macrostrat_raster_layers-0.3.3-py3-none-any.whl
| Download URL | macrostrat_raster_layers-0.3.3-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5482446a832eb00d1d995d1497cb2e3011c2f263fa4d55f7b3d6ec29dd542063
|
|
BLAKE2b-256 checksum How to use checksums |
07938f6b06277d6918c20fdc43f409c93e23b27920c1400d0d02d07f44c3e896
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|