Skip to main content

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 layer raster_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=False in backend_options for the opposite; raster_layers.should_generate_tile in the index is the right tool for deciding what to cache.
  • No coverage is a bodyless 204, with an explicit Content-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 a content-length and 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 colormap from 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 — so set-colormap and later edits take effect immediately. An explicit colormap / colormap_name query parameter always wins. Because the colormap travels per asset, per-raster rendering (leveling from rescale_range) has somewhere to live later.
  • Whole-mosaic operations are unsupported. /info, /statistics, /preview and 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

macrostrat_raster_layers-0.3.1.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

macrostrat_raster_layers-0.3.1-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file macrostrat_raster_layers-0.3.1.tar.gz.

File metadata

  • Download URL: macrostrat_raster_layers-0.3.1.tar.gz
  • Upload date:
  • Size: 13.6 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

Hashes for macrostrat_raster_layers-0.3.1.tar.gz
Algorithm Hash digest
SHA256 86b379b6a9ff8dea71d60ff7f804f0cb7c4addb742e1aede62fc8e48570e62f2
MD5 8e0183004ec4dfa39aa5c6a5fb7a7f7f
BLAKE2b-256 183e4cdba750c81e430195d4f771f3d31464cd8770753c492dbabb40cf728a34

See more details on using hashes here.

File details

Details for the file macrostrat_raster_layers-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: macrostrat_raster_layers-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 16.7 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

Hashes for macrostrat_raster_layers-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c9a17df2ed9fa7e23d94fe751635b5229c594d21848d57da1a4bd0423217d57d
MD5 d6ef985a26236b9fe9bd5f4cea00713d
BLAKE2b-256 9ade4605b851af0f3819504e09968932d00e3a139b70ae2d181828f63cf4ed40

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.2

2 files

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page