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>
impl<'a> PreparedGeometry<'a>
sourcepub fn contains<'b, G: Geom<'b>>(&self, other: &G) -> GResult<bool>
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));
sourcepub fn contains_properly<'b, G: Geom<'b>>(&self, other: &G) -> GResult<bool>
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));
sourcepub fn covered_by<'b, G: Geom<'b>>(&self, other: &G) -> GResult<bool>
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));
sourcepub fn covers<'b, G: Geom<'b>>(&self, other: &G) -> GResult<bool>
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));
sourcepub fn crosses<'b, G: Geom<'b>>(&self, other: &G) -> GResult<bool>
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));
sourcepub fn disjoint<'b, G: Geom<'b>>(&self, other: &G) -> GResult<bool>
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));
sourcepub fn intersects<'b, G: Geom<'b>>(&self, other: &G) -> GResult<bool>
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
overlapsother
self
touchesother
self
is withinother
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));
sourcepub fn overlaps<'b, G: Geom<'b>>(&self, other: &G) -> GResult<bool>
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));
sourcepub fn touches<'b, G: Geom<'b>>(&self, other: &G) -> GResult<bool>
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));
sourcepub fn within<'b, G: Geom<'b>>(&self, other: &G) -> GResult<bool>
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>
impl<'a> ContextHandling for PreparedGeometry<'a>
type Context = Arc<ContextHandle<'a>>
fn clone_context(&self) -> Arc<ContextHandle<'a>>
source§impl<'a> ContextInteractions<'a> for PreparedGeometry<'a>
impl<'a> ContextInteractions<'a> for PreparedGeometry<'a>
source§fn set_context_handle(&mut self, context: ContextHandle<'a>)
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>
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>
fn get_last_error(&self) -> Option<String>
ContextHandle
held by this object. Read moresource§fn get_last_notification(&self) -> Option<String>
fn get_last_notification(&self) -> Option<String>
ContextHandle
held by this object. Read more