Skip to main content

Crate wbraster

Crate wbraster 

Source
Expand description

§wbraster

A pure-Rust library for reading and writing common raster GIS formats.

§Supported Formats

FormatReadWriteExtension(s)
DTED✓✓.dt0, .dt1, .dt2
Esri ASCII Grid✓✓.asc, .grd
Esri Binary Grid✓✓.adf (workspace)
Esri Float Grid✓✓.flt + .hdr
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
ERDAS IMAGINE HFA✓—.img
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
PNG + World File✓✓.png + .pgw/.pngw/.wld
JPEG + World File✓✓.jpg/.jpeg + .jgw/.jpgw/.jpegw/.wld
XYZ ASCII Grid✓✓.xyz
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 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;
pub use error::RasterError;
pub use error::Result;
pub use formats::geotiff::CogWriteOptions;
pub use formats::geotiff::GeoTiffCompression;
pub use formats::geotiff::GeoTiffLayout;
pub use formats::geotiff::GeoTiffWriteOptions;
pub use formats::jpeg2000::Jpeg2000ColorSpace;
pub use formats::jpeg2000::Jpeg2000Compression;
pub use formats::jpeg2000::Jpeg2000WriteOptions;
pub use formats::jpeg2000::JPEG2000_DEFAULT_LOSSY_QUALITY_DB;
pub use formats::RasterFormat;
pub use packages::dimap_bundle::DimapBundle;
pub use packages::iceye_bundle::IceyeBundle;
pub use packages::landsat_bundle::LandsatBundle;
pub use packages::landsat_bundle::LandsatMission;
pub use packages::landsat_bundle::LandsatProcessingLevel;
pub use packages::landsat_bundle::LandsatReflectanceCoefficients;
pub use packages::landsat_bundle::LandsatThermalConstants;
pub use packages::maxar_worldview_bundle::MaxarWorldViewBundle;
pub use packages::optical::DimapBundleProvider;
pub use packages::optical::LandsatBundleProvider;
pub use packages::optical::ResolvedOpticalBundle;
pub use packages::optical::SensorBundleProvider;
pub use packages::optical::SensorBundleRegistry;
pub use packages::optical::Sentinel2SafeBundleProvider;
pub use packages::planetscope_bundle::PlanetScopeBundle;
pub use packages::radarsat2_bundle::Radarsat2Bundle;
pub use packages::rcm_bundle::RcmBundle;
pub use packages::safe_bundle::detect_safe_mission;
pub use packages::safe_bundle::open_safe_bundle;
pub use packages::safe_bundle::SafeBundle;
pub use packages::safe_bundle::SafeMission;
pub use packages::sensor_bundle::detect_sensor_bundle_family;
pub use packages::sensor_bundle::detect_sensor_bundle_family_path;
pub use packages::sensor_bundle::open_sensor_bundle;
pub use packages::sensor_bundle::open_sensor_bundle_path;
pub use packages::sensor_bundle::OpenedSensorBundle;
pub use packages::sensor_bundle::SensorBundle;
pub use packages::sensor_bundle::SensorBundleFamily;
pub use packages::sentinel1_safe::Sentinel1Burst;
pub use packages::sentinel1_safe::Sentinel1BurstList;
pub use packages::sentinel1_safe::Sentinel1CalibrationLut;
pub use packages::sentinel1_safe::Sentinel1CalibrationTarget;
pub use packages::sentinel1_safe::Sentinel1CalibrationVector;
pub use packages::sentinel1_safe::Sentinel1GeolocationGrid;
pub use packages::sentinel1_safe::Sentinel1GeolocationGridPoint;
pub use packages::sentinel1_safe::Sentinel1NoiseLut;
pub use packages::sentinel1_safe::Sentinel1NoiseVector;
pub use packages::sentinel1_safe::Sentinel1OrbitVector;
pub use packages::sentinel1_safe::Sentinel1SafePackage;
pub use packages::sentinel2_safe::Sentinel2ProductLevel;
pub use packages::sentinel2_safe::Sentinel2SafePackage;
pub use raster::AntimeridianPolicy;
pub use raster::BandView;
pub use raster::DataType;
pub use raster::DestinationFootprint;
pub use raster::Extent;
pub use raster::GridSizePolicy;
pub use raster::NoData;
pub use raster::NodataPolicy;
pub use raster::Raster;
pub use raster::RasterConfig;
pub use raster::ReprojectOptions;
pub use raster::ResampleMethod;
pub use raster::Statistics;
pub use raster::StatisticsComputationMode;

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.
packages
Package-level readers that resolve multi-file geospatial products into raster assets.
raster
Core Raster type — the central data structure for all raster GIS data.