Expand description
Computes isorings and contour polygons by applying marching squares to a rectangular array of numeric values.
Use the ContourBuilder) to compute for a given set of values and thresholds:
The contour_rings function is a convenience function to compute ring (isoline) coordinates
for a single threshold.
While contour polygons (Contour) enclose all the values above a given threshold,
isobands (Band) are polygons that enclose all the values between two thresholds.
The core of the algorithm is ported from d3-contour.
§Example:
let c = ContourBuilder::new(10, 10, false); // x dim., y dim., smoothing
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]).unwrap(); // values, thresholds
let output = serde_json::json!({
"type": "Feature",
"geometry": {
"type": "MultiPolygon",
"coordinates": [[[
[6., 7.5], [6., 6.5], [6., 5.5], [6., 4.5],
[6., 3.5], [5.5, 3.], [4.5, 3.], [3.5, 3.],
[3., 3.5], [3., 4.5], [3., 5.5], [3., 6.5],
[3., 7.5], [3.5, 8.], [4.5, 8.], [5.5, 8.],
[6., 7.5]
]]],
},
"properties": {"threshold": 0.5},
});
assert_eq!(res[0].to_geojson(), std::convert::TryFrom::try_from(output).unwrap());Structs§
- Band
- An isoband has the geometry and min / max values of a contour ring, built by [
ContourBuilder]. - Contour
- A contour has the geometry and threshold of a contour ring, built by [
ContourBuilder]. - Contour
Builder - Contours generator, using builder pattern, to
be used on a rectangular
Sliceof values to get aVecofContour(usescontour_ringsinternally). - Error
- An error that can occur when computing contours.
- Line
- A line has the geometry and threshold of a contour ring, built by [
ContourBuilder].
Enums§
- Error
Kind - The specific type of an error.
Functions§
- contour_
rings - Computes isoring for the given
Sliceofvaluesaccording to thethresholdvalue (the inside of the isoring is the surface where inputvaluesare greater than or equal to the given threshold value).