You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Computes *isorings* and __*contour polygons*__ by applying [marching squares](https://en.wikipedia.org/wiki/Marching_squares) to a rectangular array of numeric values.
8
-
Outputs ring coordinates or polygons contours as a `Vec` of [GeoJSON](https://github.com/georust/rust-geojson)[Feature](https://docs.rs/geojson/latest/geojson/struct.Feature.html)s.
8
+
Outputs ring coordinates or polygons contours (represented using geo-types [MultiPolygon](https://docs.rs/geo-types/latest/geo_types/geometry/struct.MultiPolygon.html)s).
9
+
The generated contours can also easily be serialised to GeoJSON.
10
+
9
11
*Note : This is a port of [d3-contour](https://github.com/d3/d3-contour).*
- a `contour_rings` function, which computes isorings coordinates for one threshold value (*returns a `Vec` of rings coordinates*).
30
-
- a `ContourBuilder` struct, which computes isorings coordinates for a `Vec` of threshold values and transform them in `MultiPolygon`s (*returns a `Vec` of GeoJSON Features*).
32
+
- a `ContourBuilder` struct, which computes isorings coordinates for a `Vec` of threshold values and transform them in `Contour`s (a type containing the threshold value and the geometry as a MultiPolygon, easily serializable to GeoJSON).
31
33
32
34
33
35
### Example:
34
36
37
+
**Without defining origin and step:**
38
+
35
39
```rust
36
40
letc=ContourBuilder::new(10, 10, false); // x dim., y dim., smoothing
37
41
letres=c.contours(&vec![
@@ -47,24 +51,89 @@ let res = c.contours(&vec![
47
51
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
48
52
], &[0.5])?; // values, thresholds
49
53
```
54
+
55
+
**With origin and step**
56
+
57
+
```rust
58
+
letc=ContourBuilder::new(10, 10, true) // x dim., y dim., smoothing
59
+
.x_step(2) // The horizontal coordinate for the origin of the grid.
60
+
.y_step(2) // The vertical coordinate for the origin of the grid.
61
+
.x_origin(100) // The horizontal step for the grid
62
+
.y_origin(200); // The vertical step for the grid
63
+
64
+
letres=c.contours(&[
65
+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
66
+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
67
+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
68
+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
69
+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
70
+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
71
+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
72
+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
73
+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
74
+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
75
+
], &[0.5]).unwrap(); // values, thresholds
76
+
77
+
```
78
+
79
+
**Using the `geojson` feature**
80
+
81
+
The `geojson` feature is not enabled by default, so you need to specify it in your `Cargo.toml`:
82
+
83
+
```toml
84
+
[dependencies]
85
+
contour = { version = "0.7.0", features = ["geojson"] }
86
+
```
87
+
88
+
```rust
89
+
letc=ContourBuilder::new(10, 10, true) // x dim., y dim., smoothing
90
+
.x_step(2) // The horizontal coordinate for the origin of the grid.
91
+
.y_step(2) // The vertical coordinate for the origin of the grid.
92
+
.x_origin(100) // The horizontal step for the grid
93
+
.y_origin(200); // The vertical step for the grid
94
+
95
+
letres=c.contours(&[
96
+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
97
+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
98
+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
99
+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
100
+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
101
+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
102
+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
103
+
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
104
+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
105
+
0., 0., 0., 0., 0., 0., 0., 0., 0., 0.
106
+
], &[0.5]).unwrap(); // values, thresholds
107
+
println!("{:?}", res[0].to_geojson()); // prints the GeoJSON representation of the first contour
0 commit comments