This is the multi-page printable view of this section. .
Documentation
- 1: Overview
- 1.1: What is async-geotiff?
- 1.2: Architecture
- 2: Get started
- 2.1: Requirements
- 2.2: Quick start
- 2.3: Library usage
- 3: Guides
- 3.1: Styling and band math
- 3.2: Mosaics and STAC
- 3.3: Production operation
- 4: Reference
- 4.1: Example HTTP API
- 4.2: Cargo features
- 4.3: Example server configuration
Choose the path that matches what you need:
- Overview explains the project and its boundaries.
- Get started takes you from prerequisites to a rendered tile.
- Guides cover styling, mosaics, and production operation.
- Reference records exact HTTP parameters, features, and configuration.
1 - Overview
Start here for the project model, architecture, and deliberate boundaries.
1.1 - What is async-geotiff?
async-geotiff is a Rust library for turning Cloud-Optimized GeoTIFFs (COGs)
into styled XYZ map tiles. It reads only the byte ranges needed for a tile,
decodes native TIFF blocks, optionally reprojects them, applies a rendering
style, and encodes the result.
Core capabilities
- Async COG access over HTTPS or any caller-configured
object_storebackend. - Shared, byte-bounded caching of decoded native TIFF blocks.
WebMercatorQuad(EPSG:3857) andWorldCRS84Quad(EPSG:4326) tile grids.- U8, U16, I16, U32, I32, F32, and F64 source pixels.
- Nearest, bilinear, cubic, cubic-spline, Lanczos, and average resampling.
- Rescaling, colormaps, RGB composition, color formulas, and arithmetic band math.
- PNG output, plus feature-gated WebP and JPEG output.
- Multi-asset mosaics backed by MosaicJSON, STAC, or a custom source.
What the library deliberately does not own
No GDAL runtime. TIFF I/O uses async-tiff and object_store. The default
proj feature uses the system libproj library only for coordinate
transformations that do not have a built-in fast path.
No web framework in the library. The Axum HTTP layer and MapLibre,
OpenLayers, and Leaflet viewers live under examples/. Applications can use
CogReader, Tiler, or MosaicTiler without inheriting Axum.
No credentials manager. When opening S3, GCS, MinIO, or another object store, the application configures authentication on the store and passes the ready object to the library.
No telemetry backend. The crate emits tracing spans and exposes cache
statistics. The application decides whether to export them to OpenTelemetry,
Prometheus, logs, or another system.
A tile fully outside the dataset or projection domain returns Ok(None).
The example HTTP server maps that result to 204 No Content.
1.2 - Architecture
The library separates asynchronous range I/O from CPU-heavy decode, warp, render, and encode work. Applications compose the public layers they need.
flowchart LR
Client[HTTP client or Rust caller] --> Style[TileStyle]
Client --> Tiler[Tiler]
Tiler --> Grid[TileMatrixSet]
Tiler --> Reader[CogReader]
Reader --> Store[object_store / HTTP range reads]
Reader <--> Cache[Shared BlockCache]
Reader --> CPU[CpuLimiter + spawn_blocking]
CPU --> Warp[Warp and resampling]
Warp --> Render[Rescale / colormap / composite]
Style --> Render
Render --> Encode[PNG / WebP / JPEG]
Encode --> Result[Option<Bytes>]
Mosaic[MosaicTiler] --> ReaderPool[ReaderPool]
ReaderPool --> Reader
Mosaic --> RenderMain components
| Component | Responsibility |
|---|---|
CogReader | Open a COG, read metadata and overviews, select and stitch native blocks, and sample points or windows. |
BlockCache | Share decoded native blocks across readers under one byte budget; coalesce concurrent cold fetches. |
Tiler | Plan a tile, choose an overview, read the source window, warp when required, and render encoded bytes. |
TileStyle | Parse and validate titiler-style query parameters before rendering. |
MosaicTiler | Find assets, open readers through a pool, warp each asset, reduce overlapping pixels, and render once. |
CpuLimiter | Bound CPU-heavy blocking work across readers and tilers. |
Tile data flow
TileCoordidentifies a tile in a supported TileMatrixSet.Tilercomputes the destination bounds and checks whether they intersect the source dataset.- It selects an overview whose ground resolution is appropriate for the requested tile.
CogReaderloads missing native blocks through range requests and reuses cached blocks where possible.- Same-CRS tiles use an affine fast path. Cross-CRS tiles use an inverse warp;
EPSG:4326 ↔ EPSG:3857 has a closed-form fast path, while other pairs require
the
projfeature. - The render pipeline applies nodata, scaling, optional band math, rescaling, colormaps or RGB composition, and the requested output encoder.
Concurrency model
Tokio drives asynchronous metadata and byte-range I/O. Decode, stitch, warp,
reduction, render, and encode jobs run through spawn_blocking behind a
semaphore. Applications can inject one Arc<BlockCache> across single-COG and
mosaic readers to avoid multiplying decoded-cache budgets. They can also inject
one CpuLimiter across non-mosaic CogReader/Tiler instances. Current
MosaicTiler uses its own internal limiter and cannot join that permit budget,
so mixed traffic has no automatic process-wide CPU cap.
2 - Get started
Follow the shortest path from a fresh checkout to a visible map tile.
2.1 - Requirements
Library and examples
- Rust 1.88 or newer, matching
Cargo.toml. - The default feature set requires system
libproj9.x. - Git is required when working from the repository.
On macOS:
On Debian or Ubuntu:
On other platforms, install libproj with the platform’s supported package
manager or build without the default features. The project does not currently
provide platform-specific Windows installation commands.
If you only need same-CRS tiles or the built-in EPSG:4326 ↔ EPSG:3857 fast path, build without the default features:
Documentation site
The OINK site under website/ requires Go 1.27 or newer and Hugo Extended
0.165.0 or newer. Hugo must report extended in its version string.
The library itself does not depend on Hugo or Go.
2.2 - Quick start
Clone and run
The pinned 800 KiB rio-tiler fixture is a public, range-capable COG intended
for tests and first-run verification. Replace it with your own COG after the
smoke test. The server listens on 127.0.0.1:8080 by default and prints the
available viewer and tile URLs when startup completes.
Open one of the included viewers:
The viewer automatically centers on the opened dataset and is the most reliable visual smoke test. You can also request the world tile directly:
Success produces a PNG file that you can open in any image viewer. A valid tile coordinate outside the source extent returns HTTP 204 instead of a synthetic blank image; if that happens, use one of the included viewers to request an in-bounds tile at the dataset’s calculated center and zoom.
Browse local files
Run the server without a URL to discover data/*.tif and data/*.tiff files:
The viewers then display a dataset switcher.
Optional formats
PNG is always available. Enable WebP and JPEG explicitly:
The /formats endpoint reports only the encoders compiled into the running
binary.
2.3 - Library usage
The repository currently sets publish = false, so another local project uses
a path dependency while developing. Create the application next to the clone,
then replace the relative path if your directories differ:
To avoid the system libproj dependency while retaining the mosaic APIs used
by the example server, set default-features = false, features = ["mosaic"] on
the path dependency. General CRS transformations will then be unavailable.
Render one tile
TileStyle::from_query accepts the same query string used by the example HTTP
server, without the leading ?. Save the example as src/main.rs, then run
cargo run. The pinned URL is a small, range-capable test COG; replace it
after verifying the integration.
Share memory and CPU budgets
For multiple COGs, create one block cache and give every reader a stable, distinct source ID:
Readers with the same cache share its default 512 MiB budget. The source ID is part of the cache key: reuse it only for the same logical COG.
3 - Guides
Task-oriented guides for the capabilities most applications compose.
3.1 - Styling and band math
The same TileStyle model serves the Rust API and the example server’s query
string. Styles are validated before expensive COG reads and rendering work.
Common recipes
Natural-color RGB from three bands:
Single-band color ramp:
Percentile stretch:
Average downsampling and bilinear reprojection:
Stretch behavior
For non-U8 data, the effective value range is selected in this order:
- Explicit
rescale=min,maxvalues. - The requested
stretchmode. stretch=stddev&sigma=2.0when neither is present.
U8 RGB data keeps its 0–255 fast path. Dataset statistics come from embedded
STATISTICS_* tags when present; otherwise the highest overview is sampled
once and the estimate is memoized.
Arithmetic expressions
expression computes one derived output band. Band references are 1-indexed:
This NDVI formula is only correct when band 5 is near-infrared and band 4 is
red in the selected COG. The library does not infer spectral roles from band
numbers; verify the asset metadata and adjust the references before using the
formula. A pre-rendered STAC visual asset is not automatically suitable for
this example.
When used in a URL, percent-encode / and +:
The grammar supports finite decimal numbers, parentheses, binary +, -,
*, /, and unary -. Multiplication and division bind more tightly than
addition and subtraction. Scientific notation is not supported.
expression is mutually exclusive with bidx and color_formula, and it
accepts at most one rescale range. Nodata inputs, division by zero, and other
non-finite results become transparent pixels. Input is bounded to 4096 bytes,
256 tokens, and 128 nesting levels.
Color formulas
The supported rio-color subset applies operations from left to right:
gammasigmoidalsaturation
For example:
Percent-encode spaces when the formula is placed in a URL query string.
3.2 - Mosaics and STAC
The default-enabled mosaic Cargo feature adds MosaicTiler and the
MosaicSource trait; applications that do not need mosaics can disable default
features. Because that also disables proj, use
--no-default-features --features proj when general CRS transformation is
still required. The source maps a tile coordinate to assets; the tiler opens
and warps those assets, reduces overlapping pixels, and renders the composite
once.
MosaicJSON
Run the embedded example or pass a MosaicJSON file:
The parser accepts MosaicJSON 0.0.3. Its quadkey index is defined in
WebMercatorQuad; using a MosaicJSON source with WorldCRS84Quad returns a
query error.
Connect the example server to a file at startup:
Tiles are then available under /mosaic/tiles/....
Pixel selection
| Strategy | Behavior |
|---|---|
First | First valid pixel wins; stops early after the tile is fully covered. |
Highest | Maximum value in the first output band per pixel across every asset. |
Lowest | Minimum value in the first output band per pixel across every asset. |
Mean | Streaming mean of valid samples; constant memory in asset count. |
Median | Median of valid samples; retains every contributing image until completion. |
“First output band” is internal index 0; user-facing bidx values remain
1-indexed.
MosaicConfig defaults to 8 assets processed concurrently per chunk, an
opened-reader capacity of 256 in each MosaicTiler reader pool, and a hard cap
of 64 assets per requested tile. When the cap is exceeded, the tiler logs a
warning and keeps the first assets in source-provided order. Configure all
three limits through the builder:
Keep the asset cap enabled for untrusted or low-zoom indexes to prevent fetch amplification. Choose a deterministic source order when truncation would affect visual correctness.
STAC demo
Enable stac and provide all three startup settings:
The API, collection, and asset key are fixed at process startup. HTTP query parameters cannot turn the demo into an arbitrary STAC or COG proxy.
After startup, open http://127.0.0.1:8080/maplibre. When STAC is configured, the MapLibre viewer selects mosaic mode by default and lets you verify the configured collection without guessing a tile coordinate.
HTTP asset policy
The default policy allows public and private HTTP(S) assets but blocks
loopback, link-local, and cloud-metadata destinations. Use
HttpAccessPolicy::strict() for fully untrusted documents: it requires HTTPS
and also blocks private address ranges. permissive() should be reserved for
operator-controlled asset lists.
The example server uses the default policy and does not expose an environment
override. A service that accepts untrusted mosaic or STAC documents should
construct MosaicTiler itself and pass strict() through the builder as shown
above.
Presigned query strings are redacted from mosaic errors and log messages. The access policy is a URL-resolution guard, not a complete outbound proxy sandbox. Applications still own client timeouts, redirect policy, egress firewalling, document-size limits, and any logging they add around the library.
3.3 - Production operation
Share one cache
The default decoded-block cache budget is 512 MiB. A server with many readers
should inject the same Arc<BlockCache> into every reader and mosaic. Give
each distinct COG a stable source ID so cache entries cannot collide.
This budget covers resident decoded blocks in the cache, not total process
RSS. In-flight compressed bytes, decode and warp buffers, encoded responses,
reader metadata, and mosaic reducer state are additional memory. In particular,
Median retains every contributing image until reduction completes.
The library does not enforce a global request-concurrency limit, so a hard RSS bound cannot be derived from cache capacity alone. Bound concurrent tile requests at the server or gateway, keep per-tile asset fan-out finite, and size the container from load tests that include the largest source windows and output tile sizes you permit.
Use BlockCache::stats() to observe:
hitsandmissesdecodedandfetchedentriesresident_bytes
Useful derived signals include hit ratio, fetched-to-decoded amplification, and resident bytes divided by the configured budget.
Bound CPU work
Decode, stitch, warp, mosaic reduction, render, and encode are CPU-heavy.
They run in spawn_blocking behind CpuLimiter. Non-mosaic CogReader and
Tiler instances accept a caller-owned limiter. MosaicTiler shares one
internal limiter across its assets and final render, but does not accept the
non-mosaic limiter. Defaults follow the host’s available parallelism and clamp
zero to one permit.
Tiler::new reuses the limiter carried by its reader:
The example server’s CPU accounting depends on the path. A command-line default
COG uses separate reader-decode and tiler-render limiters, so those phases can
overlap. Lazily selected local datasets reuse one AppState limiter sized to
the larger configured value. MosaicTiler owns another shared limiter. Treat
the two environment values as component tuning, not as a universal
process-wide CPU cap. For non-mosaic readers and tilers, wire one
library-level CpuLimiter through every component that supports injection.
Current MosaicTiler owns an internal shared limiter and does not expose a
builder hook for injecting the non-mosaic limiter. A strict numeric CPU-job cap
across mixed mosaic and single-COG traffic is therefore unsupported today.
External request concurrency provides useful coarse backpressure, but is not
equivalent to one shared permit budget.
Do not lower tile concurrency preemptively. Measure P95 latency and CPU contention first; an unnecessarily small limit adds queueing to every tile.
Tune access patterns
- Increase cache capacity for multi-dataset servers or wide pan/zoom sessions.
- Prefer ZSTD-compressed COGs over DEFLATE when read latency matters.
- The example server prefetches a one-block ring by default. Set
ASYNC_GEOTIFF_PREFETCH_RING=0when extra object-store GETs are undesirable. - Keep
MosaicConfig::max_assets_per_tilebounded for untrusted indexes.
Export traces and metrics
Tiler::tile and CogReader::read_window emit tracing spans. Connect a
tracing-opentelemetry layer in the application when OTLP traces are needed.
The library intentionally takes no OpenTelemetry dependency.
Record request count, latency, error count, and the Ok(None) rate at the HTTP
or application boundary. Poll cache statistics separately for memory and
fetch behavior.
Protect remote access
Use a strict HttpAccessPolicy when mosaic or STAC documents are not trusted.
Configure credentials on an object_store instance rather than embedding them
in asset identifiers. Avoid logging raw presigned URLs at application
boundaries outside the library.
4 - Reference
Use this section when you need exact supported values and defaults.
4.1 - Example HTTP API
The HTTP API belongs to examples/serve.rs; it is not part of the library’s
dependency surface.
Routes
| Method and path | Purpose |
|---|---|
GET /tiles/{tms}/{z}/{x}/{y}.{ext} | Render a tile from the selected single COG. |
GET /mosaic/tiles/{tms}/{z}/{x}/{y}.{ext} | Render a tile from the configured mosaic or STAC source. |
GET /datasets | List local TIFF files discovered under data/. |
GET /cache/stats | Return decoded-block cache statistics. |
GET /formats | Return output formats compiled into the server. |
GET /bounds | Return bounds used by the example viewers. |
GET, HEAD /data/{name} | Serve a discovered local TIFF with range support. |
Supported TMS names are WebMercatorQuad and WorldCRS84Quad. Supported
extensions are png, feature-gated webp, and feature-gated jpg/jpeg.
Style parameters
| Parameter | Repeat | Default or example | Meaning |
|---|---|---|---|
bidx | yes | bidx=1&bidx=2&bidx=3 | 1-indexed source-band selection. |
expression | no | (b5-b4)/(b5+b4) | Arithmetic expression producing one derived band. |
rescale | yes | 0,3000 | Explicit per-band min,max range; highest stretch priority. |
stretch | no | minmax, percent, stddev | Automatic stretch mode. |
pc | no | 2,98 | Percentile cut used by stretch=percent. |
sigma | no | 2.0 | Standard-deviation multiplier. |
nodata | no | nan, inf, -inf, or float | Override the dataset nodata value. |
colormap_name | no | viridis | Built-in single-band color ramp. |
color_formula | no | gamma RGB 1.5 | Supported rio-color operation sequence. |
resampling | no | nearest | Source read or resize kernel. |
reproject | no | nearest | Warp-time resampling kernel. |
tilesize | no | 256 | One of 64, 128, 256, 512, or 1024. |
format | no | png | Optional format assertion; must agree with the path extension. |
Resampling kernels are nearest, bilinear, cubic, cubic_spline,
lanczos, and average. Average computes a box mean for downsampling and
uses nearest behavior when upsampling.
The mosaic tile route additionally accepts pixel_selection=first,
highest, lowest, mean, or median. The default is first.
Responses
200 OKreturns encoded image bytes.204 No Contentmeans the coordinate is valid but fully outside the source dataset or projection domain.- Invalid style values and malformed coordinates return a client error with a structured library error behind it.
The default output size is 256×256, chosen for broad XYZ-client compatibility.
4.2 - Cargo features
| Feature | Default | Effect |
|---|---|---|
proj | yes | Enables general CRS transformation through system libproj. |
mosaic | yes | Enables MosaicTiler, MosaicSource, MosaicJSON, and async asset fan-out. |
webp | no | Enables lossless WebP encoding through image. |
jpeg | no | Enables JPEG encoding; alpha is flattened because JPEG has no alpha channel. |
stac | no | Adds the STAC client and implies mosaic. |
perf-tracing | no | Emits detailed internal timing events. |
tokio-console | no | Enables Tokio Console integration and implies perf-tracing. |
Examples:
The serve, mosaic_source, and mosaic_json examples require the mosaic
feature. PNG support is always compiled.
4.3 - Example server configuration
These variables configure cargo run --example serve. They are example-server
contracts, not global library configuration.
| Variable | Default | Meaning |
|---|---|---|
ASYNC_GEOTIFF_BIND | 127.0.0.1:8080 | Socket address for the HTTP server. |
ASYNC_GEOTIFF_BLOCK_CACHE_MB | 512 | Shared decoded-block cache capacity in MiB; must be positive. |
ASYNC_GEOTIFF_MAX_DECODE_TASKS | available parallelism | Maximum concurrent decode/stitch CPU jobs; must be positive. |
ASYNC_GEOTIFF_MAX_TILE_TASKS | available parallelism | Maximum concurrent tile warp/render CPU jobs; must be positive. |
ASYNC_GEOTIFF_PREFETCH_RING | 1 | Number of native-block rings prefetched around a read; 0 disables it. |
ASYNC_GEOTIFF_SLOW_TILE_MS | unset | Emit a slow-tile warning above this positive millisecond threshold. |
ASYNC_GEOTIFF_MOSAIC | unset | Path to a MosaicJSON file loaded at startup. |
ASYNC_GEOTIFF_STAC_URL | unset | Fixed STAC API URL; requires the stac feature and the next two variables. |
ASYNC_GEOTIFF_STAC_COLLECTION | unset | Fixed STAC collection ID. |
ASYNC_GEOTIFF_STAC_ASSET_KEY | unset | Fixed STAC COG asset key. |
ASYNC_GEOTIFF_TOKIO_CONSOLE | off | Enable Tokio Console with 1, true, yes, or on when compiled with tokio-console. |
RUST_LOG | async_geotiff=debug,warn | Standard tracing filter for the example server. |
ASYNC_GEOTIFF_MOSAIC and the STAC configuration are mutually exclusive. All
three STAC variables must be supplied together.
The decode-task and tile-task values tune single-COG work, but are not a single
process-wide CPU cap. The command-line default COG uses separate limiters;
lazily selected local datasets share one limiter sized to the larger value;
mosaics own their own limiter. The example server does not expose environment
variables for MosaicConfig fields such as max_assets_per_tile.
Example
Invalid numeric values fail at process startup instead of being silently clamped.