Struct geos::PreparedGeometry[][src]

pub struct PreparedGeometry<'a> { /* fields omitted */ }
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.