pub struct RasterCalculator;Expand description
Raster calculator for map algebra with expression parsing
Implementations§
Source§impl RasterCalculator
impl RasterCalculator
Sourcepub fn evaluate_bytecode(
expr_str: &str,
bands: &[RasterBuffer],
) -> Result<RasterBuffer>
pub fn evaluate_bytecode( expr_str: &str, bands: &[RasterBuffer], ) -> Result<RasterBuffer>
Evaluate a band-math expression using the bytecode VM.
Parsing and compilation happen once; the resulting CompiledProgram is
then executed for every pixel with a pair of pre-allocated scratch buffers
(cache and stack) so no heap allocations occur inside the pixel loop.
This method is functionally equivalent to RasterCalculator::evaluate
but can be 2–5× faster on large rasters because it avoids AST tree
traversal per pixel.
§Arguments
expr_str– The expression string (e.g."(B1 - B2) / (B1 + B2)").bands– InputRasterBufferslices; B1 = bands[0], B2 = bands[1], …
§Errors
Returns an AlgorithmError if:
bandsis empty (AlgorithmError::EmptyInput),- band dimensions differ (
AlgorithmError::InvalidDimensions), - the expression cannot be parsed or compiled.
Source§impl RasterCalculator
impl RasterCalculator
Sourcepub fn evaluate(
expression: &str,
bands: &[RasterBuffer],
) -> Result<RasterBuffer>
pub fn evaluate( expression: &str, bands: &[RasterBuffer], ) -> Result<RasterBuffer>
Evaluates a raster expression on one or more bands
§Arguments
expression- The expression to evaluate (e.g., “(B1 - B2) / (B1 + B2)”)bands- Input bands (B1, B2, etc.)
§Examples
NDVI: "(B1 - B2) / (B1 + B2)"
Conditional: "if B1 > 100 then B1 * 2 else B1"
Math: "sqrt(B1 ^ 2 + B2 ^ 2)"
§Errors
Returns an error if the expression is invalid or evaluation fails
Sourcepub fn evaluate_parallel(
expression: &str,
bands: &[RasterBuffer],
) -> Result<RasterBuffer>
pub fn evaluate_parallel( expression: &str, bands: &[RasterBuffer], ) -> Result<RasterBuffer>
Evaluates a raster expression in parallel using rayon
This method processes rows in parallel for improved performance on multi-core systems. Falls back to sequential evaluation if the parallel feature is not enabled.
§Arguments
expression- The expression to evaluate (e.g., “(B1 - B2) / (B1 + B2)”)bands- Input bands (B1, B2, etc.)
§Examples
NDVI: "(B1 - B2) / (B1 + B2)"
Conditional: "if B1 > 100 then B1 * 2 else B1"
Math: "sqrt(B1 ^ 2 + B2 ^ 2)"
§Errors
Returns an error if the expression is invalid or evaluation fails
Sourcepub fn apply_binary(
a: &RasterBuffer,
b: &RasterBuffer,
op: RasterExpression,
) -> Result<RasterBuffer>
pub fn apply_binary( a: &RasterBuffer, b: &RasterBuffer, op: RasterExpression, ) -> Result<RasterBuffer>
Applies a binary operation to two rasters (legacy API)
Sourcepub fn apply_unary<F>(src: &RasterBuffer, func: F) -> Result<RasterBuffer>
pub fn apply_unary<F>(src: &RasterBuffer, func: F) -> Result<RasterBuffer>
Applies a unary function to a raster (legacy API)
Auto Trait Implementations§
impl Freeze for RasterCalculator
impl RefUnwindSafe for RasterCalculator
impl Send for RasterCalculator
impl Sync for RasterCalculator
impl Unpin for RasterCalculator
impl UnsafeUnpin for RasterCalculator
impl UnwindSafe for RasterCalculator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more