Skip to main content

Module buffer

Module buffer 

Source
Expand description

Buffer types for raster and vector data

This module provides efficient buffer types for storing and manipulating geospatial data. When the arrow feature is enabled, buffers are backed by Apache Arrow arrays for zero-copy interoperability.

§Overview

The RasterBuffer type is the core buffer abstraction in OxiGeo, providing type-safe storage for raster pixel data with automatic memory management.

§Examples

§Creating buffers

use oxigeo_core::buffer::RasterBuffer;
use oxigeo_core::types::{RasterDataType, NoDataValue};

// Create a zero-filled buffer
let buffer = RasterBuffer::zeros(1000, 1000, RasterDataType::Float32);

// Create a buffer with nodata value
let nodata = NoDataValue::Float(-9999.0);
let buffer = RasterBuffer::nodata_filled(1000, 1000, RasterDataType::Float32, nodata);

§Working with pixel data

use oxigeo_core::buffer::RasterBuffer;
use oxigeo_core::types::RasterDataType;

let mut buffer = RasterBuffer::zeros(100, 100, RasterDataType::UInt8);

// Set pixel value
buffer.set_pixel(50, 50, 255.0)?;

// Get pixel value
let value = buffer.get_pixel(50, 50)?;
assert_eq!(value, 255.0);

§Reading pixels into a buffer you own (no extra allocation)

RasterBuffer::copy_to_slice converts and writes straight into a caller-supplied slice, so nothing is allocated or copied twice — the equivalent of GDAL’s RasterBand::read_into_slice:

use oxigeo_core::buffer::RasterBuffer;
use oxigeo_core::types::RasterDataType;

let mut buffer = RasterBuffer::zeros(4, 2, RasterDataType::UInt16);
buffer.set_pixel(0, 0, 7.0)?;

// The only allocation is the destination, and it belongs to the caller.
let mut pixels = vec![0.0f64; 8];
buffer.copy_to_slice(&mut pixels)?;
assert_eq!(pixels[0], 7.0);

With ndarray the destination is simply the array’s backing slice:

let mut array = ndarray::Array2::<f64>::zeros((height, width));
if let Some(dst) = array.as_slice_mut() {
    buffer.copy_to_slice(dst)?;
}

§Computing statistics

use oxigeo_core::buffer::RasterBuffer;
use oxigeo_core::types::RasterDataType;

let buffer = RasterBuffer::zeros(1000, 1000, RasterDataType::Float32);
let stats = buffer.compute_statistics()?;

println!("Min: {}, Max: {}", stats.min, stats.max);
println!("Mean: {}, StdDev: {}", stats.mean, stats.std_dev);
println!("Valid pixels: {}", stats.valid_count);

§See Also

Re-exports§

pub use element::FloatToIntRounding;
pub use element::RasterElement;
pub use element::RasterElementKind;
pub use element::convert_raw_bytes;
pub use element::convert_raw_into;
pub use element::convert_raw_into_with;
pub use element::elements_as_bytes;
pub use mask::Mask;
pub use crate::simd_buffer::ArenaTile;
pub use crate::simd_buffer::TileIteratorArena;

Modules§

arrow_convert
Arrow RecordBatchRasterBuffer conversions
element
Typed raster elements and allocation-free bulk conversions.
mask
Nodata and validity bitmask for raster regions.

Structs§

BandIterator
Lazy iterator over bands of a MultiBandBuffer.
BandRef
A borrowed reference to a single band within a MultiBandBuffer.
BufferStatistics
Statistics computed from a buffer
MultiBandBuffer
A multi-band raster buffer holding multiple single-band buffers.
RasterBuffer
A typed buffer for raster data
RasterWindow
A sub-region window into a raster dataset. Defines a rectangular area for reading/writing a portion of raster data.