Trait geos::Geom

source ·
pub trait Geom: AsRaw<RawType = GEOSGeometry> + ContextHandling<Context = Arc<ContextHandle>> {
Show 89 methods // Required methods fn get_type(&self) -> GResult<String>; fn geometry_type(&self) -> GeometryTypes; fn is_valid(&self) -> bool; fn is_valid_reason(&self) -> GResult<String>; fn get_coord_seq(&self) -> GResult<CoordSeq>; fn area(&self) -> GResult<f64>; fn to_wkt(&self) -> GResult<String>; fn to_wkt_precision(&self, precision: u32) -> GResult<String>; fn is_ring(&self) -> GResult<bool>; fn intersects<G: Geom>(&self, other: &G) -> GResult<bool>; fn crosses<G: Geom>(&self, other: &G) -> GResult<bool>; fn disjoint<G: Geom>(&self, other: &G) -> GResult<bool>; fn touches<G: Geom>(&self, other: &G) -> GResult<bool>; fn overlaps<G: Geom>(&self, other: &G) -> GResult<bool>; fn within<G: Geom>(&self, other: &G) -> GResult<bool>; fn equals<G: Geom>(&self, other: &G) -> GResult<bool>; fn equals_exact<G: Geom>(&self, other: &G, precision: f64) -> GResult<bool>; fn covers<G: Geom>(&self, other: &G) -> GResult<bool>; fn covered_by<G: Geom>(&self, other: &G) -> GResult<bool>; fn contains<G: Geom>(&self, other: &G) -> GResult<bool>; fn buffer(&self, width: f64, quadsegs: i32) -> GResult<Geometry>; fn buffer_with_params( &self, width: f64, buffer_params: &BufferParams ) -> GResult<Geometry>; fn buffer_with_style( &self, width: f64, quadsegs: i32, end_cap_style: CapStyle, join_style: JoinStyle, mitre_limit: f64 ) -> GResult<Geometry>; fn is_empty(&self) -> GResult<bool>; fn is_simple(&self) -> GResult<bool>; fn difference<G: Geom>(&self, other: &G) -> GResult<Geometry>; fn envelope(&self) -> GResult<Geometry>; fn sym_difference<G: Geom>(&self, other: &G) -> GResult<Geometry>; fn union<G: Geom>(&self, other: &G) -> GResult<Geometry>; fn get_centroid(&self) -> GResult<Geometry>; fn unary_union(&self) -> GResult<Geometry>; fn voronoi<G: Geom>( &self, envelope: Option<&G>, tolerance: f64, only_edges: bool ) -> GResult<Geometry>; fn intersection<G: Geom>(&self, other: &G) -> GResult<Geometry>; fn convex_hull(&self) -> GResult<Geometry>; fn boundary(&self) -> GResult<Geometry>; fn has_z(&self) -> GResult<bool>; fn is_closed(&self) -> GResult<bool>; fn length(&self) -> GResult<f64>; fn distance<G: Geom>(&self, other: &G) -> GResult<f64>; fn distance_indexed<G: Geom>(&self, other: &G) -> GResult<f64>; fn hausdorff_distance<G: Geom>(&self, other: &G) -> GResult<f64>; fn hausdorff_distance_densify<G: Geom>( &self, other: &G, distance_frac: f64 ) -> GResult<f64>; fn frechet_distance<G: Geom>(&self, other: &G) -> GResult<f64>; fn frechet_distance_densify<G: Geom>( &self, other: &G, distance_frac: f64 ) -> GResult<f64>; fn get_length(&self) -> GResult<f64>; fn snap<G: Geom>(&self, other: &G, tolerance: f64) -> GResult<Geometry>; fn extract_unique_points(&self) -> GResult<Geometry>; fn nearest_points<G: Geom>(&self, other: &G) -> GResult<CoordSeq>; fn get_x(&self) -> GResult<f64>; fn get_y(&self) -> GResult<f64>; fn get_z(&self) -> GResult<f64>; fn get_point_n(&self, n: usize) -> GResult<Geometry>; fn get_start_point(&self) -> GResult<Geometry>; fn get_end_point(&self) -> GResult<Geometry>; fn get_num_points(&self) -> GResult<usize>; fn get_num_interior_rings(&self) -> GResult<usize>; fn get_num_coordinates(&self) -> GResult<usize>; fn get_num_dimensions(&self) -> GResult<usize>; fn get_coordinate_dimension(&self) -> GResult<Dimensions>; fn make_valid(&self) -> GResult<Geometry>; fn get_num_geometries(&self) -> GResult<usize>; fn get_srid(&self) -> GResult<usize>; fn get_precision(&self) -> GResult<f64>; fn set_precision( &self, grid_size: f64, flags: Precision ) -> GResult<Geometry>; fn get_x_max(&self) -> GResult<f64>; fn get_x_min(&self) -> GResult<f64>; fn get_y_max(&self) -> GResult<f64>; fn get_y_min(&self) -> GResult<f64>; fn minimum_clearance(&self) -> GResult<f64>; fn minimum_clearance_line(&self) -> GResult<Geometry>; fn minimum_rotated_rectangle(&self) -> GResult<Geometry>; fn minimum_width(&self) -> GResult<Geometry>; fn delaunay_triangulation( &self, tolerance: f64, only_edges: bool ) -> GResult<Geometry>; fn interpolate(&self, d: f64) -> GResult<Geometry>; fn interpolate_normalized(&self, d: f64) -> GResult<Geometry>; fn project<G: Geom>(&self, p: &G) -> GResult<f64>; fn project_normalized<G: Geom>(&self, p: &G) -> GResult<f64>; fn node(&self) -> GResult<Geometry>; fn offset_curve( &self, width: f64, quadrant_segments: i32, join_style: JoinStyle, mitre_limit: f64 ) -> GResult<Geometry>; fn point_on_surface(&self) -> GResult<Geometry>; fn polygonize_full( &self ) -> GResult<(Geometry, Option<Geometry>, Option<Geometry>, Option<Geometry>)>; fn shared_paths<G: Geom>(&self, other: &G) -> GResult<Geometry>; fn to_hex(&self) -> GResult<CVec<u8>>; fn to_wkb(&self) -> GResult<CVec<u8>>; fn to_prepared_geom<'c>(&'c self) -> GResult<PreparedGeometry>; fn clone(&self) -> Geometry; fn get_geometry_n(&self, n: usize) -> GResult<ConstGeometry<'_>>; fn get_interior_ring_n(&self, n: u32) -> GResult<ConstGeometry<'_>>; fn get_exterior_ring(&self) -> GResult<ConstGeometry<'_>>;
}

Required Methods§

source

fn get_type(&self) -> GResult<String>

Returns the type of the geometry.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))")
                    .expect("Invalid geometry");
assert_eq!(geom.get_type(), Ok("Polygon".to_owned()));
source

fn geometry_type(&self) -> GeometryTypes

source

fn is_valid(&self) -> bool

Checks if the geometry is valid.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))")
                    .expect("Invalid geometry");
assert!(geom.is_valid() == false);
source

fn is_valid_reason(&self) -> GResult<String>

Returns an explanation on why the geometry is invalid.

§Example
use geos::{Geom, Geometry};

// Bowtie polygon with self-intersection
let geom = Geometry::new_from_wkt("POLYGON((0 0, 2 2, 2 0, 0 2, 0 0))")
                    .expect("Invalid geometry");
assert_eq!(
    geom.is_valid_reason(),
    Ok("Self-intersection[1 1]".to_owned()),
);
source

fn get_coord_seq(&self) -> GResult<CoordSeq>

Get the underlying geos CoordSeq object from the geometry

Note: this clones the underlying CoordSeq to avoid double free (because CoordSeq handles the object ptr and the CoordSeq is still owned by the geos geometry) if this method’s performance becomes a bottleneck, feel free to open an issue, we could skip this clone with cleaner code.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POINT (2 3)")
                    .expect("Invalid geometry");
let coord_seq = geom.get_coord_seq().expect("get_coord_seq failed");

assert_eq!(coord_seq.get_x(0), Ok(2.));
assert_eq!(coord_seq.get_y(0), Ok(3.));
source

fn area(&self) -> GResult<f64>

Returns the area of the geometry. Units are specified by the SRID of the given geometry.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POLYGON((0 0, 10 0, 10 6, 0 6, 0 0))")
                     .expect("Invalid geometry");
assert_eq!(geom1.area(), Ok(60.));
source

fn to_wkt(&self) -> GResult<String>

Returns a WKT representation of the geometry. It defaults to 2 dimensions output. Use WKTWriter type directly if you want more control.

§Examples
use geos::{Geom, Geometry, OutputDimension, WKTWriter};

let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)")
                          .expect("Invalid geometry");
assert_eq!(
    point_geom.to_wkt().unwrap(),
    "POINT (2.5000000000000000 2.5000000000000000)",
);

// A three dimension point will be output just as a 2 dimension:
let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5 3)")
                          .expect("Invalid geometry");
assert_eq!(
    point_geom.to_wkt().unwrap(),
    "POINT (2.5000000000000000 2.5000000000000000)",
);

// To "fix" it, use `WKTWriter` instead:
let mut wkt_writer = WKTWriter::new()
                               .expect("Failed to create WKTWriter");
wkt_writer.set_output_dimension(OutputDimension::ThreeD);
assert_eq!(
    wkt_writer.write(&point_geom).unwrap(),
    "POINT Z (2.5000000000000000 2.5000000000000000 3.0000000000000000)",
);
source

fn to_wkt_precision(&self, precision: u32) -> GResult<String>

Returns a WKT representation of the geometry with the given precision. It is a wrapper around WKTWriter::set_rounding_precision.

§Example
use geos::{Geom, Geometry, WKTWriter};

let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
assert_eq!(point_geom.to_wkt_precision(2).unwrap(), "POINT (2.50 2.50)");

// It is a wrapper around:
let mut writer = WKTWriter::new().expect("Failed to create WKTWriter");
writer.set_rounding_precision(2);
assert_eq!(writer.write(&point_geom).unwrap(), "POINT (2.50 2.50)");
source

fn is_ring(&self) -> GResult<bool>

Returns true if the geometry is a ring.

§Example
use geos::{Geom, Geometry};

let circle = Geometry::new_from_wkt("LINESTRING(0 0, 0 1, 1 1, 0 0)").expect("Invalid geometry");
assert_eq!(circle.is_ring(), Ok(true));
source

fn intersects<G: Geom>(&self, other: &G) -> GResult<bool>

Returns true if self shares any portion of space with other. So if any of this is true:

  • self overlaps other
  • self touches other
  • self is within other

Then intersects will return true as well.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT(0 0)").expect("invalid geometry");
let geom2 = Geometry::new_from_wkt("LINESTRING(2 0, 0 2)").expect("invalid geometry");
let geom3 = Geometry::new_from_wkt("LINESTRING(0 0, 0 2)").expect("invalid geometry");

assert_eq!(geom1.intersects(&geom2), Ok(false));
assert_eq!(geom1.intersects(&geom3), Ok(true));
source

fn crosses<G: Geom>(&self, other: &G) -> GResult<bool>

Returns true if self and other have at least one interior into each other.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("LINESTRING(1 1,2 2)").expect("invalid geometry");
let geom2 = Geometry::new_from_wkt("LINESTRING(2 1,1 2)").expect("invalid geometry");

assert_eq!(geom1.crosses(&geom2), Ok(true));
source

fn disjoint<G: Geom>(&self, other: &G) -> GResult<bool>

Returns true if self doesn’t:

  • Overlap other
  • Touch other
  • Is within other
§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT(0 0)").expect("invalid geometry");
let geom2 = Geometry::new_from_wkt("LINESTRING(2 0, 0 2)").expect("invalid geometry");
let geom3 = Geometry::new_from_wkt("LINESTRING(0 0, 0 2)").expect("invalid geometry");

assert_eq!(geom1.disjoint(&geom2), Ok(true));
assert_eq!(geom1.disjoint(&geom3), Ok(false));
source

fn touches<G: Geom>(&self, other: &G) -> GResult<bool>

Returns true if the only points in common between self and other lie in the union of the boundaries of self and other.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("LINESTRING(0 0, 1 1, 0 2)").expect("invalid geometry");
let geom2 = Geometry::new_from_wkt("POINT(1 1)").expect("invalid geometry");

assert_eq!(geom1.touches(&geom2), Ok(false));

let geom2 = Geometry::new_from_wkt("POINT(0 2)").expect("invalid geometry");

assert_eq!(geom1.touches(&geom2), Ok(true));
source

fn overlaps<G: Geom>(&self, other: &G) -> GResult<bool>

Returns true if self spatially overlaps other.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT(1 0.5)").expect("invalid geometry");
let geom2 = Geometry::new_from_wkt("LINESTRING(1 0, 1 1, 3 5)").expect("invalid geometry");

assert_eq!(geom1.overlaps(&geom2), Ok(false));

let geom1 = geom1.buffer(3., 8).expect("buffer failed");
let geom2 = geom2.buffer(0.5, 8).expect("buffer failed");

assert_eq!(geom1.overlaps(&geom2), Ok(true));
source

fn within<G: Geom>(&self, other: &G) -> GResult<bool>

Returns true if self is completely inside other.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POINT(50 50)").expect("invalid geometry");
let small_geom = geom.buffer(20., 8).expect("buffer failed");
let big_geom = geom.buffer(40., 8).expect("buffer failed");

assert_eq!(small_geom.within(&small_geom), Ok(true));
assert_eq!(small_geom.within(&big_geom), Ok(true));
assert_eq!(big_geom.within(&small_geom), Ok(false));
source

fn equals<G: Geom>(&self, other: &G) -> GResult<bool>

Checks if the two Geometry objects are equal.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("POINT (3.8 3.8)").expect("Invalid geometry");
let geom3 = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");

assert!(geom1.equals(&geom2) == Ok(false));
assert!(geom1.equals(&geom3) == Ok(true));

Note that you can also use method through the PartialEq trait:

use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("POINT (3.8 3.8)").expect("Invalid geometry");
let geom3 = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");

assert!(geom1 != geom2);
assert!(geom1 == geom3);
source

fn equals_exact<G: Geom>(&self, other: &G, precision: f64) -> GResult<bool>

Checks if the two Geometry objects are exactly equal.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("POINT (3.8 3.8)").expect("Invalid geometry");
let geom3 = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");

assert_eq!(geom1.equals_exact(&geom2, 0.1), Ok(false));
assert_eq!(geom1.equals_exact(&geom3, 0.1), Ok(true));
source

fn covers<G: Geom>(&self, other: &G) -> GResult<bool>

Returns true if no point of other is outside of self.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POINT (1 2)").expect("Invalid geometry");
let little_geom = geom.buffer(10., 8).expect("buffer failed");
let big_geom = geom.buffer(20., 8).expect("buffer failed");

assert_eq!(little_geom.covers(&big_geom), Ok(false));
assert_eq!(big_geom.covers(&little_geom), Ok(true));
source

fn covered_by<G: Geom>(&self, other: &G) -> GResult<bool>

Returns true if no point of self is outside of other.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POINT (1 2)").expect("Invalid geometry");
let little_geom = geom.buffer(10., 8).expect("buffer failed");
let big_geom = geom.buffer(20., 8).expect("buffer failed");

assert_eq!(little_geom.covered_by(&big_geom), Ok(true));
assert_eq!(big_geom.covered_by(&little_geom), Ok(false));
source

fn contains<G: Geom>(&self, other: &G) -> GResult<bool>

Returns true if no points of the other geometry is outside the exterior of self.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POLYGON((0 0, 10 0, 10 6, 0 6, 0 0))").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");

assert_eq!(geom1.contains(&geom2), Ok(true));
source

fn buffer(&self, width: f64, quadsegs: i32) -> GResult<Geometry>

Returns a geometry which represents all points whose distance from self is less than or equal to distance.

You can find nice examples about this in postgis documentation.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POINT(1 3)").expect("Invalid geometry");
let buffer_geom = geom.buffer(50., 2).expect("buffer failed");

assert_eq!(buffer_geom.to_wkt_precision(1).unwrap(),
           "POLYGON ((51.0 3.0, 36.4 -32.4, 1.0 -47.0, -34.4 -32.4, -49.0 3.0, -34.4 38.4, \
                      1.0 53.0, 36.4 38.4, 51.0 3.0))");
source

fn buffer_with_params( &self, width: f64, buffer_params: &BufferParams ) -> GResult<Geometry>

Returns a geometry which represents all points whose distance from self is less than or equal to distance.

The explicit buffer_params argument passing is more efficient than the otherwise identical (except for the single_sided option is missing) buffer_with_style method when the same BufferParams is reused.

You can find nice examples and details about the BufferParams options in this postgis documentation.

§Example
use geos::{BufferParams, CapStyle, Geom, Geometry, JoinStyle};

let geom = Geometry::new_from_wkt("POINT(1 3)").expect("Invalid geometry");
let params = BufferParams::builder()
    .end_cap_style(CapStyle::Round)
    .join_style(JoinStyle::Round)
    .mitre_limit(5.0)
    .quadrant_segments(8)
    .single_sided(false)
    .build()
    .expect("build BufferParams");
let buffer_geom = geom.buffer_with_params(2., &params).expect("buffer_with_params failed");

assert_eq!(buffer_geom.to_wkt_precision(1).unwrap(),
           "POLYGON ((3.0 3.0, 3.0 2.6, 2.8 2.2, 2.7 1.9, 2.4 1.6, 2.1 1.3, 1.8 1.2, 1.4 1.0, \
             1.0 1.0, 0.6 1.0, 0.2 1.2, -0.1 1.3, -0.4 1.6, -0.7 1.9, -0.8 2.2, -1.0 2.6, \
             -1.0 3.0, -1.0 3.4, -0.8 3.8, -0.7 4.1, -0.4 4.4, -0.1 4.7, 0.2 4.8, 0.6 5.0, \
             1.0 5.0, 1.4 5.0, 1.8 4.8, 2.1 4.7, 2.4 4.4, 2.7 4.1, 2.8 3.8, 3.0 3.4, \
             3.0 3.0))");
source

fn buffer_with_style( &self, width: f64, quadsegs: i32, end_cap_style: CapStyle, join_style: JoinStyle, mitre_limit: f64 ) -> GResult<Geometry>

Returns a geometry which represents all points whose distance from self is less than or equal to distance.

If the same paramters are used many times it’s more efficient to use the buffer_with_params operation.

You can find nice examples and details about the options in this postgis documentation.

§Example
use geos::{CapStyle, Geom, Geometry, JoinStyle};

let geom = Geometry::new_from_wkt("POINT(1 3)").expect("Invalid geometry");
let buffer_geom = geom.buffer_with_style(
    2., 8, CapStyle::Round, JoinStyle::Round, 5.
).expect("buffer_with_style failed");

assert_eq!(buffer_geom.to_wkt_precision(1).unwrap(),
           "POLYGON ((3.0 3.0, 3.0 2.6, 2.8 2.2, 2.7 1.9, 2.4 1.6, 2.1 1.3, 1.8 1.2, \
            1.4 1.0, 1.0 1.0, 0.6 1.0, 0.2 1.2, -0.1 1.3, -0.4 1.6, -0.7 1.9, -0.8 2.2, \
            -1.0 2.6, -1.0 3.0, -1.0 3.4, -0.8 3.8, -0.7 4.1, -0.4 4.4, -0.1 4.7, 0.2 4.8, \
            0.6 5.0, 1.0 5.0, 1.4 5.0, 1.8 4.8, 2.1 4.7, 2.4 4.4, 2.7 4.1, 2.8 3.8, \
            3.0 3.4, 3.0 3.0))");
source

fn is_empty(&self) -> GResult<bool>

Returns true if the given geometry is empty.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::create_empty_polygon().expect("Invalid geometry");
assert_eq!(geom.is_empty(), Ok(true));

let geom = Geometry::new_from_wkt("POLYGON EMPTY").expect("Invalid geometry");
assert_eq!(geom.is_empty(), Ok(true));

let geom = Geometry::new_from_wkt("POINT(1 3)").expect("Invalid geometry");
assert_eq!(geom.is_empty(), Ok(false));
source

fn is_simple(&self) -> GResult<bool>

Returns true if the given geometry has no anomalous geometric points, such as self intersection or self tangency.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POINT (2.5 2.5)")
                    .expect("Invalid geometry");
assert_eq!(geom.is_simple(), Ok(true));

let geom = Geometry::new_from_wkt("LINESTRING(1 1,2 2,2 3.5,1 3,1 2,2 1)")
                    .expect("Invalid geometry");
assert_eq!(geom.is_simple(), Ok(false));
source

fn difference<G: Geom>(&self, other: &G) -> GResult<Geometry>

Returns a geometry which represents part of self that doesn’t intersect with other.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("LINESTRING(50 100, 50 200)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("LINESTRING(50 50, 50 150)").expect("Invalid geometry");

let difference_geom = geom1.difference(&geom2).expect("envelope failed");

assert_eq!(difference_geom.to_wkt_precision(1).unwrap(),
           "LINESTRING (50.0 150.0, 50.0 200.0)");
source

fn envelope(&self) -> GResult<Geometry>

Returns the minimum bouding box of the given geometry.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POINT(1 3)").expect("Invalid geometry");
let envelope_geom = geom.envelope().expect("envelope failed");

assert_eq!(envelope_geom.to_wkt_precision(1).unwrap(), "POINT (1.0 3.0)");

let geom = Geometry::new_from_wkt("LINESTRING(0 0, 1 3)").expect("Invalid geometry");
let envelope_geom = geom.envelope().expect("envelope failed");

assert_eq!(envelope_geom.to_wkt_precision(1).unwrap(),
           "POLYGON ((0.0 0.0, 1.0 0.0, 1.0 3.0, 0.0 3.0, 0.0 0.0))");
source

fn sym_difference<G: Geom>(&self, other: &G) -> GResult<Geometry>

Returns a geometry which represents the parts of self and other that don’t intersect.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("LINESTRING(50 100, 50 200)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("LINESTRING(50 50, 50 150)").expect("Invalid geometry");

let sym_diff_geom = geom1.sym_difference(&geom2).expect("sym_difference failed");

assert_eq!(
    sym_diff_geom.to_wkt_precision(1).unwrap(),
    "MULTILINESTRING ((50.0 150.0, 50.0 200.0), (50.0 50.0, 50.0 100.0))",
);
source

fn union<G: Geom>(&self, other: &G) -> GResult<Geometry>

Aggregates the given geometry with another one.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT(1 2)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("POINT(3 4)").expect("Invalid geometry");

let union_geom = geom1.union(&geom2).expect("union failed");

assert_eq!(union_geom.to_wkt_precision(1).unwrap(), "MULTIPOINT (1.0 2.0, 3.0 4.0)");
source

fn get_centroid(&self) -> GResult<Geometry>

Returns the geometric center or (equivalently) the center of mass of the given geometry as a point.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("MULTIPOINT(-1 0, -1 2, -1 3, -1 4, -1 7, 0 1, 0 3, 1 1)")
                    .expect("Invalid geometry");
let centroid = geom.get_centroid().expect("failed to get centroid");

assert_eq!(centroid.to_wkt_precision(1).unwrap(), "POINT (-0.5 2.6)");
source

fn unary_union(&self) -> GResult<Geometry>

Documentation from postgis:

Unlike ST_Union, ST_UnaryUnion does dissolve boundaries between components of a multipolygon (invalid) and does perform union between the components of a geometrycollection. Each components of the input geometry is assumed to be valid, so you won’t get a valid multipolygon out of a bow-tie polygon (invalid).

You may use this function to node a set of linestrings. You may mix ST_UnaryUnion with ST_Collect to fine-tune how many geometries at once you want to dissolve to be nice on both memory size and CPU time, finding the balance between ST_Union and ST_MemUnion.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POLYGON((0 0, 10 0, 10 6, 0 6, 0 0))")
                     .expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("POLYGON((1 1, 2 1, 2 5, 1 5, 1 1))")
                     .expect("Invalid geometry");

let geom = Geometry::create_multipolygon(vec![geom1, geom2])
                    .expect("Failed to build multipolygon");

let mut union_geom = geom.unary_union().expect("unary_union failed");
union_geom.normalize().expect("normalize failed");

assert_eq!(
    union_geom.to_wkt_precision(1).unwrap(),
    "POLYGON ((0.0 0.0, 0.0 6.0, 10.0 6.0, 10.0 0.0, 0.0 0.0))",
);
source

fn voronoi<G: Geom>( &self, envelope: Option<&G>, tolerance: f64, only_edges: bool ) -> GResult<Geometry>

Create a voronoi diagram.

§Example
use geos::{Geom, Geometry};

let input = Geometry::new_from_wkt("MULTIPOINT(2 2, 4 2)")
                  .expect("Invalid geometry");
let mut expected = Geometry::new_from_wkt(
    "GEOMETRYCOLLECTION (POLYGON ((0 0, 0 4, 3 4, 3 0, 0 0)), POLYGON ((6 4, 6 0, 3 0, 3 4, 6 4)))")
    .expect("Invalid geometry");

let mut voronoi = input.voronoi(None::<&Geometry>, 0., false)
                       .expect("voronoi failed");

expected.normalize().expect("normalize failed");
voronoi.normalize().expect("normalize failed");

assert_eq!(expected.equals(&voronoi), Ok(true));
source

fn intersection<G: Geom>(&self, other: &G) -> GResult<Geometry>

Returns a geometry representing the intersection between self and other.

§Example
use geos::{Geom, Geometry};

let mut geom1 = Geometry::new_from_wkt("POINT(0 0)").expect("Invalid geometry");
let mut geom2 = Geometry::new_from_wkt("LINESTRING(2 0, 0 2)").expect("Invalid geometry");

let intersection_geom = geom1.intersection(&geom2).expect("intersection failed");

// No intersection.
assert_eq!(intersection_geom.is_empty(), Ok(true));

// We slighty change the linestring so we have an intersection:
let mut geom2 = Geometry::new_from_wkt("LINESTRING(0 0, 0 2)").expect("Invalid geometry");

let intersection_geom = geom1.intersection(&geom2).expect("intersection failed");

// Intersection!
assert_eq!(intersection_geom.to_wkt_precision(1).unwrap(), "POINT (0.0 0.0)");
source

fn convex_hull(&self) -> GResult<Geometry>

Documentation from postgis:

The convex hull of a geometry represents the minimum convex geometry that encloses all geometries within the set.

One can think of the convex hull as the geometry you get by wrapping an elastic band around a set of geometries. This is different from a concave hull which is analogous to shrink-wrapping your geometries.

It is usually used with MULTI and Geometry Collections. Although it is not an aggregate - you can use it in conjunction with ST_Collect to get the convex hull of a set of points. ST_ConvexHull(ST_Collect(somepointfield)).

It is often used to determine an affected area based on a set of point observations.

§Example
use geos::{Geom, Geometry};

let mut geom1 = Geometry::new_from_wkt("MULTILINESTRING((100 190,10 8),
                                                        (150 10, 20 30))")
                         .expect("Invalid geometry");
let mut geom2 = Geometry::new_from_wkt("MULTIPOINT(50 5, 150 30, 50 10, 10 10)")
                         .expect("Invalid geometry");

let geom = geom1.union(&geom2).expect("union failed");
let convex_hull_geom = geom.convex_hull().expect("convex_hull failed");

assert_eq!(convex_hull_geom.to_wkt_precision(1).unwrap(),
           "POLYGON ((50.0 5.0, 10.0 8.0, 10.0 10.0, 100.0 190.0, 150.0 30.0, 150.0 10.0, 50.0 5.0))");
source

fn boundary(&self) -> GResult<Geometry>

Returns the closure of the combinatorial boundary of self.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("LINESTRING(1 1,0 0, -1 1)").expect("Invalid geometry");
let boundary_geom = geom.boundary().expect("boundary failed");

assert_eq!(boundary_geom.to_wkt_precision(1).unwrap(), "MULTIPOINT (1.0 1.0, -1.0 1.0)");
source

fn has_z(&self) -> GResult<bool>

Returns true if self has a Z coordinate.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POINT(1 2 3)").expect("Invalid geometry");
assert_eq!(geom.has_z(), Ok(true));

let geom = Geometry::new_from_wkt("POINT(1 2)").expect("Invalid geometry");
assert_eq!(geom.has_z(), Ok(false));
source

fn is_closed(&self) -> GResult<bool>

Returns true if start and end point are coincident.

Only works on LineString and MultiLineString.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("LINESTRING(0 0, 1 1)").expect("Invalid geometry");
assert_eq!(geom.is_closed(), Ok(false));

let geom = Geometry::new_from_wkt("LINESTRING(0 0, 0 1, 1 1, 0 0)").expect("Invalid geometry");
assert_eq!(geom.is_closed(), Ok(true));

let geom = Geometry::new_from_wkt("MULTILINESTRING((0 0, 0 1, 1 1, 0 0),(0 0, 1 1))")
                    .expect("Invalid geometry");
assert_eq!(geom.is_closed(), Ok(false));
source

fn length(&self) -> GResult<f64>

Returns the length of self. The unit depends of the SRID.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("LINESTRING(743238 2967416,743238 2967450)")
                    .expect("Invalid geometry");

assert_eq!(
    geom.length().map(|x| format!("{:.2}", x)).unwrap(),
    "34.00",
);
source

fn distance<G: Geom>(&self, other: &G) -> GResult<f64>

Returns the distance between self and other. The unit depends of the SRID.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT (1 2)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("POINT (2 2)").expect("Invalid geometry");

assert_eq!(geom1.distance(&geom2).map(|x| format!("{:.2}", x)).unwrap(), "1.00");
source

fn distance_indexed<G: Geom>(&self, other: &G) -> GResult<f64>

Returns the indexed distance between self and other. The unit depends of the SRID.

Available using the v3_7_0 feature.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT (1 2)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("POINT (2 2)").expect("Invalid geometry");

assert_eq!(geom1.distance_indexed(&geom2).map(|x| format!("{:.2}", x)).unwrap(), "1.00");
source

fn hausdorff_distance<G: Geom>(&self, other: &G) -> GResult<f64>

Returns the hausdorff distance between self and other. The unit depends of the SRID.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT (1 2)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("POINT (2 2)").expect("Invalid geometry");

assert_eq!(geom1.hausdorff_distance(&geom2).map(|x| format!("{:.2}", x)).unwrap(), "1.00");
source

fn hausdorff_distance_densify<G: Geom>( &self, other: &G, distance_frac: f64 ) -> GResult<f64>

Returns the hausdorff distance between self and other. The unit depends of the SRID.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT (1 2)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("POINT (2 2)").expect("Invalid geometry");

assert_eq!(geom1.hausdorff_distance_densify(&geom2, 1.).map(|x| format!("{:.2}", x))
                                                       .unwrap(), "1.00");
source

fn frechet_distance<G: Geom>(&self, other: &G) -> GResult<f64>

Returns the frechet distance between self and other. The unit depends of the SRID.

Available using the v3_7_0 feature.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("LINESTRING (0 0, 100 0)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("LINESTRING (0 0, 50 50, 100 0)").expect("Invalid geometry");

assert_eq!(geom1.frechet_distance(&geom2).map(|x| format!("{:.2}", x)).unwrap(), "70.71");
source

fn frechet_distance_densify<G: Geom>( &self, other: &G, distance_frac: f64 ) -> GResult<f64>

Returns the frechet distance between self and other. The unit depends of the SRID.

Available using the v3_7_0 feature.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("LINESTRING (0 0, 100 0)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("LINESTRING (0 0, 50 50, 100 0)").expect("Invalid geometry");

assert_eq!(geom1.frechet_distance_densify(&geom2, 1.).map(|x| format!("{:.2}", x))
                                                     .unwrap(), "70.71");
source

fn get_length(&self) -> GResult<f64>

Returns the length of the given geometry.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("LINESTRING (1 2, 3 4, 5 6)")
                    .expect("Invalid geometry");

assert_eq!(geom.get_length().map(|x| format!("{:.2}", x)).unwrap(), "5.66");
source

fn snap<G: Geom>(&self, other: &G, tolerance: f64) -> GResult<Geometry>

Documentation from postgis:

Snaps the vertices and segments of a geometry another Geometry’s vertices. A snap distance tolerance is used to control where snapping is performed. The result geometry is the input geometry with the vertices snapped. If no snapping occurs then the input geometry is returned unchanged.

Snapping one geometry to another can improve robustness for overlay operations by eliminating nearly-coincident edges (which cause problems during noding and intersection calculation).

Too much snapping can result in invalid topology being created, so the number and location of snapped vertices is decided using heuristics to determine when it is safe to snap. This can result in some potential snaps being omitted, however.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("MULTIPOLYGON(((26 125, 26 200, 126 200, 126 125, 26 125),
                                                  (51 150, 101 150, 76 175, 51 150)),
                                                 ((151 100, 151 200, 176 175, 151 100)))")
                     .expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("LINESTRING(5 107, 54 84, 101 100)")
                     .expect("Invalid geometry");

let distance = geom1.distance(&geom2).expect("distance failed");
let snap_geom = geom1.snap(&geom2, distance * 1.25).expect("snap failed");

assert_eq!(snap_geom.to_wkt_precision(1).unwrap(),
           "MULTIPOLYGON (((5.0 107.0, 26.0 200.0, 126.0 200.0, 126.0 125.0, 101.0 100.0, 54.0 84.0, 5.0 107.0), \
                           (51.0 150.0, 101.0 150.0, 76.0 175.0, 51.0 150.0)), \
                          ((151.0 100.0, 151.0 200.0, 176.0 175.0, 151.0 100.0)))");
source

fn extract_unique_points(&self) -> GResult<Geometry>

Returns unique points of self.

source

fn nearest_points<G: Geom>(&self, other: &G) -> GResult<CoordSeq>

source

fn get_x(&self) -> GResult<f64>

Returns the X position. The given Geometry must be a Point, otherwise it’ll fail.

§Example
use geos::{Geom, Geometry};

let point_geom = Geometry::new_from_wkt("POINT (1.5 2.5 3.5)").expect("Invalid geometry");
assert!(point_geom.get_x() == Ok(1.5));
source

fn get_y(&self) -> GResult<f64>

Returns the Y position. The given Geometry must be a Point, otherwise it’ll fail.

§Example
use geos::{Geom, Geometry};

let point_geom = Geometry::new_from_wkt("POINT (1.5 2.5 3.5)").expect("Invalid geometry");
assert!(point_geom.get_y() == Ok(2.5));
source

fn get_z(&self) -> GResult<f64>

Returns the Z position. The given Geometry must be a Point, otherwise it’ll fail.

Available using the v3_7_0 feature.

§Example
use geos::{Geom, Geometry};

let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5 4.0)").expect("Invalid geometry");
assert!(point_geom.get_z() == Ok(4.0));
source

fn get_point_n(&self, n: usize) -> GResult<Geometry>

Returns the nth point of the given geometry.

The given Geometry must be a LineString, otherwise it’ll fail.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("LINESTRING (1 2, 3 4, 5 6)")
                    .expect("Invalid geometry");
let nth_point = geom.get_point_n(1).expect("get_point_n failed");

assert_eq!(nth_point.to_wkt_precision(1).unwrap(), "POINT (3.0 4.0)");
source

fn get_start_point(&self) -> GResult<Geometry>

Returns the start point of self.

The given Geometry must be a LineString, otherwise it’ll fail.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("LINESTRING (1 2, 3 4)")
                    .expect("Invalid geometry");
let start_point = geom.get_start_point().expect("get_start_point failed");

assert_eq!(start_point.to_wkt_precision(1).unwrap(), "POINT (1.0 2.0)");
source

fn get_end_point(&self) -> GResult<Geometry>

Returns the end point of self.

The given Geometry must be a LineString, otherwise it’ll fail.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("LINESTRING (1 2, 3 4)")
                    .expect("Invalid geometry");
let end_point = geom.get_end_point().expect("get_end_point failed");

assert_eq!(end_point.to_wkt_precision(1).unwrap(), "POINT (3.0 4.0)");
source

fn get_num_points(&self) -> GResult<usize>

Returns the number of points of self.

The given Geometry must be a LineString, otherwise it’ll fail.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("LINESTRING (1 2, 3 4)")
                    .expect("Invalid geometry");

assert_eq!(geom.get_num_points(), Ok(2));
source

fn get_num_interior_rings(&self) -> GResult<usize>

Returns the number of interior rings.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POLYGON((0 0, 10 0, 10 6, 0 6, 0 0),\
                                           (1 1, 2 1, 2 5, 1 5, 1 1),\
                                           (8 5, 8 4, 9 4, 9 5, 8 5))")
                    .expect("Invalid geometry");

assert_eq!(geom.get_num_interior_rings(), Ok(2));
source

fn get_num_coordinates(&self) -> GResult<usize>

Returns the number of coordinates inside self.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POLYGON((0 0, 10 0, 10 6, 0 6, 0 0))")
                    .expect("Invalid geometry");

assert_eq!(geom.get_num_coordinates(), Ok(5));
source

fn get_num_dimensions(&self) -> GResult<usize>

Returns the number of dimensions used in self.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POLYGON((0 0, 10 0, 10 6, 0 6, 0 0))")
                    .expect("Invalid geometry");

assert_eq!(geom.get_num_dimensions(), Ok(2));
source

fn get_coordinate_dimension(&self) -> GResult<Dimensions>

Return in which coordinate dimension the geometry is.

§Example
use geos::{Dimensions, Geom, Geometry};

let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5 4.0)").expect("Invalid geometry");
assert!(point_geom.get_coordinate_dimension() == Ok(Dimensions::ThreeD));

let point_geom = Geometry::new_from_wkt("POINT (2.5 4.0)").expect("Invalid geometry");
assert!(point_geom.get_coordinate_dimension() == Ok(Dimensions::TwoD));
source

fn make_valid(&self) -> GResult<Geometry>

This functions attempts to return a valid representation of self.

Available using the v3_8_0 feature.

source

fn get_num_geometries(&self) -> GResult<usize>

Returns the number of geometries.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)")
                    .expect("Invalid geometry");
assert_eq!(geom.get_num_geometries(), Ok(1));

let geom = Geometry::new_from_wkt("GEOMETRYCOLLECTION(MULTIPOINT(-2 3 , -2 2),\
                                                      LINESTRING(5 5 ,10 10),\
                                                      POLYGON((-7 4.2,-7.1 5,-7.1 4.3,-7 4.2)))")
                    .expect("Invalid geometry");
assert_eq!(geom.get_num_geometries(), Ok(3));
source

fn get_srid(&self) -> GResult<usize>

Get SRID of self.

§Example
use geos::{Geom, Geometry};

let mut point_geom = Geometry::new_from_wkt("POINT (2.5 2.5 4.0)")
                              .expect("Invalid geometry");
point_geom.set_srid(4326);
assert_eq!(point_geom.get_srid(), Ok(4326));
source

fn get_precision(&self) -> GResult<f64>

Returns the precision of self.

Available using the v3_6_0 feature.

§Example
use geos::{Geom, Geometry};

let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5 4.0)").expect("Invalid geometry");
assert_eq!(point_geom.get_precision().map(|x| format!("{:.2}", x)).unwrap(), "0.00");
source

fn set_precision(&self, grid_size: f64, flags: Precision) -> GResult<Geometry>

Returns the precision of self.

Available using the v3_6_0 feature.

§Example
use geos::{Geom, Geometry, Precision};

let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5 4.0)").expect("Invalid geometry");

point_geom.set_precision(1., Precision::KeepCollapsed);
assert_eq!(point_geom.get_precision().map(|x| format!("{:.2}", x)).unwrap(), "0.00");
source

fn get_x_max(&self) -> GResult<f64>

Returns the biggest X of the geometry.

Available using the v3_7_0 feature.

§Example
use geos::{Geom, Geometry};

let line = Geometry::new_from_wkt("LINESTRING(1 3 4, 5 6 7)").expect("Invalid WKT");
assert_eq!(line.get_x_max(), Ok(5.));
source

fn get_x_min(&self) -> GResult<f64>

Returns the smallest X of the geometry.

Available using the v3_7_0 feature.

§Example
use geos::{Geom, Geometry};

let line = Geometry::new_from_wkt("LINESTRING(1 3 4, 5 6 7)").expect("Invalid WKT");
assert_eq!(line.get_x_min(), Ok(1.));
source

fn get_y_max(&self) -> GResult<f64>

Returns the biggest Y of the geometry.

Available using the v3_7_0 feature.

§Example
use geos::{Geom, Geometry};

let line = Geometry::new_from_wkt("LINESTRING(1 3 4, 5 6 7)").expect("Invalid WKT");
assert_eq!(line.get_y_max(), Ok(6.));
source

fn get_y_min(&self) -> GResult<f64>

Returns the smallest Y of the geometry.

Available using the v3_7_0 feature.

§Example
use geos::{Geom, Geometry};

let line = Geometry::new_from_wkt("LINESTRING(1 3 4, 5 6 7)").expect("Invalid WKT");
assert_eq!(line.get_y_min(), Ok(3.));
source

fn minimum_clearance(&self) -> GResult<f64>

Returns the smallest distance by which a vertex of self could be moved to produce an invalid geometry.

Available using the v3_6_0 feature.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("LINESTRING(1 3 4, 5 6 7)").expect("Invalid WKT");
assert_eq!(geom.minimum_clearance().map(|x| format!("{:.8}", x)).unwrap(), "5.00000000");
source

fn minimum_clearance_line(&self) -> GResult<Geometry>

Returns the two-point LineString spanning of self’s minimum clearance.

Available using the v3_6_0 feature.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POLYGON ((0 0, 1 0, 1 1, 0.5 3.2e-4, 0 0))")
                    .expect("Invalid WKT");
let line = geom.minimum_clearance_line().expect("minimum_clearance_line failed");
assert_eq!(line.to_wkt_precision(1).unwrap(), "LINESTRING (0.5 0.0, 0.5 0.0)");
source

fn minimum_rotated_rectangle(&self) -> GResult<Geometry>

Returns the minimum rotated rectangle inside of self.

Available using the v3_6_0 feature.

source

fn minimum_width(&self) -> GResult<Geometry>

Returns the minimum width inside of self.

Available using the v3_6_0 feature.

source

fn delaunay_triangulation( &self, tolerance: f64, only_edges: bool ) -> GResult<Geometry>

Returns a delaunay triangulation around the vertices of self.

§Example
use geos::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POLYGON((175 150, 20 40, 50 60, 125 100, 175 150))")
                     .expect("Invalid WKT");
let geom2 = Geometry::new_from_wkt("POINT(110 170)").expect("Invalid WKT");
let geom2 = geom2.buffer(20., 8).expect("buffer failed");

let geom = geom1.union(&geom2).expect("union failed");

let final_geom = geom.delaunay_triangulation(0.001, false).expect("delaunay_triangulation failed");
source

fn interpolate(&self, d: f64) -> GResult<Geometry>

source

fn interpolate_normalized(&self, d: f64) -> GResult<Geometry>

source

fn project<G: Geom>(&self, p: &G) -> GResult<f64>

source

fn project_normalized<G: Geom>(&self, p: &G) -> GResult<f64>

source

fn node(&self) -> GResult<Geometry>

source

fn offset_curve( &self, width: f64, quadrant_segments: i32, join_style: JoinStyle, mitre_limit: f64 ) -> GResult<Geometry>

Return an offset line at a given distance and side from an input line. All points of the returned geometries are not further than the given distance from the input geometry.

§Parameters description:
§width
  • If width is positive, the offset will be at the left side of the input line and retain the same direction.
  • If width is negative, it’ll be at the right side and in the opposite direction.
§quadrant_segments
  • If quadrant_segments is >= 1, joins are round, and quadrant_segments indicates the number of segments to use to approximate a quarter-circle.
  • If quadrant_segments == 0, joins are bevelled (flat).
  • If quadrant_segments < 0, joins are mitred, and the value of quadrant_segments indicates the mitre ration limit as mitre_limit = |quadrant_segments|
§mitre_limit

The mitre ratio is the ratio of the distance from the corner to the end of the mitred offset corner. When two line segments meet at a sharp angle, a miter join will extend far beyond the original geometry (and in the extreme case will be infinitely far). To prevent unreasonable geometry, the mitre limit allows controlling the maximum length of the join corner. Corners with a ratio which exceed the limit will be beveled.

source

fn point_on_surface(&self) -> GResult<Geometry>

source

fn polygonize_full( &self ) -> GResult<(Geometry, Option<Geometry>, Option<Geometry>, Option<Geometry>)>

Returns, in the tuple elements order:

  1. The polygonized geometry.
  2. The cuts geometries collection.
  3. The dangles geometries collection.
  4. The invalid geometries collection.
source

fn shared_paths<G: Geom>(&self, other: &G) -> GResult<Geometry>

source

fn to_hex(&self) -> GResult<CVec<u8>>

Converts a Geometry to the HEX format. For more control over the generated output, use the WKBWriter type.

§Example
use geos::{Geom, Geometry};

let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)")
                          .expect("Invalid geometry");
let hex_buf = point_geom.to_hex().expect("conversion to WKB failed");
source

fn to_wkb(&self) -> GResult<CVec<u8>>

Converts a Geometry to the WKB format. For more control over the generated output, use the WKBWriter type.

§Example
use geos::{Geom, Geometry};

let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)")
                          .expect("Invalid geometry");
let wkb_buf = point_geom.to_wkb().expect("conversion to WKB failed");
source

fn to_prepared_geom<'c>(&'c self) -> GResult<PreparedGeometry>

Creates a new PreparedGeometry from the current Geometry.

§Example
use geos::{Geom, Geometry};

let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)")
                          .expect("Invalid geometry");
let prepared_geom = point_geom.to_prepared_geom().expect("failed to create prepared geom");
source

fn clone(&self) -> Geometry

Also passes the context to the newly created Geometry.

source

fn get_geometry_n(&self, n: usize) -> GResult<ConstGeometry<'_>>

Returns the 1-based nth geometry.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("MULTIPOINT(1 1, 2 2, 3 3, 4 4)")
                    .expect("Invalid geometry");
let point_nb3 = geom
    .get_geometry_n(2)
    .expect("failed to get third point");
assert_eq!(
    point_nb3.to_wkt().unwrap(),
    "POINT (3.0000000000000000 3.0000000000000000)",
);
source

fn get_interior_ring_n(&self, n: u32) -> GResult<ConstGeometry<'_>>

Returns the nth interior ring.

§Example
use geos::{Geom, Geometry};

let geom = Geometry::new_from_wkt("POLYGON((0 0, 10 0, 10 6, 0 6, 0 0),\
                                           (1 1, 2 1, 2 5, 1 5, 1 1),\
                                           (8 5, 8 4, 9 4, 9 5, 8 5))")
                    .expect("Invalid geometry");
let interior = geom
    .get_interior_ring_n(0)
    .expect("failed to get interior ring");
assert_eq!(interior.to_wkt().unwrap(),
           "LINEARRING (1.0000000000000000 1.0000000000000000, \
                        2.0000000000000000 1.0000000000000000, \
                        2.0000000000000000 5.0000000000000000, \
                        1.0000000000000000 5.0000000000000000, \
                        1.0000000000000000 1.0000000000000000)");
source

fn get_exterior_ring(&self) -> GResult<ConstGeometry<'_>>

Returns the exterior ring.

§Example
use geos::{Geom, Geometry};

let point_geom = Geometry::new_from_wkt("POLYGON((0 0, 10 0, 10 6, 0 6, 0 0),\
                                              (1 1, 2 1, 2 5, 1 5, 1 1))")
                          .expect("Invalid geometry");

let exterior = point_geom
    .get_exterior_ring()
    .expect("failed to get exterior ring");
assert_eq!(exterior.to_wkt().unwrap(),
           "LINEARRING (0.0000000000000000 0.0000000000000000, \
                        10.0000000000000000 0.0000000000000000, \
                        10.0000000000000000 6.0000000000000000, \
                        0.0000000000000000 6.0000000000000000, \
                        0.0000000000000000 0.0000000000000000)");

Object Safety§

This trait is not object safe.

Implementors§