contour-rs
Computes isorings and contour polygons by applying marching squares to a rectangular array of numeric values.
Outputs ring coordinates or polygons contours (represented using geo-types MultiPolygons).
The generated contours can also easily be serialised to GeoJSON.
Note : This is a port of d3-contour.
Usage
Add this to your Cargo.toml:
[]
= "0.7.0"
and this to your crate root:
extern crate contour;
The API exposes:
- a
contour_ringsfunction, which computes isorings coordinates for one threshold value (returns aVecof rings coordinates). - a
ContourBuilderstruct, which computes isorings coordinates for aVecof threshold values and transform them inContours (a type containing the threshold value and the geometry as a MultiPolygon, easily serializable to GeoJSON).
Example:
Without defining origin and step:
let c = new; // x dim., y dim., smoothing
let res = c.contours?; // values, thresholds
With origin and step
let c = new // x dim., y dim., smoothing
.x_step // The horizontal coordinate for the origin of the grid.
.y_step // The vertical coordinate for the origin of the grid.
.x_origin // The horizontal step for the grid
.y_origin; // The vertical step for the grid
let res = c.contours.unwrap; // values, thresholds
Using the geojson feature
The geojson feature is not enabled by default, so you need to specify it in your Cargo.toml:
[]
= { = "0.7.0", = ["geojson"] }
let c = new // x dim., y dim., smoothing
.x_step // The horizontal coordinate for the origin of the grid.
.y_step // The vertical coordinate for the origin of the grid.
.x_origin // The horizontal step for the grid
.y_origin; // The vertical step for the grid
let res = c.contours.unwrap; // values, thresholds
println!; // prints the GeoJSON representation of the first contour
Output:
Feature
Demo
Demo of this crate compiled to WebAssembly and used from JavaScript : wasm_demo_contour.
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.