Expand description
§wbraster
A pure-Rust library for reading and writing common raster GIS formats.
§Supported Formats
| Format | Read | Write | Extension(s) |
|---|---|---|---|
| Esri ASCII Grid | ✓ | ✓ | .asc, .grd |
| Esri Binary Grid | ✓ | ✓ | .adf (workspace) |
| GRASS ASCII Raster | ✓ | ✓ | .asc, .txt |
| Surfer GRD | ✓ | ✓ | .grd |
| PCRaster | ✓ | ✓ | .map |
| SAGA Binary Grid | ✓ | ✓ | .sdat / .sgrd |
| Idrisi/TerrSet Raster | ✓ | ✓ | .rst / .rdc |
| ER Mapper | ✓ | ✓ | .ers / .ers data |
| ENVI HDR Labelled Raster | ✓ | ✓ | .hdr + .img/.dat/.bin/.raw/.bil/.bsq/.bip |
| GeoTIFF / BigTIFF / COG | ✓ | ✓ | .tif / .tiff |
| GeoPackage Raster (Phase 4) | ✓ | ✓ | .gpkg |
| JPEG 2000 / GeoJP2 | ✓ | ✓ | .jp2 |
| Zarr v2/v3 (MVP) | ✓ | ✓ | .zarr |
§Quick Start
use wbraster::{Raster, RasterFormat, RasterConfig};
// Create a new raster in memory
let mut r = Raster::new(RasterConfig {
cols: 100,
rows: 100,
bands: 1,
x_min: 0.0,
y_min: 0.0,
cell_size: 1.0,
nodata: -9999.0,
..Default::default()
});
// Set some values
r.set(0, 50isize, 50isize, 42.0).unwrap();
assert_eq!(r.get(0, 50isize, 50isize), 42.0);
// Write to disk
r.write("output.asc", RasterFormat::EsriAscii).unwrap();
// Read back
let r2 = Raster::read("output.asc").unwrap();
assert_eq!(r2.get(0, 50isize, 50isize), 42.0);§COG-first write API
use wbraster::{CogWriteOptions, GeoTiffCompression, Raster};
let raster = Raster::read("input.tif").unwrap();
// Fast convenience defaults (deflate, tile=512, bigtiff=false)
raster.write_cog("output_default.cog.tif").unwrap();
// Convenience defaults with custom tile size
raster
.write_cog_with_tile_size("output_tile256.cog.tif", 256)
.unwrap();
// COG-focused typed options (compression + bigtiff + tile size)
let opts = CogWriteOptions {
compression: Some(GeoTiffCompression::Deflate),
bigtiff: Some(false),
tile_size: Some(256),
};
raster
.write_cog_with_options("output_opts.cog.tif", &opts)
.unwrap();§JPEG2000 default lossy quality
use wbraster::{
Jpeg2000Compression,
Jpeg2000WriteOptions,
JPEG2000_DEFAULT_LOSSY_QUALITY_DB,
Raster,
RasterFormat,
};
let raster = Raster::read("input.tif").unwrap();
let opts = Jpeg2000WriteOptions {
compression: Some(Jpeg2000Compression::Lossy {
quality_db: JPEG2000_DEFAULT_LOSSY_QUALITY_DB,
}),
decomp_levels: Some(5),
color_space: None,
};
raster.write_jpeg2000_with_options("output.jp2", &opts).unwrap();
raster.write("output_default.jp2", RasterFormat::Jpeg2000).unwrap();Re-exports§
pub use error::RasterError;pub use error::Result;pub use raster::Raster;pub use raster::RasterConfig;pub use raster::DataType;pub use raster::NoData;pub use raster::Statistics;pub use raster::StatisticsComputationMode;pub use raster::Extent;pub use raster::ResampleMethod;pub use raster::NodataPolicy;pub use raster::AntimeridianPolicy;pub use raster::GridSizePolicy;pub use raster::DestinationFootprint;pub use raster::ReprojectOptions;pub use formats::RasterFormat;pub use formats::geotiff::CogWriteOptions;pub use formats::geotiff::GeoTiffCompression;pub use formats::geotiff::GeoTiffLayout;pub use formats::geotiff::GeoTiffWriteOptions;pub use formats::jpeg2000::Jpeg2000Compression;pub use formats::jpeg2000::Jpeg2000WriteOptions;pub use formats::jpeg2000::JPEG2000_DEFAULT_LOSSY_QUALITY_DB;pub use color_math::hsi2value;pub use color_math::hsi_to_rgb_norm;pub use color_math::rgb_to_hsi_norm;pub use color_math::value2hsi;pub use color_math::value2i;pub use crs_info::CrsInfo;
Modules§
- color_
math - HSI colour-space conversion helpers for packed-RGB and normalised-RGB raster values.
- crs_
info - Lightweight spatial reference representation.
- error
- Error types for wbraster.
- formats
- Format registry and auto-detection.
- io_
utils - Low-level I/O helpers — byte-order conversion, buffered I/O.
- memory_
store - In-process raster memory store for passing rasters between tools without disk I/O.
- raster
- Core
Rastertype — the central data structure for all raster GIS data.