Skip to main content

Crate rusterize

Crate rusterize 

Source
Expand description

§rusterize

rusterize is an extremely fast, trait-based, rasterization engine for geo::Geometry.

Geometries can be rasterized as a DenseArray (a materialized raster) or a SparseArray, containing the band/row/col value triplets of all lazily burned pixels. A SparseArray can later be materialized into a raster, therefore avoiding large memory allocations until it’s actually needed.

§Installation

[dependencies]
rusterize-rs = "0.1"

To include polars support:

[dependencies]
rusterize-rs = { version = "0.1", features = ["polars"] }

§Example

Build a RasterInfo describing the output grid, wrap it in a RasterizeContext, then call rasterize on any slice of geometries. The target type (DenseArray or SparseArray) selects the output encoding and data type. The PixelFunction dictates what happens to overlapping pixels. FieldSource represents the values to be burned.

use rusterize::prelude::*;
use geo::{Geometry, Point};

fn example() -> RusterizeResult<()> {
    let raster_info = RasterInfoBuilder::new()
        .extent(0.0, 0.0, 10.0, 10.0)
        .resolution(1.0, 1.0)
        .build()?;

    let geoms = vec![Geometry::Point(Point::new(5.0, 5.0)), Geometry::Point(Point::new(3.0, 3.0))];

    let ctx = RasterizeContext {
        raster_info,
        field: FieldSource::Scalar(1.0_f64),
        by: None,
        pixel_fn: PixelFunction::Last,
        background: f64::NAN,
        all_touched: false,
    };

    let raster = geoms.rasterize::<DenseArray<f64>>(ctx)?;
    Ok(())
}

§Feature flags

  • polars: Adds FieldSource::Column for burning a polars column.

Structs§

DenseArray
A materialized 3-dimensional array containing the burned geometries and spatial information.
RasterInfo
Contains the spatial information associated with the burned geo::Geometry.
RasterInfoBuilder
Builder for a RasterInfo instance. If extent is not provided, it can be inferred from the geo::Geometry when building it. In this case, a half-pixel buffer is applied to avoid missing points on the border. The logics dictating the final spatial properties of the rasterized geometries follow those of GDAL.
RasterizeContext
Spatial + value context handed to the rasterization engine.
SparseArray
A sparse array in COOordinate format storing the band/row/col value triplets. of all burned geo::Geometry.

Enums§

FieldSource
Source of values to burn onto a DenseArray or SparseArray.
PixelFunction
Supported functions to apply to overlapping pixels.
RusterizeError

Traits§

ArrayBuilder
DenseArray or SparseArray creation trait.
NaNAware
Trait to handle NaN check for dtypes that don’t have it.
PolarsHandler
Handle polars dtypes and conversions.
RasterDtype
Bound rasterization to a dtype.
Rasterize
Rasterization trait. Attaches to anything that can be viewed as a geo::Geometry slice and produces a DenseArray or a SparseArray.

Type Aliases§

RusterizeResult