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§

SFCGeometry
Object representing a SFCGAL Geometry.

Enums§

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

Traits§

FromGeoJSON
Conversion from GeoJson to SFCGAL Geometries.
ToCoordinates
Convert object to a CoordSeq holding coordinates and information about geometry type.
ToGeoJSON
Conversion from SFCGAL Geometries to GeoJson.
ToSFCGAL
Convert object to a SFCGeometry (implemented on CoordSeq and geo-types geometries)
TryInto
Conversion from SFCGeometry (implemented on geo-types geometries)

Functions§

version
Display SFCGAL version information.

Type Aliases§

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