Crate sfcgal

source ·
Expand description

Rust bindings providing a high-level API to SFCGAL library and conversion to / from other geometry crates from Rust ecosystem. Based on the sfcgal-sys crate exposing low-level bindings.

Allows notably reading from / writing to WKT as well as interoperability with geojson and geo-types crates. It also offers an API to manipulate SFCGAL geometries from/to coordinates (represented as tuples of 2 or 3 positions).

§Example
extern crate sfcgal;
use sfcgal::{SFCGeometry, CoordSeq, ToGeoJSON, ToSFCGAL, Point2d, Point3d};

// Create SFCGAL geometries from coordinates..
let coords_linestring = vec![(-0.5, -0.5, 2.5), (0., 0., 4.0)];
let coords_polygon = vec![
    vec![(-1., -1., 3.0), (1., -1., 3.0), (1., 1., 3.0), (-1., 1., 3.0), (-1., -1., 3.0)], // Exterior ring
    vec![(0.1, 0.1, 3.0), (0.1, 0.9, 3.0), (0.9, 0.9, 3.0), (0.9, 0.1, 3.0), (0.1, 0.1, 3.0)], // 1 interior ring
];

// .. by using the CoordSeq enum variants to match the wanted SFCGAL geometry type:
let line_3d = CoordSeq::Linestring(coords_linestring).to_sfcgal()?;
let polygon_3d = CoordSeq::Polygon(coords_polygon).to_sfcgal()?;

// ..
assert!(line_3d.intersects_3d(&polygon_3d)?);
let intersection = line_3d.intersection_3d(&polygon_3d)?;

// Get the geojson representation of the geometry with 3-member coordinates :
let geom = intersection.to_geojson::<Point3d>()?;
// Or the wkt representation with a floating precision of 1 :
let wkt = intersection.to_wkt_decim(1)?;

Structs§

Enums§

  • Represent the buffer types usable with the buffer3d method.
  • Coordinates corresponding to the shapes described by SFCGAL Geometry types.
  • SFCGAL Geometry types.
  • Represents the orientation of a SFCGeometry.

Traits§

Functions§

  • Display SFCGAL version information.

Type Aliases§

  • Type alias for manipulating 2d coordinates, represented as (x, y).
  • Type alias for manipulating 3d coordinates, represented as (x, y, z).
  • Type alias for Result with the error type set to Error.