[][src]Struct geos::Geometry

pub struct Geometry<'a> { /* fields omitted */ }

Representation of a GEOS geometry.

Example

use geos::Geometry;

let point_geom = Geometry::new_from_wkt("POINT (2.5 3.5)").expect("Invalid geometry");
assert_eq!(point_geom.get_x(), Ok(2.5));
assert_eq!(point_geom.get_y(), Ok(3.5));

Methods

impl<'a> Geometry<'a>[src]

pub fn new_from_wkt(wkt: &str) -> GResult<Geometry<'a>>[src]

Creates a Geometry from the WKT format.

Example

use geos::Geometry;

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

pub fn new_from_hex(hex: &[u8]) -> GResult<Geometry<'a>>[src]

Create a new Geometry from the HEX format.

Example

use geos::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 HEX failed");

// The interesting part is here:
let new_geom = Geometry::new_from_hex(hex_buf.as_ref())
                     .expect("conversion from HEX failed");
assert_eq!(point_geom.equals(&new_geom), Ok(true));

pub fn new_from_wkb(wkb: &[u8]) -> GResult<Geometry<'a>>[src]

Create a new Geometry from the WKB format.

Example

use geos::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");

// The interesting part is here:
let new_geom = Geometry::new_from_wkb(wkb_buf.as_ref())
                     .expect("conversion from WKB failed");
assert_eq!(point_geom.equals(&new_geom), Ok(true));

pub fn to_hex(&self) -> GResult<CVec<u8>>[src]

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

Example

use geos::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");

pub fn to_wkb(&self) -> GResult<CVec<u8>>[src]

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

Example

use geos::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");

pub fn to_prepared_geom(&self) -> GResult<PreparedGeometry<'a>>[src]

Creates a new PreparedGeometry from the current Geometry.

Example

use geos::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");

pub fn build_area(&self) -> GResult<Geometry<'a>>[src]

Creates an areal geometry formed by the constituent linework of given geometry.

You can find new illustrations on postgis documentation.

Available using the v3_8_0 feature.

Example

use geos::Geometry;

let geom = Geometry::new_from_wkt("POINT(100 90)").expect("Invalid geometry");
let small_geom = geom.buffer(25., 8).expect("buffer failed");
let big_geom = geom.buffer(50., 8).expect("buffer failed");

let union_geom = small_geom.union(&big_geom).expect("union failed");
let build_area_geom = union_geom.build_area().expect("build_area failed");

// Looks like a donut.
assert_eq!(union_geom.to_wkt_precision(1).unwrap(),
           "POLYGON ((150.0 90.0, 149.0 80.2, 146.2 70.9, 141.6 62.2, 135.4 54.6, \
                      127.8 48.4, 119.1 43.8, 109.8 41.0, 100.0 40.0, 90.2 41.0, \
                      80.9 43.8, 72.2 48.4, 64.6 54.6, 58.4 62.2, 53.8 70.9, 51.0 80.2, \
                      50.0 90.0, 51.0 99.8, 53.8 109.1, 58.4 117.8, 64.6 125.4, \
                      72.2 131.6, 80.9 136.2, 90.2 139.0, 100.0 140.0, 109.8 139.0, \
                      119.1 136.2, 127.8 131.6, 135.4 125.4, 141.6 117.8, 146.2 109.1, \
                      149.0 99.8, 150.0 90.0))");

pub fn polygonize<T: Borrow<Geometry<'a>>>(
    geometries: &[T]
) -> GResult<Geometry<'a>>
[src]

Description from postgis:

Creates a GeometryCollection containing possible polygons formed from the constituent linework of a set of geometries.

Example:

use geos::Geometry;

let geom1 = Geometry::new_from_wkt("POLYGON((-71.040878 42.285678,\
                                             -71.040943 42.2856,\
                                             -71.04096 42.285752,\
                                             -71.040878 42.285678))")
                     .expect("Failed to create geometry");
let geom2 = Geometry::new_from_wkt("POLYGON((-71.17166 42.353675,\
                                             -71.172026 42.354044,\
                                             -71.17239 42.354358,\
                                             -71.171794 42.354971,\
                                             -71.170511 42.354855,\
                                             -71.17112 42.354238,\
                                             -71.17166 42.353675))")
                     .expect("Failed to create geometry");

let polygonized = Geometry::polygonize(&[geom1, geom2]).expect("polygonize failed");
assert_eq!(polygonized.to_wkt().unwrap(),
           "GEOMETRYCOLLECTION (POLYGON ((-71.0408780000000064 42.2856779999999972, \
                                          -71.0409429999999986 42.2856000000000023, \
                                          -71.0409599999999983 42.2857520000000022, \
                                          -71.0408780000000064 42.2856779999999972)), \
                                POLYGON ((-71.1716600000000028 42.3536750000000026, \
                                          -71.1720260000000025 42.3540440000000018, \
                                          -71.1723899999999929 42.3543579999999977, \
                                          -71.1717940000000056 42.3549709999999990, \
                                          -71.1705110000000047 42.3548550000000006, \
                                          -71.1711200000000019 42.3542380000000023, \
                                          -71.1716600000000028 42.3536750000000026)))");

pub fn polygonizer_get_cut_edges<T: Borrow<Geometry<'a>>>(
    &self,
    geometries: &[T]
) -> GResult<Geometry<'a>>
[src]

pub fn line_merge(&self) -> GResult<Geometry<'a>>[src]

Merges Multi Line String geometry into a (set of) Line String.

Warning

If you use this function on something else than a Multi Line String or a Line String, it'll return an empty Geometry collection.

Example

use geos::Geometry;

let lines = Geometry::new_from_wkt("MULTILINESTRING((-29 -27,-30 -29.7,-36 -31,-45 -33),\
                                                 (-45 -33,-46 -32))")
                  .expect("Invalid geometry");
let lines_merged = lines.line_merge().expect("line merge failed");
assert_eq!(lines_merged.to_wkt_precision(1).unwrap(),
           "LINESTRING (-29.0 -27.0, -30.0 -29.7, -36.0 -31.0, -45.0 -33.0, -46.0 -32.0)");

pub fn reverse(&self) -> GResult<Geometry<'a>>[src]

Reverses the order of the vertexes.

Available using the v3_7_0 feature.

Example

use geos::Geometry;

let line = Geometry::new_from_wkt("LINESTRING(1 10,1 2)").expect("invalid geometry");
let reversed_line = line.reverse().expect("reverse failed");

assert_eq!(reversed_line.to_wkt_precision(1).unwrap(), "LINESTRING (1.0 2.0, 1.0 10.0)");

pub fn simplify(&self, tolerance: f64) -> GResult<Geometry<'a>>[src]

Returns a simplified version of the given geometry.

pub fn topology_preserve_simplify(
    &self,
    tolerance: f64
) -> GResult<Geometry<'a>>
[src]

Returns a simplified version of the given geometry. It will avoid creating invalid derived geometries.

pub fn is_valid(&self) -> bool[src]

Checks if the geometry is valid.

Example

use geos::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);

pub fn is_valid_reason(&self) -> GResult<String>[src]

Returns an explanation on why the geometry is invalid.

Example

use geos::Geometry;

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

pub fn get_type(&self) -> GResult<String>[src]

Returns the type of the geometry.

Example

use geos::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()));

pub fn get_coord_seq(&self) -> GResult<CoordSeq<'a>>[src]

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

pub fn geometry_type(&self) -> GeometryTypes[src]

pub fn area(&self) -> GResult<f64>[src]

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

Example

use geos::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.));

pub fn to_wkt(&self) -> GResult<String>[src]

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::{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)");

pub fn to_wkt_precision(&self, precision: u32) -> GResult<String>[src]

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

Example

use geos::{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)");

pub fn is_ring(&self) -> GResult<bool>[src]

Returns true if the geometry is a ring.

Example

use geos::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));

pub fn intersects<'b>(&self, other: &Geometry<'b>) -> GResult<bool>[src]

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::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));

pub fn crosses<'b>(&self, other: &Geometry<'b>) -> GResult<bool>[src]

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

Example

use geos::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));

pub fn disjoint<'b>(&self, other: &Geometry<'b>) -> GResult<bool>[src]

Returns true if self doesn't:

  • Overlap other
  • Touch other
  • Is within other

Example

use geos::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));

pub fn touches<'b>(&self, other: &Geometry<'b>) -> GResult<bool>[src]

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::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));

pub fn overlaps<'b>(&self, other: &Geometry<'b>) -> GResult<bool>[src]

Returns true if self spatially overlaps other.

Example

use geos::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));

pub fn within<'b>(&self, other: &Geometry<'b>) -> GResult<bool>[src]

Returns true if self is completely inside other.

Example

use geos::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));

pub fn equals<'b>(&self, other: &Geometry<'b>) -> GResult<bool>[src]

Checks if the two Geometry objects are equal.

Example

use geos::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::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);

pub fn equals_exact<'b>(
    &self,
    other: &Geometry<'b>,
    precision: f64
) -> GResult<bool>
[src]

Checks if the two Geometry objects are exactly equal.

Example

use geos::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));

pub fn covers<'b>(&self, other: &Geometry<'b>) -> GResult<bool>[src]

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

Example

use geos::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));

pub fn covered_by<'b>(&self, other: &Geometry<'b>) -> GResult<bool>[src]

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

Example

use geos::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));

pub fn contains<'b>(&self, other: &Geometry<'b>) -> GResult<bool>[src]

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

Example

use geos::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));

pub fn buffer(&self, width: f64, quadsegs: i32) -> GResult<Geometry<'a>>[src]

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::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))");

pub fn is_empty(&self) -> GResult<bool>[src]

Returns true if the given geometry is empty.

Example

use geos::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));

pub fn is_simple(&self) -> GResult<bool>[src]

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

Example

use geos::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));

pub fn difference<'b>(&self, other: &Geometry<'b>) -> GResult<Geometry<'a>>[src]

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

Example

use geos::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)");

pub fn envelope(&self) -> GResult<Geometry<'a>>[src]

Returns the minimum bouding box of the given geometry.

Example

use geos::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))");

pub fn sym_difference<'b>(&self, other: &Geometry<'b>) -> GResult<Geometry<'a>>[src]

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

Example

use geos::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))");

pub fn union(&self, other: &Geometry<'a>) -> GResult<Geometry<'a>>[src]

Aggregates the given geometry with another one.

Example

use geos::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)");

pub fn get_centroid(&self) -> GResult<Geometry<'a>>[src]

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

Example

use geos::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)");

pub fn create_empty_polygon() -> GResult<Geometry<'a>>[src]

Creates an empty polygon geometry.

Example

use geos::Geometry;

let geom = Geometry::create_empty_polygon().expect("Failed to build empty polygon");

assert_eq!(geom.to_wkt().unwrap(), "POLYGON EMPTY");

pub fn create_empty_point() -> GResult<Geometry<'a>>[src]

Creates an empty point geometry.

Example

use geos::Geometry;

let geom = Geometry::create_empty_point().expect("Failed to build empty point");

assert_eq!(geom.to_wkt().unwrap(), "POINT EMPTY");

pub fn create_empty_line_string() -> GResult<Geometry<'a>>[src]

Creates an empty line string geometry.

Example

use geos::Geometry;

let geom = Geometry::create_empty_line_string().expect("Failed to build empty line string");

assert_eq!(geom.to_wkt().unwrap(), "LINESTRING EMPTY");

pub fn create_empty_collection(type_: GeometryTypes) -> GResult<Geometry<'a>>[src]

Creates an empty collection.

The type_ must be one of:

Example

use geos::{Geometry, GeometryTypes};

let geom = Geometry::create_empty_collection(GeometryTypes::MultiPolygon)
                    .expect("Failed to build empty collection");

assert_eq!(geom.to_wkt().unwrap(), "MULTIPOLYGON EMPTY");

pub fn create_polygon<'b>(
    exterior: Geometry<'a>,
    interiors: Vec<Geometry<'b>>
) -> GResult<Geometry<'a>>
[src]

Creates a polygon formed by the given shell and array of holes.

Note

exterior must be a LinearRing.

Example

use geos::Geometry;

let geom = Geometry::new_from_wkt("LINEARRING(75.15 29.53,77 29,77.6 29.5, 75.15 29.53)")
                    .expect("Invalid geometry");
let polygon_geom = Geometry::create_polygon(geom, vec![]).expect("create_polygon failed");

assert_eq!(polygon_geom.to_wkt_precision(1).unwrap(),
           "POLYGON ((75.2 29.5, 77.0 29.0, 77.6 29.5, 75.2 29.5))");

pub fn create_geometry_collection(
    geoms: Vec<Geometry<'a>>
) -> GResult<Geometry<'a>>
[src]

Create a geometry collection.

Example

use geos::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 (3.0 4.0)").expect("Invalid geometry");

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

assert_eq!(geom.to_wkt_precision(1).unwrap(),
           "GEOMETRYCOLLECTION (POLYGON ((0.0 0.0, 10.0 0.0, 10.0 6.0, 0.0 6.0, 0.0 0.0)), \
                                POINT (3.0 4.0))");

pub fn create_multipolygon(polygons: Vec<Geometry<'a>>) -> GResult<Geometry<'a>>[src]

Create a multi polygon geometry.

Example

use geos::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((3 3, 10 3, 10 6, 3 6, 3 3))")
                     .expect("Invalid geometry");

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

assert_eq!(geom.to_wkt_precision(1).unwrap(),
           "MULTIPOLYGON (((0.0 0.0, 10.0 0.0, 10.0 6.0, 0.0 6.0, 0.0 0.0)), \
                          ((3.0 3.0, 10.0 3.0, 10.0 6.0, 3.0 6.0, 3.0 3.0)))");

pub fn create_multiline_string(
    linestrings: Vec<Geometry<'a>>
) -> GResult<Geometry<'a>>
[src]

Create a multiline string geometry.

Example

use geos::Geometry;

let geom1 = Geometry::new_from_wkt("LINESTRING (1.0 2.0, 3.0 4.0)").expect("invalid geometry");
let geom2 = Geometry::new_from_wkt("LINESTRING (5.0 6.0, 7.0 8.0)").expect("invalid geometry");

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

assert_eq!(geom.to_wkt_precision(1).unwrap(),
           "MULTILINESTRING ((1.0 2.0, 3.0 4.0), (5.0 6.0, 7.0 8.0))");

pub fn create_multipoint(points: Vec<Geometry<'a>>) -> GResult<Geometry<'a>>[src]

Creates a multi point geometry.

Example

use geos::Geometry;

let geom1 = Geometry::new_from_wkt("POINT (1.0 2.0)").expect("Invalid geometry");
let geom2 = Geometry::new_from_wkt("POINT (3.0 4.0)").expect("Invalid geometry");

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

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

pub fn create_point(s: CoordSeq<'a>) -> GResult<Geometry<'a>>[src]

Creates a point geometry.

Example

use geos::{CoordDimensions, CoordSeq, Geometry};

let coords = CoordSeq::new_from_vec(&[&[1., 2.]])
                      .expect("failed to create CoordSeq");

let geom = Geometry::create_point(coords).expect("Failed to create a point");

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

pub fn create_line_string(s: CoordSeq<'a>) -> GResult<Geometry<'a>>[src]

Creates a line string geometry.

Example

use geos::{CoordDimensions, CoordSeq, Geometry};

let coords = CoordSeq::new_from_vec(&[&[1., 2.], &[3., 4.]])
                      .expect("failed to create CoordSeq");

let geom = Geometry::create_line_string(coords).expect("Failed to create a line string");

assert_eq!(geom.to_wkt_precision(1).unwrap(), "LINESTRING (1.0 2.0, 3.0 4.0)");

pub fn create_linear_ring(s: CoordSeq<'a>) -> GResult<Geometry<'a>>[src]

Creates a linear ring geometry.

Example

use geos::{CoordDimensions, CoordSeq, Geometry};

let coords = CoordSeq::new_from_vec(&[&[75.15, 29.53],
                                      &[77., 29.],
                                      &[77.6, 29.5],
                                      &[75.15, 29.53]])
                      .expect("failed to create CoordSeq");

let geom = Geometry::create_linear_ring(coords).expect("Failed to create a linea ring");

assert_eq!(geom.to_wkt_precision(1).unwrap(),
           "LINEARRING (75.2 29.5, 77.0 29.0, 77.6 29.5, 75.2 29.5)");

pub fn unary_union(&self) -> GResult<Geometry<'a>>[src]

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::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 union_geom = geom.unary_union().expect("unary_union 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))");

pub fn voronoi<'b>(
    &self,
    envelope: Option<&Geometry<'b>>,
    tolerance: f64,
    only_edges: bool
) -> GResult<Geometry<'a>>
[src]

Create a voronoi diagram.

Example

use geos::Geometry;

let input = Geometry::new_from_wkt("MULTIPOINT((100 200), (105 202), (110 200), (140 230),
                                               (210 240), (220 190), (170 170), (170 260),
                                               (213 245), (220 190))")
                  .expect("Invalid geometry");
let mut expected = Geometry::new_from_wkt(
    "GEOMETRYCOLLECTION(POLYGON ((-20 50, -20 380, -3.75 380, 105 235, 105 115, 77.14285714285714 50, -20 50)),\
                         POLYGON ((247 50, 77.14285714285714 50, 105 115, 145 195, 178.33333333333334 211.66666666666666, 183.51851851851853 208.7037037037037, 247 50)),\
                         POLYGON ((-3.75 380, 20.000000000000007 380, 176.66666666666666 223.33333333333334, 178.33333333333334 211.66666666666666, 145 195, 105 235, -3.75 380)),\
                         POLYGON ((105 115, 105 235, 145 195, 105 115)),\
                         POLYGON ((20.000000000000007 380, 255 380, 176.66666666666666 223.33333333333334, 20.000000000000007 380)),\
                         POLYGON ((255 380, 340 380, 340 240, 183.51851851851853 208.7037037037037, 178.33333333333334 211.66666666666666, 176.66666666666666 223.33333333333334, 255 380)),\
                         POLYGON ((340 240, 340 50, 247 50, 183.51851851851853 208.7037037037037, 340 240)))")
                            .expect("Invalid geometry");

let mut voronoi = input.voronoi(None, 6., false).expect("voronoi failed");

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

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

pub fn normalize(&mut self) -> GResult<bool>[src]

Normalizes self in its normalized/canonical form. May reorder vertices in polygon rings, rings in a polygon, elements in a multi-geometry complex.

Example

use geos::Geometry;

let mut geom = Geometry::new_from_wkt("GEOMETRYCOLLECTION(POINT(2 3),
                                                          MULTILINESTRING((0 0, 1 1),(2 2, 3 3)))")
                        .expect("Invalid geometry");

geom.normalize();

assert_eq!(geom.to_wkt_precision(1).unwrap(),
           "GEOMETRYCOLLECTION (MULTILINESTRING ((2.0 2.0, 3.0 3.0), (0.0 0.0, 1.0 1.0)), \
                                POINT (2.0 3.0))");

pub fn intersection<'b>(&self, other: &Geometry<'b>) -> GResult<Geometry<'a>>[src]

Returns a geometry representing the intersection between self and other.

Example

use geos::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)");

pub fn convex_hull(&self) -> GResult<Geometry<'a>>[src]

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::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))");

pub fn boundary(&self) -> GResult<Geometry<'a>>[src]

Returns the closure of the combinatorial boundary of self.

Example

use geos::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)");

pub fn has_z(&self) -> GResult<bool>[src]

Returns true if self has a Z coordinate.

Example

use geos::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));

pub fn is_closed(&self) -> GResult<bool>[src]

Returns true if start and end point are coincident.

Only works on LineString and MultiLineString.

Example

use geos::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));

pub fn length(&self) -> GResult<f64>[src]

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

Example

use geos::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");

pub fn distance<'b>(&self, other: &Geometry<'b>) -> GResult<f64>[src]

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

Example

use geos::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");

pub fn distance_indexed<'b>(&self, other: &Geometry<'b>) -> GResult<f64>[src]

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

Available using the v3_7_0 feature.

Example

use geos::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");

pub fn hausdorff_distance<'b>(&self, other: &Geometry<'b>) -> GResult<f64>[src]

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

Example

use geos::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");

pub fn hausdorff_distance_densify<'b>(
    &self,
    other: &Geometry<'b>,
    distance_frac: f64
) -> GResult<f64>
[src]

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

Example

use geos::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");

pub fn frechet_distance<'b>(&self, other: &Geometry<'b>) -> GResult<f64>[src]

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

Available using the v3_7_0 feature.

Example

use geos::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");

pub fn frechet_distance_densify<'b>(
    &self,
    other: &Geometry<'b>,
    distance_frac: f64
) -> GResult<f64>
[src]

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

Available using the v3_7_0 feature.

Example

use geos::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");

pub fn get_length(&self) -> GResult<f64>[src]

Returns the length of the given geometry.

Example

use geos::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");

pub fn snap<'b>(
    &self,
    other: &Geometry<'b>,
    tolerance: f64
) -> GResult<Geometry<'a>>
[src]

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::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)))");

pub fn extract_unique_points(&self) -> GResult<Geometry<'a>>[src]

Returns unique points of self.

pub fn nearest_points<'b>(&self, other: &Geometry<'b>) -> GResult<CoordSeq<'a>>[src]

pub fn get_x(&self) -> GResult<f64>[src]

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

Example

use geos::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));

pub fn get_y(&self) -> GResult<f64>[src]

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

Example

use geos::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));

pub fn get_z(&self) -> GResult<f64>[src]

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::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));

pub fn get_point_n(&self, n: usize) -> GResult<Geometry<'a>>[src]

Returns the nth point of the given geometry.

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

Example

use geos::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)");

pub fn get_start_point(&self) -> GResult<Geometry<'a>>[src]

Returns the start point of self.

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

Example

use geos::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)");

pub fn get_end_point(&self) -> GResult<Geometry<'a>>[src]

Returns the end point of self.

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

Example

use geos::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)");

pub fn get_num_points(&self) -> GResult<usize>[src]

Returns the number of points of self.

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

Example

use geos::Geometry;

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

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

pub fn get_num_interior_rings(&self) -> GResult<usize>[src]

Returns the number of interior rings.

Example

use geos::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));

pub fn get_interior_ring_n(&self, n: u32) -> GResult<Geometry<'a>>[src]

Returns the nth interior ring.

Example

use geos::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)");

pub fn get_exterior_ring(&self) -> GResult<Geometry<'a>>[src]

Returns the exterior ring.

Example

use geos::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)");

pub fn get_num_coordinates(&self) -> GResult<usize>[src]

Returns the number of coordinates inside self.

Example

use geos::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));

pub fn get_num_dimensions(&self) -> GResult<usize>[src]

Returns the number of dimensions used in self.

Example

use geos::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));

pub fn get_coordinate_dimension(&self) -> GResult<Dimensions>[src]

Return in which coordinate dimension the geometry is.

Example

use geos::{Dimensions, 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));

pub fn make_valid(&self) -> GResult<Geometry<'a>>[src]

This functions attempts to return a valid representation of self.

Available using the v3_8_0 feature.

pub fn get_num_geometries(&self) -> GResult<usize>[src]

Returns the number of geometries.

Example

use geos::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));

pub fn get_geometry_n(&self, n: usize) -> GResult<Geometry<'a>>[src]

Returns the 1-based nth geometry.

Example

use geos::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)");

pub fn get_srid(&self) -> GResult<usize>[src]

Get SRID of self.

Example

use geos::Geometry;

let 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));

pub fn set_srid(&self, srid: usize) -> GResult<()>[src]

Set SRID of self.

Example

use geos::Geometry;

let 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));

pub fn get_precision(&self) -> GResult<f64>[src]

Returns the precision of self.

Available using the v3_6_0 feature.

Example

use geos::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");

pub fn set_precision(
    &self,
    grid_size: f64,
    flags: Precision
) -> GResult<Geometry<'a>>
[src]

Returns the precision of self.

Available using the v3_6_0 feature.

Example

use geos::{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");

pub fn get_x_max(&self) -> GResult<f64>[src]

Returns the biggest X of the geometry.

Available using the v3_7_0 feature.

Example

use geos::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.));

pub fn get_x_min(&self) -> GResult<f64>[src]

Returns the smallest X of the geometry.

Available using the v3_7_0 feature.

Example

use geos::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.));

pub fn get_y_max(&self) -> GResult<f64>[src]

Returns the biggest Y of the geometry.

Available using the v3_7_0 feature.

Example

use geos::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.));

pub fn get_y_min(&self) -> GResult<f64>[src]

Returns the smallest Y of the geometry.

Available using the v3_7_0 feature.

Example

use geos::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.));

pub fn minimum_clearance(&self) -> GResult<f64>[src]

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::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");

pub fn minimum_clearance_line(&self) -> GResult<Geometry<'a>>[src]

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

Available using the v3_6_0 feature.

Example

use geos::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)");

pub fn minimum_rotated_rectangle(&self) -> GResult<Geometry<'a>>[src]

Returns the minimum rotated rectangle inside of self.

Available using the v3_6_0 feature.

pub fn minimum_width(&self) -> GResult<Geometry<'a>>[src]

Returns the minimum width inside of self.

Available using the v3_6_0 feature.

pub fn delaunay_triangulation(
    &self,
    tolerance: f64,
    only_edges: bool
) -> GResult<Geometry<'a>>
[src]

Returns a delaunay triangulation around the vertices of self.

Example

use geos::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");

pub fn interpolate(&self, d: f64) -> GResult<Geometry<'a>>[src]

pub fn interpolate_normalized(&self, d: f64) -> GResult<Geometry<'a>>[src]

pub fn project(&self, p: &Geometry) -> GResult<f64>[src]

pub fn project_normalized(&self, p: &Geometry) -> GResult<f64>[src]

pub fn node(&self) -> GResult<Geometry<'a>>[src]

pub fn offset_curve(
    &self,
    width: f64,
    quadrant_segments: i32,
    join_style: JoinStyle,
    mitre_limit: f64
) -> GResult<Geometry<'a>>
[src]

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.

pub fn point_on_surface(&self) -> GResult<Geometry<'a>>[src]

pub fn polygonize_full(
    &self
) -> GResult<(Geometry<'a>, Option<Geometry<'a>>, Option<Geometry<'a>>, Option<Geometry<'a>>)>
[src]

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.

pub fn shared_paths(&self, other: Geometry) -> GResult<Geometry<'a>>[src]

Trait Implementations

impl<'a> TryInto<Geometry<'a>> for &'a Point<f64>[src]

type Err = Error

impl<'a, T: Borrow<Point<f64>>> TryInto<Geometry<'a>> for &'a [T][src]

type Err = Error

impl<'a> TryInto<Geometry<'a>> for &'a LineString<f64>[src]

type Err = Error

impl<'a> TryInto<Geometry<'a>> for &'a Polygon<f64>[src]

type Err = Error

impl<'a> TryInto<Geometry<'a>> for &'a MultiPolygon<f64>[src]

type Err = Error

impl<'a> TryInto<Geometry<f64>> for GGeom<'a>[src]

type Err = Error

impl<'a> ContextHandling for Geometry<'a>[src]

impl<'a> ContextInteractions<'a> for Geometry<'a>[src]

fn set_context_handle(&mut self, context: ContextHandle<'a>)[src]

Set the context handle to the geometry.

use geos::{ContextInteractions, ContextHandle, Geometry};

let context_handle = ContextHandle::init().expect("invalid init");
context_handle.set_notice_message_handler(Some(Box::new(|s| println!("new message: {}", s))));
let mut point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
point_geom.set_context_handle(context_handle);

fn get_context_handle(&self) -> &ContextHandle<'a>[src]

Get the context handle of the geometry.

use geos::{ContextInteractions, Geometry};

let point_geom = Geometry::new_from_wkt("POINT (2.5 2.5)").expect("Invalid geometry");
let context = point_geom.get_context_handle();
context.set_notice_message_handler(Some(Box::new(|s| println!("new message: {}", s))));

fn get_last_error(&self) -> Option<String>[src]

Gets the last error (if any) from the ContextHandle held by this object. Read more

fn get_last_notification(&self) -> Option<String>[src]

Gets the last notification (if any) from the ContextHandle held by this object. Read more

impl<'a> Sync for Geometry<'a>[src]

impl<'a> Send for Geometry<'a>[src]

impl<'a> Clone for Geometry<'a>[src]

fn clone(&self) -> Geometry<'a>[src]

Also passes the context to the newly created Geometry.

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<'a> Drop for Geometry<'a>[src]

impl<'a> PartialEq<Geometry<'a>> for Geometry<'a>[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]