oxigdal-vrt
Pure Rust VRT (Virtual Raster) driver for OxiGDAL - create mosaics, transformations, and virtual datasets without copying data.
Overview
VRT (Virtual Raster) is an XML-based format that references other raster files without copying data. This driver provides a pure Rust implementation enabling efficient multi-file processing and on-the-fly transformations.
Features
- Pure Rust - 100% Pure Rust implementation, no GDAL dependency
- Mosaicking - Combine multiple tiles into a single virtual dataset
- Band Subsetting - Extract specific bands from multi-band rasters
- On-the-fly Transformations - Apply scaling, offset, and pixel functions
- Windowing - Create virtual subsets of large rasters
- XML-based - Human-readable XML format for easy editing
- Zero-copy - References source files without data duplication
- Async I/O - Optional async support for non-blocking operations
- No unwrap policy - All operations return
Result<T, E>
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
Feature Flags
std(default) - Enable standard library supportasync- Enable async I/O with Tokio
Example with async support:
[]
= { = "0.1.0", = ["async"] }
Quick Start
Creating a VRT Mosaic
use VrtBuilder;
Reading from a VRT
use VrtReader;
Usage
Band Subsetting
Extract specific bands from multi-band rasters:
use VrtBuilder;
// Create RGB VRT from 4-band RGBA
let vrt = new
.add_source?
.select_bands? // Red, Green, Blue only
.build_file?;
On-the-fly Scaling
Apply scale and offset transformations:
use ;
let vrt = new
.add_source?
.set_scale_offset? // Convert Kelvin to Celsius
.build_file?;
Pixel Functions
Apply custom pixel functions:
use ;
// Calculate NDVI from red and NIR bands
let vrt = new
.add_source?
.set_pixel_function?
.build_file?;
Virtual Warping
Create reprojected virtual datasets:
use VrtBuilder;
let vrt = new
.add_source?
.set_srs? // Reproject to WGS84
.build_file?;
Complex Mosaics
Build mosaics with overlapping tiles:
use ;
let vrt = new
.add_tile_with_options?
.add_tile_with_options?
.set_blend_mode?
.build_file?;
API Overview
| Module | Description |
|---|---|
builder |
VRT creation with builder pattern |
reader |
Reading VRT datasets |
dataset |
VRT dataset representation |
band |
Virtual band configuration |
source |
Source raster references |
mosaic |
Mosaic creation utilities |
xml |
XML parsing and generation |
error |
Error types |
Key Types
VrtBuilder- Builder for creating VRT datasetsVrtReader- Read and query VRT filesVrtDataset- In-memory VRT representationVrtBand- Virtual band configurationVrtSource- Reference to source rasterPixelFunction- Built-in pixel transformation functionsResampleAlg- Resampling algorithms (Nearest, Bilinear, Cubic, etc.)
Supported Pixel Functions
The VRT driver supports various built-in pixel functions:
| Function | Description | Example Use Case |
|---|---|---|
Ndvi |
Normalized Difference Vegetation Index | Vegetation analysis |
Ndwi |
Normalized Difference Water Index | Water body detection |
Hillshade |
Terrain hillshade | Elevation visualization |
Slope |
Terrain slope | Gradient analysis |
Aspect |
Terrain aspect | Direction analysis |
Sum |
Sum of bands | Band arithmetic |
Diff |
Difference of bands | Change detection |
Mul |
Multiply bands | Masking operations |
Div |
Divide bands | Ratio indices |
Resampling Algorithms
- Nearest - Nearest neighbor (fastest)
- Bilinear - Bilinear interpolation
- Cubic - Cubic convolution
- CubicSpline - Cubic spline
- Lanczos - Lanczos windowed sinc (best quality)
- Average - Average of all contributing pixels
- Mode - Most common value
- Max - Maximum value
- Min - Minimum value
VRT XML Format
VRT files are XML documents with the following structure:
EPSG:4326
-180.0, 0.35, 0.0, 90.0, 0.0, -0.35
Gray
-9999
tile1.tif
1
Performance
VRT datasets provide zero-copy access to source rasters:
| Operation | Performance | Notes |
|---|---|---|
| VRT Creation | <1ms | XML generation only |
| VRT Parsing | 1-10ms | Depends on complexity |
| Pixel Access | Same as source | No overhead for simple VRTs |
| Mosaic Access | Linear with sources | Cached for repeated access |
Optimization Tips
- Use relative paths - Enables portability
- Enable caching - For repeated window reads
- Align windows to tiles - Minimizes source file access
- Use overviews - For multi-resolution access
Error Handling
The VRT driver follows the "no unwrap" policy. All operations return Result<T, VrtError>:
use ;
match open
Pure Rust
This library is 100% Pure Rust with no GDAL or C dependencies. All VRT parsing, generation, and processing is implemented in Rust.
Benefits:
- Cross-platform - Works on any platform Rust supports
- WebAssembly - Compiles to WASM
- Embedded - Suitable for embedded systems
- Memory-safe - Guaranteed memory safety
Examples
See the tests/ directory for comprehensive examples:
create_vrt_mosaic.rs- Creating tile mosaicsvrt_band_subset.rs- Band extractionvrt_pixel_functions.rs- Pixel transformationsvrt_virtual_warp.rs- Reprojection
Run examples:
OxiGDAL Integration
VRT integrates seamlessly with other OxiGDAL drivers:
use DataSource;
use VrtReader;
use GeoTiffWriter;
// Read from VRT, write to GeoTIFF
let vrt = open?;
let data = vrt.read_all?;
let writer = create?;
writer.write_band?;
writer.close?;
Testing
Run the test suite:
# All tests
# With async support
Documentation
- API Documentation: docs.rs/oxigdal-vrt
- GDAL VRT Format: GDAL VRT Specification
- Main Project: github.com/cool-japan/oxigdal
Contributing
Contributions are welcome! Please ensure:
- All tests pass
- No
unwrap()in production code - Comprehensive error handling
- Documentation for public APIs
- Follow Rust naming conventions
Related Projects
OxiGDAL Ecosystem:
- oxigdal-core - Core types and traits
- oxigdal-geotiff - GeoTIFF driver
- oxigdal-cloud - Cloud storage backends
COOLJAPAN Ecosystem:
License
Licensed under the Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0).
Authors
COOLJAPAN OU (Team Kitasan)
Part of the COOLJAPAN ecosystem - Building the future of geospatial computing in Pure Rust.