Struct sfcgal::SFCGeometry

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

Object representing a SFCGAL Geometry.

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.

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.

source

pub fn to_wkb_in_memory(&self) -> Result<Vec<u8>>

Creates a Wkb string of the given geometry. In memory version.

source

pub unsafe fn to_ewkt_in_memory( prepared: *const sfcgal_prepared_geometry_t, num_decimals: i32, ) -> Result<Vec<u8>>

§Safety

Returns an EWKT representation of the given PreparedGeometry

source

pub fn to_hexwkb_in_memory(&self) -> Result<Vec<u8>>

Creates a Hexwkb string of the given geometry. In memory version.

source

pub fn io_read_binary_prepared( data: &[u8], ) -> Result<*mut sfcgal_prepared_geometry_t>

Read the binary prepared geometry

source

pub fn io_read_wkb(data: &[u8]) -> Result<*mut sfcgal_prepared_geometry_t>

Read the binary prepared geometry

source

pub fn io_read_ewkt(data: &[u8]) -> Result<*mut sfcgal_prepared_geometry_t>

Read the binary prepared geometry

source

pub unsafe fn io_write_binary_prepared( prepared_geometry: *mut sfcgal_prepared_geometry_t, ) -> Result<Vec<u8>>

§Safety

Read the binary prepared geometry in memory

source

pub fn to_obj_file(&self, filename: &str) -> Result<()>

Creates a OBJ file of the given geometry

source

pub fn to_obj_in_memory(&self) -> Result<Vec<u8>>

Creates a OBJ string of the given geometry. In memory version.

source

pub fn to_vtk_file(&self, filename: &str) -> Result<()>

Creates a VTK file of the given geometry

source

pub fn to_vtk_in_memory(&self) -> Result<Vec<u8>>

Creates a VTK string of the given geometry. In memory version.

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 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 validity_detail(&self) -> Result<Option<String>>

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

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>

Test if the geometry covers an other SFCGeometry.

source

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

Test if the geometry covers an other SFCGeometry in 3D.

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.

source

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

Returns the straight skeleton of the given SFCGeometry.

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.

source

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

Returns the extrude straight skeleton of the given Polygon.

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.

source

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

Returns the approximate medial axis for the given SFCGeometry Polygon.

source

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

Returns the offset polygon of the given SFCGeometry.

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).

source

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

Returns a tesselation of the given SFCGeometry.

source

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

Returns a triangulation of the given SFCGeometry.

source

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

Returns the convex hull of the given SFCGeometry.

source

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

Returns the 3d convex hull of the given SFCGeometry.

source

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

Returns the substring of the given SFCGeometry LineString between fractional distances.

source

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

Returns the alpha shape of the given SFCGeometry Point set.

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)",
);
source

pub fn point_create() -> Result<SFCGeometry>

Creates an empty point

source

pub fn point_create_from_xy(x: f64, y: f64) -> Result<SFCGeometry>

Creates a point from two X and Y coordinates

source

pub fn point_create_from_xym(x: f64, y: f64, m: f64) -> Result<SFCGeometry>

Creates a point from three X, Y and M coordinates

source

pub fn point_create_from_xyz(x: f64, y: f64, z: f64) -> Result<SFCGeometry>

Creates a point from three X, Y and Z coordinates

source

pub fn point_create_from_xyzm( &self, x: f64, y: f64, z: f64, m: f64, ) -> Result<SFCGeometry>

Create a point from x, y, z, m components.

source

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

Returns the X coordinate of the given Point

source

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

Returns the Y coordinate of the given Point

source

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

Returns the Z coordinate of the given Point

source

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

Returns the M coordinate of the given Point

source

pub fn triangle_set_vertex( &self, index: i32, vertex: &SFCGeometry, ) -> Result<()>

Sets one vertex of a Triangle

source

pub fn triangle_set_vertex_from_xy( &self, index: i32, x: f64, y: f64, ) -> Result<()>

Sets one vertex of a Triangle from two coordinates

source

pub fn triangle_set_vertex_from_xyz( &self, index: i32, x: f64, y: f64, z: f64, ) -> Result<()>

Sets one vertex of a Triangle from three coordinates

source

pub fn straight_skeleton_partition( &self, auto_orientation: bool, ) -> Result<SFCGeometry>

Returns the straight skeleton partition for the given Polygon

source

pub fn visibility_point(&self, point: &SFCGeometry) -> Result<SFCGeometry>

Returns the visibility polygon of a Point inside a Polygon

source

pub fn rotate(&self, angle: f64) -> Result<SFCGeometry>

Rotates a geometry around the origin (0,0,0) by a given angle

source

pub fn rotate_x(&self, angle: f64) -> Result<SFCGeometry>

Rotates a geometry around the X axis by a given angle

source

pub fn rotate_y(&self, angle: f64) -> Result<SFCGeometry>

Rotates a geometry around the Y axis by a given angle

source

pub fn rotate_z(&self, angle: f64) -> Result<SFCGeometry>

Rotates a geometry around the Z axis by a given angle

source

pub fn rotate_2d( &self, angle: f64, origin_x: f64, origin_y: f64, ) -> Result<SFCGeometry>

Rotates a geometry around a specified point by a given angle

source

pub fn rotate_3d( &self, angle: f64, axis_x_angle: f64, axis_y_angle: f64, axis_z_angle: f64, ) -> Result<SFCGeometry>

Rotates a 3D geometry around a specified axis by a given angle

source

pub fn rotate_3d_around_center( &self, angle: f64, axis_x_angle: f64, axis_y_angle: f64, axis_z_angle: f64, center_x: f64, center_y: f64, center_z: f64, ) -> Result<SFCGeometry>

Rotates a 3D geometry around a specified axis and center point by a given

source

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

Force a Right Handed Rule on the given Geometry

source

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

Force a Left Handed Rule on the given Geometry

source

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

Scale a geometry by a given factor

source

pub fn scale_3d( &self, scale_x: f64, scale_y: f64, scale_z: f64, ) -> Result<SFCGeometry>

Scale a geometry by different factors for each dimension

source

pub fn scale_3d_around_center( &self, factor_x: f64, factor_y: f64, factor_z: f64, center_x: f64, center_y: f64, center_z: f64, ) -> Result<SFCGeometry>

Scale a geometry by different factors for each dimension around a center

source

pub fn round(&self, value: i32) -> Result<SFCGeometry>

Round coordinates of the given Geometry

source

pub fn buffer3d( &self, radius: f64, segments: i32, buffer_type: BufferType, ) -> Result<SFCGeometry>

Computes a 3D buffer around a geometry

source

pub fn has_validity_flag(&self) -> i32

Gets the validity flag of the geometry

source

pub fn visibility_segment( &self, point_a: &SFCGeometry, point_b: &SFCGeometry, ) -> Result<SFCGeometry>

Build the visibility polygon of the segment [pointA ; pointB] on a Polygon

source

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

Convert a PolyhedralSurface to a Solid

source

pub fn translate_2d(&self, dx: f64, dy: f64) -> Result<SFCGeometry>

Translate a geometry by a 2D vector

source

pub fn translate_3d( &self, translation_x: f64, translation_y: f64, translation_z: f64, ) -> Result<SFCGeometry>

Translate a geometry by a 3D vector

source

pub fn force_valid(&self, validity: i32)

Sets the validity flag of the geometry.

source

pub fn set_geometry_validation(enabled: i32)

Set the geometry validation mode

source

pub fn triangle_create() -> Result<SFCGeometry>

Creates an empty Triangle

source

pub fn triangle_vertex(&self, index: i32) -> Result<SFCGeometry>

Returns one the Triangle’s vertex as a Point

source

pub fn triangle_create_from_points( point_a: &SFCGeometry, point_b: &SFCGeometry, point_c: &SFCGeometry, ) -> Result<SFCGeometry>

Creates a Triangle from three given Point

source

pub fn triangulated_surface_create() -> Result<SFCGeometry>

Creates an empty TriangulatedSurface

source

pub fn triangulated_surface_triangle_n( &self, index: usize, ) -> Result<SFCGeometry>

Returns the ith Triangle of a given TriangulatedSurface

source

pub fn triangulated_surface_add_triangle( &self, triangle: &SFCGeometry, ) -> Result<()>

Adds a Triangle to a given TriangulatedSurface

source

pub fn triangulated_surface_num_triangles(&self) -> Result<usize>

Returns the number of triangles of a given TriangulatedSurface

source

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

Returns the optimal convex partition of a geometry (polygon without hole)

source

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

Returns the approximal convex partition of a geometry (polygon without hole)

source

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

Returns the greene approximal convex partition of a geometry (polygon without hole)

source

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

Returns the y monotone partition of a geometry (polygon without hole)

source

pub fn linestring_num_points(&self) -> Result<usize>

Returns the number of points of the given LineString

source

pub fn linestring_add_point(&self, point: &SFCGeometry) -> Result<()>

Adds a point to a LineString

source

pub fn linestring_point_n(&self, index: usize) -> Result<SFCGeometry>

Returns the ith point of a given LineString

source

pub fn linestring_create() -> Result<SFCGeometry>

Creates an empty LineString

source

pub fn polyhedral_surface_create() -> Result<SFCGeometry>

Creates an empty PolyhedralSurface

source

pub fn polyhedral_surface_num_polygons(&self) -> Result<usize>

Returns the number of polygons of a given PolyhedralSurface

source

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

Adds a Polygon to a given PolyhedralSurface

source

pub fn polyhedral_surface_polygon_n(&self, index: usize) -> Result<SFCGeometry>

Returns the ith polygon of a given PolyhedralSurface

source

pub fn set_error_handlers( warning_handler: sfcgal_error_handler_t, error_handler: sfcgal_error_handler_t, )

Sets the error handlers. These callbacks are called on warning or error

source

pub fn set_alloc_handlers( alloc_handler: sfcgal_alloc_handler_t, free_handler: sfcgal_free_handler_t, )

Sets the error handlers. These callbacks are called on warning or error

source

pub fn solid_create() -> Result<SFCGeometry>

Creates an empty Solid

source

pub fn solid_num_shells(&self) -> Result<usize>

Returns the number of shells of a given Solid

source

pub fn solid_create_from_exterior_shell( exterior_shell: &SFCGeometry, ) -> Result<SFCGeometry>

Creates a Solid from an exterior shell

source

pub fn solid_shell_n(&self, index: usize) -> Result<SFCGeometry>

Returns the ith shell of a given Solid

source

pub fn solid_add_interior_shell(&self, shell: &SFCGeometry) -> Result<()>

Adds a shell to a given Solid

source

pub fn polygon_create() -> Result<SFCGeometry>

Creates an empty Polygon

source

pub fn polygon_num_interior_rings(&self) -> Result<usize>

Returns the number of interior rings of a given Polygon

source

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

Returns the exterior ring of a given Polygon

source

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

Creates an empty Polygon from an extrior ring

source

pub fn polygon_add_interior_ring(&self, ring: &SFCGeometry) -> Result<()>

Adds an interior ring to a given Polygon

source

pub fn polygon_interior_ring_n(&self, index: usize) -> Result<SFCGeometry>

Returns the ith interior ring of a given Polygon

source

pub fn multi_solid_create() -> Result<SFCGeometry>

Creates an empty MultiSolid

source

pub unsafe fn prepared_geometry_set_srid( prepared_geometry: *mut sfcgal_prepared_geometry_t, srid: srid_t, )

§Safety

Sets SRID associated with a given PreparedGeometry

source

pub unsafe fn prepared_geometry_delete( prepared_geometry: *mut sfcgal_prepared_geometry_t, )

§Safety

Deletes a given PreparedGeometry

source

pub fn prepared_geometry_create_from_geometry( &self, srid: srid_t, ) -> Result<*mut sfcgal_prepared_geometry_t>

§Safety

Creates a PreparedGeometry from a Geometry and an SRID

source

pub unsafe fn prepared_geometry_set_geometry( &self, prepared: *mut sfcgal_prepared_geometry_t, )

§Safety

Sets the Geometry associated with the given PreparedGeometry

source

pub unsafe fn prepared_geometry_srid( prepared: *mut sfcgal_prepared_geometry_t, ) -> u32

§Safety

Returns SRID associated with a given PreparedGeometry

source

pub fn prepared_geometry_create() -> Result<*mut sfcgal_prepared_geometry_t>

Creates an empty PreparedGeometry

source

pub unsafe fn prepared_geometry_geometry( prepared_geometry: *mut sfcgal_prepared_geometry_t, ) -> Result<SFCGeometry>

§Safety

Returns the Geometry associated with a given PreparedGeometry

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();
source§

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();
source§

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

source§

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>,

source§

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>,

source§

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.