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 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)