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§
- An isoband has the geometry and min / max values of a contour ring, built by [
ContourBuilder
]. - A contour has the geometry and threshold of a contour ring, built by [
ContourBuilder
]. - Contours generator, using builder pattern, to be used on a rectangular
Slice
of values to get aVec
ofContour
(usescontour_rings
internally). - An error that can occur when computing contours.
- A line has the geometry and threshold of a contour ring, built by [
ContourBuilder
].
Enums§
- The specific type of an error.
Functions§
- Computes isoring for the given
Slice
ofvalues
according to thethreshold
value (the inside of the isoring is the surface where inputvalues
are greater than or equal to the given threshold value).