Expand description
VersaTiles Container: read, convert, and write tile containers.
This crate exposes a small set of building blocks to work with map tile containers:
- a registry that maps file extensions to readers/writers,
- reader traits and adapters to stream tiles,
- writer traits to serialize tiles,
- utilities like caching and streaming combinators.
It is designed for runtime composition: readers are object‑safe and can be wrapped by adapters (e.g. bbox filters, axis flips, compression overrides) and then written out with the appropriate writer inferred from the output path.
§Quick start
use versatiles_container::*;
use versatiles_core::*;
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Open a source container via the registry
let runtime = TilesRuntime::default();
let reader = runtime.reader_from_str("../testdata/berlin.mbtiles").await?;
// Optionally adapt the reader: limit to a tile pyramid, keep compression as-is
let params = TilesConverterParameters {
tile_pyramid: Some(TilePyramid::new_full_up_to(8)),
..Default::default()
};
let reader = Arc::new(Box::new(TilesConvertReader::new_from_reader(reader, params).await?) as Box<dyn TileSource>);
// Write to a target path; format is inferred from the extension
let output = std::env::temp_dir().join("example.versatiles");
runtime.write_to_path(reader, &output).await?;
Ok(())
}§Four traits, two axes
Reading and writing are each split in two, which is easier to hold onto as a grid than as four separate names:
| Open a container | Move the tiles | |
|---|---|---|
| Read | TilesReader — a path or a DataReader becomes a source | TileSource — the tiles, object‑safe, wrappable by adapters |
| Write | TilesWriter — serialise a whole source in one pass | TileSink — take tiles one at a time, shared across threads |
The read row is a pipeline: a TilesReader opens something and hands
back a TileSource, and everything downstream — adapters, the server, the
VPL pipeline — only ever sees the source.
The write row is a choice, and it is the one worth understanding. A
TilesWriter is handed the entire source and writes the file its own way,
which is what versatiles convert uses. A TileSink is the opposite: it
is wrapped in an Arc, shared by several threads, and fed tiles in whatever
order they finish — which is what versatiles mosaic needs, because it
composites tiles as they are produced.
§Which formats do what
| Format | Read | Write whole | Write incrementally |
|---|---|---|---|
.versatiles | ✓ | ✓ | ✓ |
.mbtiles | ✓ | ✓ | ✓ |
.tar | ✓ | ✓ | ✓ |
| directory | ✓ | ✓ | ✓ |
.pmtiles | ✓ | ✓ | — |
PMTiles is the one gap, and it follows from the format rather than from an
omission: a clustered archive stores its tiles ordered by Hilbert index, so
the order cannot be known until every tile is in. PMTilesWriter gets there
by reordering through a temporary file, which a sink — receiving tiles as
they arrive, with no idea what is still coming — cannot do. Writing PMTiles
therefore goes through the registry, not through open_tile_sink.
§Features
cli: enables human‑readable probing of containers and tiles.test: helpers for integration tests in downstream crates.
§See also
ContainerRegistry: register custom reader/writer implementations at runtimeTileSource,TilesWriter: object‑safe traits for IOopen_tile_sink: pick aTileSinkfrom a destination pathTilesConvertReader,convert_tiles_container: convenience conversion helpers
Re-exports§
Modules§
- cache
- Caching subsystem for
VersaTiles. - probe
- Container analysis: what a probe works out, as data rather than as output.
- progress
- Progress reporting.
- runtime
- Re‑exports progress tracking and event bus types. Runtime configuration and services for tile processing operations
Structs§
- Container
Registry - Re‑exports reader/writer traits, converters, and auxiliary types. Registry mapping file extensions to async tile container readers and writers.
- Data
Source - Re‑exports reader/writer traits, converters, and auxiliary types.
Represents a parsed input specification which may include a driver prefix (like
mbtiles:). It can resolve standard input (-) into an in-memory Blob and derives the effective extension that determines which reader to pick. - Directory
Reader - Re‑exports the container registry and common open/write helpers. A reader for tiles stored in a directory structure.
- Directory
Tile Sink - Re‑exports the container registry and common open/write helpers. A tile sink that writes pre-compressed blobs to a directory tree.
- Directory
Writer - Re‑exports the container registry and common open/write helpers.
Writes a directory-based tile pyramid along with a compressed
TileJSON(tiles.json[.<br|gz>]). - MBTiles
Reader - Re‑exports the container registry and common open/write helpers.
Reader for
MBTiles(SQLite) containers. - MBTiles
Tile Sink - Re‑exports the container registry and common open/write helpers. A tile sink that writes pre-compressed blobs into an MBTiles SQLite database.
- MBTiles
Writer - Re‑exports the container registry and common open/write helpers.
Writer for
MBTiles(SQLite) containers. - PMTiles
Reader - Re‑exports the container registry and common open/write helpers.
Reader for
PMTilesv3 containers. - PMTiles
Writer - Re‑exports the container registry and common open/write helpers.
Writer for
PMTilesv3 archives. - Remapped
Tile Source - Re‑exports reader/writer traits, converters, and auxiliary types. Presents a source under relabelled tile coordinates.
- TarTile
Sink - Re‑exports the container registry and common open/write helpers.
A tile sink that writes pre-compressed blobs into a
.tararchive. - TarTiles
Reader - Re‑exports the container registry and common open/write helpers. Reader for tiles stored inside a tar archive.
- TarTiles
Writer - Re‑exports the container registry and common open/write helpers.
Writes a source into an uncompressed
.tararchive of tile files. - Tile
- Re‑exports reader/writer traits, converters, and auxiliary types. A lazy tile container that can hold either an encoded blob or decoded content.
- Tile
Source Metadata - Re‑exports reader/writer traits, converters, and auxiliary types. Metadata describing the output characteristics of a tile source.
- Tiles
Convert Reader - Re‑exports reader/writer traits, converters, and auxiliary types. Reader adapter that applies coordinate transforms, bbox filtering, and optional compression changes on-the-fly.
- Tiles
Converter Parameters - Re‑exports reader/writer traits, converters, and auxiliary types. Parameters that control how tiles are transformed during reading/conversion.
- Traversal
- Represents a traversal strategy for iterating over tile bounding boxes.
- Traversal
Size - Represents allowed sizes of a block of tiles
The size is represented as log2(size).
For example,
TraversalSize{ max: 6 } represents block of sizes up to 64 tiles. - Versa
Tiles Reader - Re‑exports the container registry and common open/write helpers.
Reader for
.versatilescontainers. - Versa
Tiles Sink - Re‑exports the container registry and common open/write helpers.
A tile sink that buffers tiles to temporary files and assembles a
.versatilescontainer onfinish. - Versa
Tiles Writer - Re‑exports the container registry and common open/write helpers.
Writer for
.versatilescontainers.
Enums§
- Data
Location - Re‑exports reader/writer traits, converters, and auxiliary types. A flexible location of data used across I/O code.
- Source
Type - Re‑exports reader/writer traits, converters, and auxiliary types. Distinguishes between different tile source types.
- Tile
Content - Re‑exports reader/writer traits, converters, and auxiliary types. Decoded tile content (raster or vector).
- Traversal
Order - Strategies for ordering tiles when traversing a tile pyramid.
- Traversal
Translation - How a source traversing one way can feed a writer requiring another.
- Traversal
Translation Step - Represents a single operation during traversal translation from one traversal configuration to another.
Constants§
- DEFAULT_
TILE_ COUNT_ LIMIT - Re‑exports reader/writer traits, converters, and auxiliary types.
Converts tiles from the given reader and writes them to
pathusing the provided runtime. - TILE_
COUNT_ LIMIT_ ENV - Re‑exports reader/writer traits, converters, and auxiliary types.
Environment variable overriding
DEFAULT_TILE_COUNT_LIMIT;0disables the check.
Traits§
- Tile
Sink - Re‑exports reader/writer traits, converters, and auxiliary types. Push-model interface for writing individual tiles to a container in any order.
- Tile
Source - Re‑exports reader/writer traits, converters, and auxiliary types. Unified object-safe interface for reading or processing tiles.
- Tile
Source Traverse Ext - Extension trait providing traversal with higher-rank trait bounds (HRTBs).
- Tile
Stream Error Ext - Re‑exports reader/writer traits, converters, and auxiliary types. Routes per-tile failures to the runtime instead of unwrapping them.
- Tiles
Reader - Re‑exports reader/writer traits, converters, and auxiliary types. Interface for opening tile containers from paths or data readers.
- Tiles
Writer - Re‑exports reader/writer traits, converters, and auxiliary types. Object‑safe interface for writing tiles from a reader into a container format.
Functions§
- convert_
tiles_ container - Re‑exports reader/writer traits, converters, and auxiliary types.
Converts a source into a container at
path, applyingcp. - convert_
tiles_ container_ to_ str - Re‑exports reader/writer traits, converters, and auxiliary types. Converts tiles from the given reader and writes them to a string destination.
- deduplicating_
tile_ sink - Re‑exports reader/writer traits, converters, and auxiliary types. Wrap a tile sink so that each coordinate is written at most once.
- open_
tile_ sink - Re‑exports reader/writer traits, converters, and auxiliary types. Open a tile sink based on the destination’s file extension.
- resolve_
tile_ count_ limit - Re‑exports reader/writer traits, converters, and auxiliary types.
The tile-count limit in force, from
TILE_COUNT_LIMIT_ENVorDEFAULT_TILE_COUNT_LIMIT.0maps tou64::MAX, i.e. no limit. - translate_
traversals - Translates traversal steps from a reading traversal configuration to a writing traversal configuration.
- translation_
between - Decides how (or whether)
readcan feedwrite, without doing the work.
Type Aliases§
- Shared
Tile Source - Re‑exports reader/writer traits, converters, and auxiliary types. Shared ownership of a tile source for concurrent access.