Struct geos::PreparedGeometry

source ·
pub struct PreparedGeometry<'a> { /* private fields */ }
Expand description

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§

source§

impl<'a> PreparedGeometry<'a>

source

pub fn new<'b: 'a, G: Geom<'b>>(g: &'a G) -> GResult<PreparedGeometry<'a>>

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

pub fn contains<'b, G: Geom<'b>>(&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 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));
source

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

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

pub fn covered_by<'b, G: Geom<'b>>(&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");

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

pub fn covers<'b, G: Geom<'b>>(&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");

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

pub fn crosses<'b, G: Geom<'b>>(&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");
let prepared_geom = geom1.to_prepared_geom().expect("to_prepared_geom failed");

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

pub fn disjoint<'b, G: Geom<'b>>(&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 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));
source

pub fn intersects<'b, G: Geom<'b>>(&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 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));
source

pub fn overlaps<'b, G: Geom<'b>>(&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 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));
source

pub fn touches<'b, G: Geom<'b>>(&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 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));
source

pub fn within<'b, G: Geom<'b>>(&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");

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§

source§

impl<'a> ContextHandling for PreparedGeometry<'a>

source§

impl<'a> ContextInteractions<'a> for PreparedGeometry<'a>

source§

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

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

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

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

fn get_last_error(&self) -> Option<String>

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

fn get_last_notification(&self) -> Option<String>

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

impl<'a> Drop for PreparedGeometry<'a>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a> Send for PreparedGeometry<'a>

source§

impl<'a> Sync for PreparedGeometry<'a>

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.