Crate contour_isobands

Source
Expand description

Compute isobands (i.e. contour polygons which enclose all the points of a grid included between two chosen values) by applying marching squares to an array of values.

Use the ContourBuilder to create the contour polygons. Output is a Vec of Band, each Band is characterized by its minimum value, its maximum value, and a MultiPolygon geometry. Each band can be serialised to a GeoJSON Feature (using the Band::to_geojson method that is enabled if compiling this crate with the optional geojson feature flag).

§Example:
let c = ContourBuilder::new(10, 10); // x dim., y dim.
let res = c.contours(&vec![
    0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
    0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
    0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
    0., 0., 0., 1., 1., 1., 0., 0., 0., 0.,
    0., 0., 0., 1., 1., 1., 0., 0., 0., 0.,
    0., 0., 0., 1., 1., 1., 0., 0., 0., 0.,
    0., 0., 0., 1., 1., 1., 0., 0., 0., 0.,
    0., 0., 0., 1., 1., 1., 0., 0., 0., 0.,
    0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
    0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
], &[0.5, 1.]).unwrap(); // values, thresholds

let expected_output = serde_json::json!({
  "type": "Feature",
  "geometry": {
    "type": "MultiPolygon",
    "coordinates": [[[
        [3.0, 2.5], [2.5, 3.0], [2.5, 4.0], [2.5, 5.0],
        [2.5, 6.0], [2.5, 7.0], [3.0, 7.5], [4.0, 7.5],
        [5.0, 7.5], [5.5, 7.0], [5.5, 6.0], [5.5, 5.0],
        [5.5, 4.0], [5.5, 3.0], [5.0, 2.5], [4.0, 2.5],
        [3.0, 2.5]
    ]]]
  },
  "properties": {"min_v": 0.5, "max_v": 1.0}
});

assert_eq!(
    res[0].to_geojson(),
    std::convert::TryFrom::try_from(expected_output).unwrap(),
);

Structs§

Band
An isoband, described by its min and max value and MultiPolygon.
ContourBuilder
Contours generator, using builder pattern, to be used on a rectangular Slice of values to get a Vec of Band (uses isobands function internally).

Functions§

isobands
Generates contours for the given data and thresholds. Returns a Vec of BandRaw (this is the raw result of the marching squares algorithm that contains the paths of the Band as a Vec of Vec of Points - this is the intermediate result that is used to build the MultiPolygons in the ContourBuilder::contours method).

Type Aliases§

BandRaw
The raw result of the isoband computation, where the first element is a vector of paths, the second is the minimum value and the third is the maximum value. See the Band struct for a more convenient representation.