[][src]Struct geos::PreparedGeometry

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

PreparedGeometry is an interface which prepares [Geometry] for greater performance on repeated calls.

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 mut prepared_geom = geom1.to_prepared_geom()
                             .expect("failed to create prepared geom");
let geom2 = Geometry::new_from_wkt("POINT (2.5 2.5)")
                     .expect("Invalid geometry");

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

Implementations

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

pub fn new<G: Geom<'a>>(g: &G) -> GResult<PreparedGeometry<'a>>[src]

Creates a new PreparedGeometry from a [Geometry].

Example

use geos::{Geometry, PreparedGeometry};

let geom1 = Geometry::new_from_wkt("POLYGON((0 0, 10 0, 10 6, 0 6, 0 0))")
                     .expect("Invalid geometry");
let prepared_geom = PreparedGeometry::new(&geom1);

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

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 mut prepared_geom = geom1
    .to_prepared_geom()
    .expect("failed to create prepared geom");
let geom2 = Geometry::new_from_wkt("POINT (2.5 2.5)")
                     .expect("Invalid geometry");

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

pub fn contains_properly<'b, G: Geom<'b>>(&self, other: &G) -> GResult<bool>[src]

Returns true if every point of the other geometry is inside self's interior.

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 mut prepared_geom = geom1
    .to_prepared_geom()
    .expect("failed to create prepared geom");
let geom2 = Geometry::new_from_wkt("POINT (2.5 2.5)")
                     .expect("Invalid geometry");

assert_eq!(prepared_geom.contains_properly(&geom2), Ok(true));

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

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

let prepared_little_geom = little_geom
    .to_prepared_geom()
    .expect("to_prepared_geom failed");
let prepared_big_geom = big_geom
    .to_prepared_geom()
    .expect("to_prepared_geom failed");

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

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

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

let prepared_little_geom = little_geom
    .to_prepared_geom()
    .expect("to_prepared_geom failed");
let prepared_big_geom = big_geom
    .to_prepared_geom()
    .expect("to_prepared_geom failed");

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

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

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");
let prepared_geom = geom1.to_prepared_geom().expect("to_prepared_geom failed");

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

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

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 prepared_geom = geom1
    .to_prepared_geom()
    .expect("to_prepared_geom failed");
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!(prepared_geom.disjoint(&geom2), Ok(true));
assert_eq!(prepared_geom.disjoint(&geom3), Ok(false));

pub fn intersects<'b, G: Geom<'b>>(&self, other: &G) -> 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::{Geom, Geometry};

let geom1 = Geometry::new_from_wkt("POINT(0 0)")
                     .expect("invalid geometry");
let prepared_geom = geom1
    .to_prepared_geom()
    .expect("to_prepared_geom failed");
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!(prepared_geom.intersects(&geom2), Ok(false));
assert_eq!(prepared_geom.intersects(&geom3), Ok(true));

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

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 prepared_geom = geom1
    .to_prepared_geom()
    .expect("to_prepared_geom failed");
let geom2 = Geometry::new_from_wkt("LINESTRING(1 0, 1 1, 3 5)")
                     .expect("invalid geometry");

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

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

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

pub fn touches<'b, G: Geom<'b>>(&self, other: &G) -> 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::{Geom, Geometry};

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

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

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

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

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

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

let small_prepared_geom = small_geom
    .to_prepared_geom()
    .expect("to_prepared_geom failed");
let big_prepared_geom = big_geom
    .to_prepared_geom()
    .expect("to_prepared_geom failed");

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

Trait Implementations

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

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

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

Set the context handle to the PreparedGeometry.

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

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

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

Get the context handle of the PreparedGeometry.

use geos::{
    ContextInteractions, CoordDimensions, Geom, Geometry,
    PreparedGeometry,
};

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");
let context = prepared_geom.get_context_handle();
context.set_notice_message_handler(Some(Box::new(|s| println!("new message: {}", s))));

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

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

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

Auto Trait Implementations

impl<'a> RefUnwindSafe for PreparedGeometry<'a>

impl<'a> Unpin for PreparedGeometry<'a>

impl<'a> UnwindSafe for PreparedGeometry<'a>

Blanket Implementations

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

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

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

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

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

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.