pub enum Geometry<T> where
T: CoordNum, {
Point(Point<T>),
Line(Line<T>),
LineString(LineString<T>),
Polygon(Polygon<T>),
MultiPoint(MultiPoint<T>),
MultiLineString(MultiLineString<T>),
MultiPolygon(MultiPolygon<T>),
GeometryCollection(GeometryCollection<T>),
Rect(Rect<T>),
Triangle(Triangle<T>),
}
Expand description
An enum representing any possible geometry type.
All Geo
types can be converted to a Geometry
member using .into()
(as part of the
std::convert::Into
pattern), and Geo
types implement the TryFrom
trait in order to
convert back from enum members.
Example
use std::convert::TryFrom;
use geo_types::{Point, point, Geometry, GeometryCollection};
let p = point!(x: 1.0, y: 1.0);
let pe: Geometry<f64> = p.into();
let pn = Point::try_from(pe).unwrap();
Variants
Point(Point<T>)
Line(Line<T>)
LineString(LineString<T>)
Polygon(Polygon<T>)
MultiPoint(MultiPoint<T>)
MultiLineString(MultiLineString<T>)
MultiPolygon(MultiPolygon<T>)
GeometryCollection(GeometryCollection<T>)
Rect(Rect<T>)
Triangle(Triangle<T>)
Implementations
sourceimpl<T> Geometry<T> where
T: CoordNum,
impl<T> Geometry<T> where
T: CoordNum,
sourcepub fn into_point(self) -> Option<Point<T>>
👎 Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<Point>
pub fn into_point(self) -> Option<Point<T>>
Will be removed in an upcoming version. Switch to std::convert::TryInto<Point>
If this Geometry is a Point, then return that, else None.
Examples
use geo_types::*;
use std::convert::TryInto;
let g = Geometry::Point(Point::new(0., 0.));
let p2: Point<f32> = g.try_into().unwrap();
assert_eq!(p2, Point::new(0., 0.,));
sourcepub fn into_line_string(self) -> Option<LineString<T>>
👎 Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<LineString>
pub fn into_line_string(self) -> Option<LineString<T>>
Will be removed in an upcoming version. Switch to std::convert::TryInto<LineString>
If this Geometry is a LineString, then return that LineString, else None.
sourcepub fn into_line(self) -> Option<Line<T>>
👎 Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<Line>
pub fn into_line(self) -> Option<Line<T>>
Will be removed in an upcoming version. Switch to std::convert::TryInto<Line>
If this Geometry is a Line, then return that Line, else None.
sourcepub fn into_polygon(self) -> Option<Polygon<T>>
👎 Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<Polygon>
pub fn into_polygon(self) -> Option<Polygon<T>>
Will be removed in an upcoming version. Switch to std::convert::TryInto<Polygon>
If this Geometry is a Polygon, then return that, else None.
sourcepub fn into_multi_point(self) -> Option<MultiPoint<T>>
👎 Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPoint>
pub fn into_multi_point(self) -> Option<MultiPoint<T>>
Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPoint>
If this Geometry is a MultiPoint, then return that, else None.
sourcepub fn into_multi_line_string(self) -> Option<MultiLineString<T>>
👎 Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiLineString>
pub fn into_multi_line_string(self) -> Option<MultiLineString<T>>
Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiLineString>
If this Geometry is a MultiLineString, then return that, else None.
sourcepub fn into_multi_polygon(self) -> Option<MultiPolygon<T>>
👎 Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPolygon>
pub fn into_multi_polygon(self) -> Option<MultiPolygon<T>>
Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPolygon>
If this Geometry is a MultiPolygon, then return that, else None.
Trait Implementations
sourceimpl<T> AbsDiffEq<Geometry<T>> for Geometry<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum,
impl<T> AbsDiffEq<Geometry<T>> for Geometry<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum,
sourcefn abs_diff_eq(
&self,
other: &Geometry<T>,
epsilon: <Geometry<T> as AbsDiffEq<Geometry<T>>>::Epsilon
) -> bool
fn abs_diff_eq(
&self,
other: &Geometry<T>,
epsilon: <Geometry<T> as AbsDiffEq<Geometry<T>>>::Epsilon
) -> bool
Equality assertion with an absolute limit.
Examples
use geo_types::{Geometry, polygon};
let a: Geometry<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7., y: 9.), (x: 0., y: 0.)].into();
let b: Geometry<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7.01, y: 9.), (x: 0., y: 0.)].into();
approx::assert_abs_diff_eq!(a, b, epsilon=0.1);
approx::assert_abs_diff_ne!(a, b, epsilon=0.001);
type Epsilon = T
type Epsilon = T
Used for specifying relative comparisons.
sourcefn default_epsilon() -> <Geometry<T> as AbsDiffEq<Geometry<T>>>::Epsilon
fn default_epsilon() -> <Geometry<T> as AbsDiffEq<Geometry<T>>>::Epsilon
The default tolerance to use when testing values that are close together. Read more
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
The inverse of [AbsDiffEq::abs_diff_eq
].
sourceimpl<T> Area<T> for Geometry<T> where
T: CoordFloat,
impl<T> Area<T> for Geometry<T> where
T: CoordFloat,
fn signed_area(&self) -> T
fn unsigned_area(&self) -> T
sourceimpl<T> BoundingRect<T> for Geometry<T> where
T: CoordNum,
impl<T> BoundingRect<T> for Geometry<T> where
T: CoordNum,
sourceimpl<F: GeoFloat> ClosestPoint<F, Point<F>> for Geometry<F>
impl<F: GeoFloat> ClosestPoint<F, Point<F>> for Geometry<F>
sourcefn closest_point(&self, p: &Point<F>) -> Closest<F>
fn closest_point(&self, p: &Point<F>) -> Closest<F>
Find the closest point between self
and p
.
sourceimpl<T> Contains<Coordinate<T>> for Geometry<T> where
T: GeoNum,
impl<T> Contains<Coordinate<T>> for Geometry<T> where
T: GeoNum,
fn contains(&self, coord: &Coordinate<T>) -> bool
sourceimpl<T> CoordinatePosition for Geometry<T> where
T: GeoNum,
impl<T> CoordinatePosition for Geometry<T> where
T: GeoNum,
type Scalar = T
fn calculate_coordinate_position(
&self,
coord: &Coordinate<T>,
is_inside: &mut bool,
boundary_count: &mut usize
)
fn coordinate_position(&self, coord: &Coordinate<Self::Scalar>) -> CoordPos
sourceimpl<'a, T: CoordNum + 'a> CoordsIter<'a> for Geometry<T>
impl<'a, T: CoordNum + 'a> CoordsIter<'a> for Geometry<T>
sourcefn coords_count(&'a self) -> usize
fn coords_count(&'a self) -> usize
Return the number of coordinates in the Geometry
.
type Iter = GeometryCoordsIter<'a, T>
type ExteriorIter = GeometryExteriorCoordsIter<'a, T>
type Scalar = T
sourcefn coords_iter(&'a self) -> Self::Iter
fn coords_iter(&'a self) -> Self::Iter
Iterate over all exterior and (if any) interior coordinates of a geometry. Read more
sourcefn exterior_coords_iter(&'a self) -> Self::ExteriorIter
fn exterior_coords_iter(&'a self) -> Self::ExteriorIter
Iterate over all exterior coordinates of a geometry. Read more
sourceimpl<T> From<LineString<T>> for Geometry<T> where
T: CoordNum,
impl<T> From<LineString<T>> for Geometry<T> where
T: CoordNum,
sourcefn from(x: LineString<T>) -> Geometry<T>
fn from(x: LineString<T>) -> Geometry<T>
Converts to this type from the input type.
sourceimpl<T> From<MultiLineString<T>> for Geometry<T> where
T: CoordNum,
impl<T> From<MultiLineString<T>> for Geometry<T> where
T: CoordNum,
sourcefn from(x: MultiLineString<T>) -> Geometry<T>
fn from(x: MultiLineString<T>) -> Geometry<T>
Converts to this type from the input type.
sourceimpl<T> From<MultiPoint<T>> for Geometry<T> where
T: CoordNum,
impl<T> From<MultiPoint<T>> for Geometry<T> where
T: CoordNum,
sourcefn from(x: MultiPoint<T>) -> Geometry<T>
fn from(x: MultiPoint<T>) -> Geometry<T>
Converts to this type from the input type.
sourceimpl<T> From<MultiPolygon<T>> for Geometry<T> where
T: CoordNum,
impl<T> From<MultiPolygon<T>> for Geometry<T> where
T: CoordNum,
sourcefn from(x: MultiPolygon<T>) -> Geometry<T>
fn from(x: MultiPolygon<T>) -> Geometry<T>
Converts to this type from the input type.
sourceimpl<C: GeoNum> HasDimensions for Geometry<C>
impl<C: GeoNum> HasDimensions for Geometry<C>
sourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Some geometries, like a MultiPoint
, can have zero coordinates - we call these empty
. Read more
sourcefn dimensions(&self) -> Dimensions
fn dimensions(&self) -> Dimensions
The dimensions of some geometries are fixed, e.g. a Point always has 0 dimensions. However
for others, the dimensionality depends on the specific geometry instance - for example
typical Rect
s are 2-dimensional, but it’s possible to create degenerate Rect
s which
have either 1 or 0 dimensions. Read more
sourcefn boundary_dimensions(&self) -> Dimensions
fn boundary_dimensions(&self) -> Dimensions
The dimensions of the Geometry
’s boundary, as used by OGC-SFA. Read more
sourceimpl<T, G> Intersects<G> for Geometry<T> where
T: CoordNum,
Point<T>: Intersects<G>,
MultiPoint<T>: Intersects<G>,
Line<T>: Intersects<G>,
LineString<T>: Intersects<G>,
MultiLineString<T>: Intersects<G>,
Triangle<T>: Intersects<G>,
Rect<T>: Intersects<G>,
Polygon<T>: Intersects<G>,
MultiPolygon<T>: Intersects<G>,
impl<T, G> Intersects<G> for Geometry<T> where
T: CoordNum,
Point<T>: Intersects<G>,
MultiPoint<T>: Intersects<G>,
Line<T>: Intersects<G>,
LineString<T>: Intersects<G>,
MultiLineString<T>: Intersects<G>,
Triangle<T>: Intersects<G>,
Rect<T>: Intersects<G>,
Polygon<T>: Intersects<G>,
MultiPolygon<T>: Intersects<G>,
fn intersects(&self, rhs: &G) -> bool
sourceimpl<T> Intersects<Geometry<T>> for Coordinate<T> where
Geometry<T>: Intersects<Coordinate<T>>,
T: CoordNum,
impl<T> Intersects<Geometry<T>> for Coordinate<T> where
Geometry<T>: Intersects<Coordinate<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Geometry<T>) -> bool
sourceimpl<T> Intersects<Geometry<T>> for Line<T> where
Geometry<T>: Intersects<Line<T>>,
T: CoordNum,
impl<T> Intersects<Geometry<T>> for Line<T> where
Geometry<T>: Intersects<Line<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Geometry<T>) -> bool
sourceimpl<T> Intersects<Geometry<T>> for Rect<T> where
Geometry<T>: Intersects<Rect<T>>,
T: CoordNum,
impl<T> Intersects<Geometry<T>> for Rect<T> where
Geometry<T>: Intersects<Rect<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Geometry<T>) -> bool
sourceimpl<T> Intersects<Geometry<T>> for Polygon<T> where
Geometry<T>: Intersects<Polygon<T>>,
T: CoordNum,
impl<T> Intersects<Geometry<T>> for Polygon<T> where
Geometry<T>: Intersects<Polygon<T>>,
T: CoordNum,
fn intersects(&self, rhs: &Geometry<T>) -> bool
sourceimpl<T: CoordNum> MapCoordsInplace<T> for Geometry<T>
impl<T: CoordNum> MapCoordsInplace<T> for Geometry<T>
sourceimpl<F: GeoFloat> Relate<F, Geometry<F>> for Geometry<F>
impl<F: GeoFloat> Relate<F, Geometry<F>> for Geometry<F>
fn relate(&self, other: &Geometry<F>) -> IntersectionMatrix
sourceimpl<T> RelativeEq<Geometry<T>> for Geometry<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>,
impl<T> RelativeEq<Geometry<T>> for Geometry<T> where
T: AbsDiffEq<T, Epsilon = T> + CoordNum + RelativeEq<T>,
sourcefn relative_eq(
&self,
other: &Geometry<T>,
epsilon: <Geometry<T> as AbsDiffEq<Geometry<T>>>::Epsilon,
max_relative: <Geometry<T> as AbsDiffEq<Geometry<T>>>::Epsilon
) -> bool
fn relative_eq(
&self,
other: &Geometry<T>,
epsilon: <Geometry<T> as AbsDiffEq<Geometry<T>>>::Epsilon,
max_relative: <Geometry<T> as AbsDiffEq<Geometry<T>>>::Epsilon
) -> bool
Equality assertion within a relative limit.
Examples
use geo_types::{Geometry, polygon};
let a: Geometry<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7., y: 9.), (x: 0., y: 0.)].into();
let b: Geometry<f32> = polygon![(x: 0., y: 0.), (x: 5., y: 0.), (x: 7.01, y: 9.), (x: 0., y: 0.)].into();
approx::assert_relative_eq!(a, b, max_relative=0.1);
approx::assert_relative_ne!(a, b, max_relative=0.001);
sourcefn default_max_relative() -> <Geometry<T> as AbsDiffEq<Geometry<T>>>::Epsilon
fn default_max_relative() -> <Geometry<T> as AbsDiffEq<Geometry<T>>>::Epsilon
The default relative tolerance for testing values that are far-apart. Read more
fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
The inverse of [RelativeEq::relative_eq
].
sourceimpl<T> TryFrom<Geometry<T>> for Polygon<T> where
T: CoordNum,
impl<T> TryFrom<Geometry<T>> for Polygon<T> where
T: CoordNum,
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.
sourceimpl<T> TryFrom<Geometry<T>> for Triangle<T> where
T: CoordNum,
impl<T> TryFrom<Geometry<T>> for Triangle<T> where
T: CoordNum,
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.
sourceimpl<T> TryFrom<Geometry<T>> for Line<T> where
T: CoordNum,
impl<T> TryFrom<Geometry<T>> for Line<T> where
T: CoordNum,
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.
sourceimpl<T> TryFrom<Geometry<T>> for MultiPolygon<T> where
T: CoordNum,
impl<T> TryFrom<Geometry<T>> for MultiPolygon<T> where
T: CoordNum,
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.
sourceimpl<T> TryFrom<Geometry<T>> for Point<T> where
T: CoordNum,
impl<T> TryFrom<Geometry<T>> for Point<T> where
T: CoordNum,
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.
sourceimpl<T> TryFrom<Geometry<T>> for Rect<T> where
T: CoordNum,
impl<T> TryFrom<Geometry<T>> for Rect<T> where
T: CoordNum,
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.
sourceimpl<T> TryFrom<Geometry<T>> for MultiLineString<T> where
T: CoordNum,
impl<T> TryFrom<Geometry<T>> for MultiLineString<T> where
T: CoordNum,
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.
sourceimpl<T> TryFrom<Geometry<T>> for LineString<T> where
T: CoordNum,
impl<T> TryFrom<Geometry<T>> for LineString<T> where
T: CoordNum,
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.
sourceimpl<T> TryFrom<Geometry<T>> for MultiPoint<T> where
T: CoordNum,
impl<T> TryFrom<Geometry<T>> for MultiPoint<T> where
T: CoordNum,
Convert a Geometry enum into its inner type.
Fails if the enum case does not match the type you are trying to convert it to.
sourceimpl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for Geometry<T>
impl<T: CoordNum, NT: CoordNum, E> TryMapCoords<T, NT, E> for Geometry<T>
sourceimpl<T: CoordNum, E> TryMapCoordsInplace<T, E> for Geometry<T>
impl<T: CoordNum, E> TryMapCoordsInplace<T, E> for Geometry<T>
impl<T> Eq for Geometry<T> where
T: Eq + CoordNum,
impl<T> StructuralEq for Geometry<T> where
T: CoordNum,
impl<T> StructuralPartialEq for Geometry<T> where
T: CoordNum,
Auto Trait Implementations
impl<T> RefUnwindSafe for Geometry<T> where
T: RefUnwindSafe,
impl<T> Send for Geometry<T> where
T: Send,
impl<T> Sync for Geometry<T> where
T: Sync,
impl<T> Unpin for Geometry<T> where
T: Unpin,
impl<T> UnwindSafe for Geometry<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<'a, T, G> Extremes<'a, T> for G where
G: CoordsIter<'a, Scalar = T>,
T: CoordNum,
impl<'a, T, G> Extremes<'a, T> for G where
G: CoordsIter<'a, Scalar = T>,
T: CoordNum,
sourceimpl<T, G> RotatePoint<T> for G where
T: CoordFloat,
G: MapCoords<T, T, Output = G>,
impl<T, G> RotatePoint<T> for G where
T: CoordFloat,
G: MapCoords<T, T, Output = G>,
sourcefn rotate_around_point(&self, angle: T, point: Point<T>) -> G
fn rotate_around_point(&self, angle: T, point: Point<T>) -> G
Rotate a Geometry around an arbitrary point by an angle, given in degrees Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T, G> Translate<T> for G where
T: CoordNum,
G: MapCoords<T, T, Output = G> + MapCoordsInplace<T>,
impl<T, G> Translate<T> for G where
T: CoordNum,
G: MapCoords<T, T, Output = G> + MapCoordsInplace<T>,
sourcefn translate(&self, xoff: T, yoff: T) -> G
fn translate(&self, xoff: T, yoff: T) -> G
Translate a Geometry along its axes by the given offsets Read more
sourcefn translate_inplace(&mut self, xoff: T, yoff: T)
fn translate_inplace(&mut self, xoff: T, yoff: T)
Translate a Geometry along its axes, but in place.