Skip to main content

RasterBuffer

Struct RasterBuffer 

Source
pub struct RasterBuffer { /* private fields */ }
Expand description

A typed buffer for raster data

Implementations§

Source§

impl RasterBuffer

Source

pub fn new( data: Vec<u8>, width: u64, height: u64, data_type: RasterDataType, nodata: NoDataValue, ) -> Result<Self>

Creates a new raster buffer

§Errors

Returns an error if the data size doesn’t match the dimensions and type

Source

pub fn zeros(width: u64, height: u64, data_type: RasterDataType) -> Self

Creates a zero-filled buffer

Source

pub fn nodata_filled( width: u64, height: u64, data_type: RasterDataType, nodata: NoDataValue, ) -> Self

Creates a buffer filled with the nodata value

Source

pub fn fill_value(&mut self, value: f64)

Fills the buffer with a constant value

Source

pub const fn width(&self) -> u64

Returns the width in pixels

Source

pub const fn height(&self) -> u64

Returns the height in pixels

Source

pub const fn data_type(&self) -> RasterDataType

Returns the data type

Source

pub const fn nodata(&self) -> NoDataValue

Returns the nodata value

Source

pub const fn pixel_count(&self) -> u64

Returns the total number of pixels

Source

pub fn as_bytes(&self) -> &[u8]

Returns the raw bytes

Source

pub fn as_bytes_mut(&mut self) -> &mut [u8]

Returns mutable raw bytes

Source

pub fn into_bytes(self) -> Vec<u8>

Consumes the buffer and returns the raw bytes

Source

pub fn from_typed_vec<T: Copy + 'static>( width: usize, height: usize, data: Vec<T>, data_type: RasterDataType, ) -> Result<Self>

Creates a buffer from typed vector data

§Arguments
  • width - Width in pixels
  • height - Height in pixels
  • data - Typed data (e.g., Vec<f32>, Vec<u8>)
  • data_type - The raster data type
§Errors

Returns an error if the data size doesn’t match dimensions and type

Source

pub fn as_slice<T: Copy + 'static>(&self) -> Result<&[T]>

Returns the buffer data as a typed slice

§Type Parameters
  • T - The target type (must match the buffer’s data type size)
§Errors

Returns an error if the type size doesn’t match the data type

Source

pub fn as_slice_mut<T: Copy + 'static>(&mut self) -> Result<&mut [T]>

Returns the buffer data as a mutable typed slice

§Type Parameters
  • T - The target type (must match the buffer’s data type size)
§Errors

Returns an error if the type size doesn’t match the data type

Source

pub fn get_pixel(&self, x: u64, y: u64) -> Result<f64>

Gets a pixel value as f64

§Errors

Returns an error if coordinates are out of bounds

Source

pub fn set_pixel(&mut self, x: u64, y: u64, value: f64) -> Result<()>

Sets a pixel value

§Errors

Returns an error if coordinates are out of bounds

Source

pub fn get_u8(&self, x: u64, y: u64) -> Result<u8>

Gets a pixel value as u8.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not UInt8.

Source

pub fn get_i8(&self, x: u64, y: u64) -> Result<i8>

Gets a pixel value as i8.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not Int8.

Source

pub fn get_u16(&self, x: u64, y: u64) -> Result<u16>

Gets a pixel value as u16.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not UInt16.

Source

pub fn get_i16(&self, x: u64, y: u64) -> Result<i16>

Gets a pixel value as i16.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not Int16.

Source

pub fn get_u32(&self, x: u64, y: u64) -> Result<u32>

Gets a pixel value as u32.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not UInt32.

Source

pub fn get_i32(&self, x: u64, y: u64) -> Result<i32>

Gets a pixel value as i32.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not Int32.

Source

pub fn get_u64(&self, x: u64, y: u64) -> Result<u64>

Gets a pixel value as u64.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not UInt64.

Source

pub fn get_i64(&self, x: u64, y: u64) -> Result<i64>

Gets a pixel value as i64.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not Int64.

Source

pub fn get_f32(&self, x: u64, y: u64) -> Result<f32>

Gets a pixel value as f32.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not Float32.

Source

pub fn get_f64(&self, x: u64, y: u64) -> Result<f64>

Gets a pixel value as f64.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not Float64.

Source

pub fn set_u8(&mut self, x: u64, y: u64, value: u8) -> Result<()>

Sets a pixel value from u8.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not UInt8.

Source

pub fn set_f32(&mut self, x: u64, y: u64, value: f32) -> Result<()>

Sets a pixel value from f32.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not Float32.

Source

pub fn set_f64(&mut self, x: u64, y: u64, value: f64) -> Result<()>

Sets a pixel value from f64.

§Errors

Returns an error if coordinates are out of bounds or the buffer type is not Float64.

Source

pub fn row_slice<T: Copy + 'static>(&self, y: u64) -> Result<&[T]>

Returns a row of pixel data as a typed slice.

§Errors

Returns an error if y is out of bounds or type size mismatches.

Source

pub fn window(&self, x: u64, y: u64, width: u64, height: u64) -> Result<Self>

Returns a rectangular window of pixel data as a new RasterBuffer.

§Errors

Returns an error if the window extends outside buffer bounds.

Source

pub fn is_nodata(&self, value: f64) -> bool

Returns true if the given value equals the nodata value

Source

pub fn convert_to(&self, target_type: RasterDataType) -> Result<Self>

Converts the buffer to a different data type

§Errors

Returns an error if conversion fails

Source

pub fn compute_statistics(&self) -> Result<BufferStatistics>

Computes basic statistics

Source

pub fn compute_statistics_with_histogram( &self, bin_count: usize, ) -> Result<BufferStatistics>

Computes statistics and an optional histogram in one pass.

The returned BufferStatistics contains a histogram of bin_count bins with uniform spacing covering the range [min, max]. Each bin holds the count of valid pixels whose value falls within that bin’s interval.

§Arguments
  • bin_count — Number of histogram bins. Must be ≥ 1.
§Errors

Returns crate::error::OxiGdalError::InvalidParameter if bin_count is 0. Returns errors from pixel access on corrupt buffers.

§Notes
  • NaN and infinite values are excluded (same as RasterBuffer::compute_statistics).
  • When all valid values are identical (min == max), all counts go into bin 0.
  • When no valid pixels exist, histogram is Some(vec![0; bin_count]).

Trait Implementations§

Source§

impl Clone for RasterBuffer

Source§

fn clone(&self) -> RasterBuffer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RasterBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.