All Projects β†’ mthh β†’ contour-rs

mthh / contour-rs

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
Contour polygon creation in Rust (using marching squares algorithm)

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to contour-rs

leaflet-examples
🍁 A collection of examples of leaflet map usage
Stars: ✭ 90 (+172.73%)
Mutual labels:  geojson, polygons
crc32c
Fast CRC-32-Castagnoli implementation in Rust
Stars: ✭ 26 (-21.21%)
Mutual labels:  rust-library
Rgm
Tiny (1kb less) but very powerful React Google Map
Stars: ✭ 221 (+569.7%)
Mutual labels:  geojson
kandilli-rasathanesi-api
Kandilli rasathanesinin son dakika depremler ve tarihe gâre deprem listesi için ara API (last minute earthquakes in turkey)
Stars: ✭ 90 (+172.73%)
Mutual labels:  geojson
Mapshaper
Tools for editing Shapefile, GeoJSON, TopoJSON and CSV files
Stars: ✭ 2,813 (+8424.24%)
Mutual labels:  geojson
cogj-spec
Cloud Optimized GeoJSON spec
Stars: ✭ 36 (+9.09%)
Mutual labels:  geojson
Django Geojson
django-geojson is a collection of helpers to (de)serialize (Geo)Django objects into GeoJSON.
Stars: ✭ 209 (+533.33%)
Mutual labels:  geojson
Nebuchadnezzar
High Performance Key-Value Store
Stars: ✭ 49 (+48.48%)
Mutual labels:  rust-library
arangors
Easy to use rust driver for arangoDB
Stars: ✭ 120 (+263.64%)
Mutual labels:  rust-library
geojson-editor
A modified version of Googles Simple GeoJSON Editor
Stars: ✭ 43 (+30.3%)
Mutual labels:  geojson
geojsoncontour
Convert matplotlib contour plots to geojson
Stars: ✭ 78 (+136.36%)
Mutual labels:  geojson
Mapstore2
Modern webmapping with OpenLayers, Leaflet and React
Stars: ✭ 251 (+660.61%)
Mutual labels:  geojson
i2p-rs
Rust client library for interacting with I2P
Stars: ✭ 62 (+87.88%)
Mutual labels:  rust-library
Geojson.js
Turn your geo data into GeoJSON. For Node.js and the browser.
Stars: ✭ 223 (+575.76%)
Mutual labels:  geojson
gjf
A tool in Python to fix invalid GeoJSON objects and files
Stars: ✭ 94 (+184.85%)
Mutual labels:  geojson
Qgis Latlontools Plugin
QGIS tools to capture and zoom to coordinates using decimal, DMS, WKT, GeoJSON, MGRS, UTM, and Plus Codes notation. Provides external map support, MGRS & Plus Codes conversion and point digitizing tools.
Stars: ✭ 213 (+545.45%)
Mutual labels:  geojson
echarty
Minimal R/Shiny Interface to ECharts.js
Stars: ✭ 49 (+48.48%)
Mutual labels:  geojson
hidapi-rs
Rust bindings for the hidapi C library
Stars: ✭ 103 (+212.12%)
Mutual labels:  rust-library
vfin
🦈 GUI framework agnostic virtual DOM library
Stars: ✭ 17 (-48.48%)
Mutual labels:  rust-library
HitboxBuilder-2D
Building hitboxes has never been easier
Stars: ✭ 21 (-36.36%)
Mutual labels:  marching-squares

contour-rs

Build status GitHub Actions Build status Appveyor Docs.rs version

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). For each threshold value, the contour polygon are representing the area where the input values are greater than or equal to the threshold value.

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:

[dependencies]
contour = "0.9.0"

and this to your crate root:

extern crate contour;

The API exposes:

  • a ContourBuilder struct, which computes isorings coordinates for a Vec of threshold values and transform them either :

    • in Contours (a type containing the threshold value and the geometry as a MultiPolygon, easily serializable to GeoJSON), or,
    • in Lines (a type containing the threshold value and the geometry as a MultiLineString, easily serializable to GeoJSON).
  • a contour_rings function, which computes isorings coordinates for a single threshold value (returns a Vec of rings coordinates - this is what is used internally by the ContourBuilder).

ContourBuilder is the recommended way to use this crate, as it is more flexible and easier to use (it enables to specify the origin and the step of the grid, and to smooth the contours, while contour_rings only speak in grid coordinates and doesn't smooth the resulting rings).

Example:

Without defining origin and step:

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])?; // values, thresholds

With origin and step

let c = ContourBuilder::new(10, 10, true) // x dim., y dim., smoothing
    .x_step(2) // The horizontal coordinate for the origin of the grid.
    .y_step(2) // The vertical coordinate for the origin of the grid.
    .x_origin(100) // The horizontal step for the grid
    .y_origin(200); // The vertical step for the grid

let res = c.contours(&[
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., 0., 1., 0., 0., 0.,
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
0., 0., 0., 1., 1., 0., 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.5]).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:

[dependencies]
contour = { version = "0.8.0", features = ["geojson"] }
let c = ContourBuilder::new(10, 10, true) // x dim., y dim., smoothing
    .x_step(2) // The horizontal coordinate for the origin of the grid.
    .y_step(2) // The vertical coordinate for the origin of the grid.
    .x_origin(100) // The horizontal step for the grid
    .y_origin(200); // The vertical step for the grid

let res = c.contours(&[
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., 0., 1., 0., 0., 0.,
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
0., 0., 0., 1., 1., 0., 1., 0., 0., 0.,
0., 0., 0., 1., 1., 0., 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.5]).unwrap(); // values, thresholds
println!("{:?}", res[0].to_geojson()); // prints the GeoJSON representation of the first contour

Output:

Feature {
    bbox: None,
    geometry: Some(Geometry {
        bbox: None,
        value: MultiPolygon([
            [[
                [110.0, 215.0], [110.0, 213.0], [110.0, 211.0], [110.0, 209.0],
                [110.0, 207.0], [109.0, 206.0], [107.0, 206.0], [106.0, 207.0],
                [106.0, 209.0], [106.0, 211.0], [106.0, 213.0], [106.0, 215.0],
                [107.0, 216.0], [109.0, 216.0], [110.0, 215.0]
            ]],
            [[
                [114.0, 215.0], [114.0, 213.0], [114.0, 211.0], [114.0, 209.0],
                [114.0, 207.0], [113.0, 206.0], [112.0, 207.0], [112.0, 209.0],
                [112.0, 211.0], [112.0, 213.0], [112.0, 215.0], [113.0, 216.0],
                [114.0, 215.0]
            ]]
        ]),
        foreign_members: None
    }),
    id: None,
    properties: Some({"threshold": Number(0.5)}),
    foreign_members: None
}

WASM demo

Demo of this crate compiled to WebAssembly and used from JavaScript : wasm_demo_contour.

Difference with the contour-isobands crate (from mthh/contour-isobands-rs repository)

While this crate computes isolines (cf. wikipedia:Marching_squares) and their corresponding polygons (i.e. polygons that contain all points above the threshold defined for a given isoline), contour-isobands-rs computes isobands (cf. wikipedia:Marching_squares#Isobands) and their corresponding polygons (i.e. contour polygons that contain all points between a minimum and a maximum bound).

Depending on the desired use of the result, the contour-isobands crate may be more suitable than this contour crate.

License

Licensed under either of

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].