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.
Implementations§
source§impl SFCGeometry
impl SFCGeometry
pub fn new_from_coordinates<T>(coords: &CoordSeq<T>) -> Result<SFCGeometry>where
T: ToSFCGALGeom + CoordType,
sourcepub fn to_wkt(&self) -> Result<String>
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)
sourcepub fn to_wkt_decim(&self, nb_decim: i32) -> Result<String>
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)
sourcepub fn is_measured(&self) -> Result<bool>
pub fn is_measured(&self) -> Result<bool>
Test if the given SFCGeometry
is measured (has an ‘m’ coordinates)
sourcepub fn validity_detail(&self) -> Result<Option<String>>
pub fn validity_detail(&self) -> Result<Option<String>>
Returns reason for the invalidity or None in case of validity.
sourcepub fn distance(&self, other: &SFCGeometry) -> Result<f64>
pub fn distance(&self, other: &SFCGeometry) -> Result<f64>
Computes the distance to an other SFCGeometry
.
sourcepub fn distance_3d(&self, other: &SFCGeometry) -> Result<f64>
pub fn distance_3d(&self, other: &SFCGeometry) -> Result<f64>
Computes the 3d distance to an other SFCGeometry
.
sourcepub fn volume(&self) -> Result<f64>
pub fn volume(&self) -> Result<f64>
Computes the volume of the given SFCGeometry
(must be a volume).
sourcepub fn orientation(&self) -> Result<Orientation>
pub fn orientation(&self) -> Result<Orientation>
Computes the orientation of the given SFCGeometry
(must be a Polygon)
sourcepub fn intersects(&self, other: &SFCGeometry) -> Result<bool>
pub fn intersects(&self, other: &SFCGeometry) -> Result<bool>
Test the intersection with an other SFCGeometry
.
sourcepub fn intersects_3d(&self, other: &SFCGeometry) -> Result<bool>
pub fn intersects_3d(&self, other: &SFCGeometry) -> Result<bool>
Test the 3d intersection with an other SFCGeometry
.
sourcepub fn intersection(&self, other: &SFCGeometry) -> Result<SFCGeometry>
pub fn intersection(&self, other: &SFCGeometry) -> Result<SFCGeometry>
Returns the intersection of the given SFCGeometry
to an other SFCGeometry
.
sourcepub fn intersection_3d(&self, other: &SFCGeometry) -> Result<SFCGeometry>
pub fn intersection_3d(&self, other: &SFCGeometry) -> Result<SFCGeometry>
Returns the 3d intersection of the given SFCGeometry
to an other SFCGeometry
.
sourcepub fn covers(&self, other: &SFCGeometry) -> Result<bool>
pub fn covers(&self, other: &SFCGeometry) -> Result<bool>
sourcepub fn covers_3d(&self, other: &SFCGeometry) -> Result<bool>
pub fn covers_3d(&self, other: &SFCGeometry) -> Result<bool>
sourcepub fn difference(&self, other: &SFCGeometry) -> Result<SFCGeometry>
pub fn difference(&self, other: &SFCGeometry) -> Result<SFCGeometry>
Returns the difference of the given SFCGeometry
to an other SFCGeometry
.
sourcepub fn difference_3d(&self, other: &SFCGeometry) -> Result<SFCGeometry>
pub fn difference_3d(&self, other: &SFCGeometry) -> Result<SFCGeometry>
Returns the 3d difference of the given SFCGeometry
to an other SFCGeometry
.
sourcepub fn union(&self, other: &SFCGeometry) -> Result<SFCGeometry>
pub fn union(&self, other: &SFCGeometry) -> Result<SFCGeometry>
Returns the union of the given SFCGeometry
to an other SFCGeometry
.
sourcepub fn union_3d(&self, other: &SFCGeometry) -> Result<SFCGeometry>
pub fn union_3d(&self, other: &SFCGeometry) -> Result<SFCGeometry>
Returns the 3d union of the given SFCGeometry
to an other SFCGeometry
.
sourcepub fn minkowski_sum(&self, other: &SFCGeometry) -> Result<SFCGeometry>
pub fn minkowski_sum(&self, other: &SFCGeometry) -> Result<SFCGeometry>
Returns the minkowski sum of the given SFCGeometry
and an other SFCGEOMETRY
.
(C API reference)
sourcepub fn straight_skeleton(&self) -> Result<SFCGeometry>
pub fn straight_skeleton(&self) -> Result<SFCGeometry>
Returns the straight skeleton of the given SFCGeometry
.
(C API reference)
sourcepub fn straight_skeleton_distance_in_m(&self) -> Result<SFCGeometry>
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)
sourcepub fn extrude_straight_skeleton(&self, height: f64) -> Result<SFCGeometry>
pub fn extrude_straight_skeleton(&self, height: f64) -> Result<SFCGeometry>
Returns the extrude straight skeleton of the given Polygon. (C API reference)
sourcepub fn extrude_polygon_straight_skeleton(
&self,
building_height: f64,
roof_height: f64
) -> Result<SFCGeometry>
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)
sourcepub fn approximate_medial_axis(&self) -> Result<SFCGeometry>
pub fn approximate_medial_axis(&self) -> Result<SFCGeometry>
Returns the approximate medial axis for the given SFCGeometry
Polygon.
(C API reference)
sourcepub fn offset_polygon(&self, radius: f64) -> Result<SFCGeometry>
pub fn offset_polygon(&self, radius: f64) -> Result<SFCGeometry>
Returns the offset polygon of the given SFCGeometry
.
(C API reference)
sourcepub fn extrude(&self, ex: f64, ey: f64, ez: f64) -> Result<SFCGeometry>
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
sourcepub fn tesselate(&self) -> Result<SFCGeometry>
pub fn tesselate(&self) -> Result<SFCGeometry>
Returns a tesselation of the given SFCGeometry
.
(C API reference)
sourcepub fn triangulate_2dz(&self) -> Result<SFCGeometry>
pub fn triangulate_2dz(&self) -> Result<SFCGeometry>
Returns a triangulation of the given SFCGeometry
.
(C API reference)
sourcepub fn convexhull(&self) -> Result<SFCGeometry>
pub fn convexhull(&self) -> Result<SFCGeometry>
Returns the convex hull of the given SFCGeometry
.
(C API reference)
sourcepub fn convexhull_3d(&self) -> Result<SFCGeometry>
pub fn convexhull_3d(&self) -> Result<SFCGeometry>
Returns the 3d convex hull of the given SFCGeometry
.
(C API reference)
sourcepub fn line_substring(&self, start: f64, end: f64) -> Result<SFCGeometry>
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)
sourcepub fn alpha_shapes(&self, alpha: f64, allow_holes: bool) -> Result<SFCGeometry>
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)
sourcepub fn optimal_alpha_shapes(
&self,
allow_holes: bool,
nb_components: usize
) -> Result<SFCGeometry>
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.
sourcepub fn create_collection(geoms: &mut [SFCGeometry]) -> Result<SFCGeometry>
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))",
);
sourcepub fn get_collection_members(self) -> Result<Vec<SFCGeometry>>
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
impl Clone for SFCGeometry
source§fn clone(&self) -> SFCGeometry
fn clone(&self) -> SFCGeometry
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SFCGeometry
impl Debug for SFCGeometry
source§impl Drop for SFCGeometry
impl Drop for SFCGeometry
source§impl FromGeoJSON for SFCGeometry
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
fn from_geojson<T: FromSlice + CoordType + ToSFCGALGeom>( geom: &GeometryValue ) -> Result<SFCGeometry>
source§impl ToCoordinates for SFCGeometry
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).
fn to_coordinates<T>(&self) -> Result<CoordSeq<T>>where
T: FromSFCGALGeom + CoordType,
source§impl ToGeoJSON for SFCGeometry
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
fn to_geojson<T: FromSlice + CoordType + ToVec + FromSFCGALGeom>( &self ) -> Result<GeometryValue>
source§impl TryInto<Geometry> for SFCGeometry
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.