Struct sfcgal::SFCGeometry

source ·
#[repr(C)]
pub struct SFCGeometry { /* private fields */ }
Expand description

Object representing a SFCGAL Geometry.

Most of the operations allowed by SFCGAL C API are wrapped, except those modifying the geometry in-place (such as adding a new point to a linestring for example) and those retrieving a specific part of a geometry (such as getting the 2nd interior ring of some polygon as a linestring). However, this can easily be done by yourself by converting them from/to coordinates with the new_from_coordinates and to_coordinates methods.

(C API reference)

Implementations§

source§

impl SFCGeometry

source

pub fn new(wkt: &str) -> Result<SFCGeometry>

Create a geometry by parsing a WKT string.

source

pub fn new_from_coordinates<T>(coords: &CoordSeq<T>) -> Result<SFCGeometry>
where T: ToSFCGALGeom + CoordType,

source

pub fn to_wkt(&self) -> Result<String>

Returns a WKT representation of the given SFCGeometry using CGAL exact integer fractions as coordinate values. (C API reference)

source

pub fn to_wkt_decim(&self, nb_decim: i32) -> Result<String>

Returns a WKT representation of the given SFCGeometry using floating point coordinate values with the desired number of decimals. (C API reference)

source

pub fn is_empty(&self) -> Result<bool>

Test if the given SFCGeometry is empty or not.

source

pub fn is_valid(&self) -> Result<bool>

Test if the given SFCGeometry is valid or not.

source

pub fn is_measured(&self) -> Result<bool>

Test if the given SFCGeometry is measured (has an ‘m’ coordinates)

source

pub fn validity_detail(&self) -> Result<Option<String>>

Returns reason for the invalidity or None in case of validity.

source

pub fn is_planar(&self) -> Result<bool>

Test if the given SFCGeometry is planar or not.

source

pub fn is_3d(&self) -> Result<bool>

Test if the given SFCGeometry is a 3d geometry or not.

source

pub fn _type(&self) -> Result<GeomType>

Returns the SFCGAL type of the given SFCGeometry.

source

pub fn distance(&self, other: &SFCGeometry) -> Result<f64>

Computes the distance to an other SFCGeometry.

source

pub fn distance_3d(&self, other: &SFCGeometry) -> Result<f64>

Computes the 3d distance to an other SFCGeometry.

source

pub fn area(&self) -> Result<f64>

Computes the area of the given SFCGeometry.

source

pub fn area_3d(&self) -> Result<f64>

Computes the 3d area of the given SFCGeometry.

source

pub fn volume(&self) -> Result<f64>

Computes the volume of the given SFCGeometry (must be a volume).

source

pub fn orientation(&self) -> Result<Orientation>

Computes the orientation of the given SFCGeometry (must be a Polygon)

source

pub fn intersects(&self, other: &SFCGeometry) -> Result<bool>

Test the intersection with an other SFCGeometry.

source

pub fn intersects_3d(&self, other: &SFCGeometry) -> Result<bool>

Test the 3d intersection with an other SFCGeometry.

source

pub fn intersection(&self, other: &SFCGeometry) -> Result<SFCGeometry>

Returns the intersection of the given SFCGeometry to an other SFCGeometry.

source

pub fn intersection_3d(&self, other: &SFCGeometry) -> Result<SFCGeometry>

Returns the 3d intersection of the given SFCGeometry to an other SFCGeometry.

source

pub fn covers(&self, other: &SFCGeometry) -> Result<bool>

source

pub fn covers_3d(&self, other: &SFCGeometry) -> Result<bool>

source

pub fn difference(&self, other: &SFCGeometry) -> Result<SFCGeometry>

Returns the difference of the given SFCGeometry to an other SFCGeometry.

source

pub fn difference_3d(&self, other: &SFCGeometry) -> Result<SFCGeometry>

Returns the 3d difference of the given SFCGeometry to an other SFCGeometry.

source

pub fn union(&self, other: &SFCGeometry) -> Result<SFCGeometry>

Returns the union of the given SFCGeometry to an other SFCGeometry.

source

pub fn union_3d(&self, other: &SFCGeometry) -> Result<SFCGeometry>

Returns the 3d union of the given SFCGeometry to an other SFCGeometry.

source

pub fn minkowski_sum(&self, other: &SFCGeometry) -> Result<SFCGeometry>

Returns the minkowski sum of the given SFCGeometry and an other SFCGEOMETRY. (C API reference)

source

pub fn straight_skeleton(&self) -> Result<SFCGeometry>

Returns the straight skeleton of the given SFCGeometry. (C API reference)

source

pub fn straight_skeleton_distance_in_m(&self) -> Result<SFCGeometry>

Returns the straight skeleton of the given SFCGeometry with the distance to the border as M coordinate. (C API reference)

source

pub fn extrude_straight_skeleton(&self, height: f64) -> Result<SFCGeometry>

Returns the extrude straight skeleton of the given Polygon. (C API reference)

source

pub fn extrude_polygon_straight_skeleton( &self, building_height: f64, roof_height: f64 ) -> Result<SFCGeometry>

Returns the union of the polygon z-extrusion (with respect to building_height) and the extrude straight skeleton (with respect to roof_height) of the given Polygon. (C API reference)

source

pub fn approximate_medial_axis(&self) -> Result<SFCGeometry>

Returns the approximate medial axis for the given SFCGeometry Polygon. (C API reference)

source

pub fn offset_polygon(&self, radius: f64) -> Result<SFCGeometry>

Returns the offset polygon of the given SFCGeometry. (C API reference)

source

pub fn extrude(&self, ex: f64, ey: f64, ez: f64) -> Result<SFCGeometry>

Returns the extrusion of the given SFCGeometry (not supported on Solid and Multisolid). (C API reference

source

pub fn tesselate(&self) -> Result<SFCGeometry>

Returns a tesselation of the given SFCGeometry. (C API reference)

source

pub fn triangulate_2dz(&self) -> Result<SFCGeometry>

Returns a triangulation of the given SFCGeometry. (C API reference)

source

pub fn convexhull(&self) -> Result<SFCGeometry>

Returns the convex hull of the given SFCGeometry. (C API reference)

source

pub fn convexhull_3d(&self) -> Result<SFCGeometry>

Returns the 3d convex hull of the given SFCGeometry. (C API reference)

source

pub fn line_substring(&self, start: f64, end: f64) -> Result<SFCGeometry>

Returns the substring of the given SFCGeometry LineString between fractional distances. (C API reference)

source

pub fn alpha_shapes(&self, alpha: f64, allow_holes: bool) -> Result<SFCGeometry>

Returns the alpha shape of the given SFCGeometry Point set. (C API reference)

source

pub fn optimal_alpha_shapes( &self, allow_holes: bool, nb_components: usize ) -> Result<SFCGeometry>

Return the optimal alpha shape of the given SFCGeometry Point set.

source

pub fn create_collection(geoms: &mut [SFCGeometry]) -> Result<SFCGeometry>

Create a SFCGeometry collection type (MultiPoint, MultiLineString, MultiPolygon, MultiSolid or GeometryCollection) given a mutable slice of SFCGeometry’s (this is a destructive operation)

use sfcgal::SFCGeometry;
let a = SFCGeometry::new("POINT(1.0 1.0)").unwrap();
let b = SFCGeometry::new("POINT(2.0 2.0)").unwrap();
let g = SFCGeometry::create_collection(&mut[a, b]).unwrap();
assert_eq!(
    g.to_wkt_decim(1).unwrap(),
    "MULTIPOINT((1.0 1.0),(2.0 2.0))",
);
source

pub fn get_collection_members(self) -> Result<Vec<SFCGeometry>>

Get the members of a SFCGeometry. Returns Err if the SFCGeometry if not a collection (i.e. if it’s type is not in { MultiPoint, MultiLineString, MultiPolygon, MultiSolid, GeometryCollection }). The original geometry stay untouched.

use sfcgal::SFCGeometry;
let g = SFCGeometry::new("MULTIPOINT((1.0 1.0),(2.0 2.0))").unwrap();
let members = g.get_collection_members().unwrap();
assert_eq!(
    members[0].to_wkt_decim(1).unwrap(),
    "POINT(1.0 1.0)",
);
assert_eq!(
    members[1].to_wkt_decim(1).unwrap(),
    "POINT(2.0 2.0)",
);

Trait Implementations§

source§

impl Clone for SFCGeometry

source§

fn clone(&self) -> SFCGeometry

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SFCGeometry

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for SFCGeometry

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl FromGeoJSON for SFCGeometry

Conversion from GeoJson to SFCGAL geometries.

Allows to choose if the constructed SFCGAL geometries will be 2d or 3d.

use sfcgal::{SFCGeometry, FromGeoJSON};
type Point2d = (f64, f64);

let geom = geojson::Geometry {
    bbox: None,
    value: geojson::Value::LineString(vec![vec![101.0, 0.0], vec![102.0, 1.0]]),
    foreign_members: None,
};
let line_sfcgal = SFCGeometry::from_geojson::<Point2d>(&geom.value).unwrap();
§

type Err = Error

source§

fn from_geojson<T: FromSlice + CoordType + ToSFCGALGeom>( geom: &GeometryValue ) -> Result<SFCGeometry>

source§

impl ToCoordinates for SFCGeometry

Convert a SFCGeometry, given it’s internal GeomType, to the corresponding CoordSeq holding its coordinates (as tuple of 2 or 3 members).

source§

fn to_coordinates<T>(&self) -> Result<CoordSeq<T>>
where T: FromSFCGALGeom + CoordType,

source§

impl ToGeoJSON for SFCGeometry

Conversion from SFCGAL Geometries to GeoJson.

Allows to choose if coordinates of constructed geojson have to be 2d or 3d.

use sfcgal::{SFCGeometry, ToGeoJSON};
type Point3d = (f64, f64, f64);

let input_wkt = "POINT(0.1 0.9 1.0)";
let pt_sfcgal = SFCGeometry::new(input_wkt).unwrap();
let pt_geojson = pt_sfcgal.to_geojson::<Point3d>().unwrap();
§

type Err = Error

source§

fn to_geojson<T: FromSlice + CoordType + ToVec + FromSFCGALGeom>( &self ) -> Result<GeometryValue>

source§

impl TryInto<Geometry> for SFCGeometry

Implements faillible conversion from SFCGeometry to geo_types::Geometry.

This is notably faillible because some types of SFCGeometry like GeoTypes::Polyhedralsurface don’t have equivalents in geo_types::Geometry. Please note that geo_types Coordinate and Point primitives are 2d only, so every information about z coordinate (if any) won’t be taken into account.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.