pub enum Geometry<T: CoordNum = f64> {
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 geometry variants (Point
, LineString
, etc.) can be converted to a Geometry
using
Into::into
. Conversely, TryFrom::try_from
can be used to convert a Geometry
back to one of it’s specific 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 = 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§
source§impl<T: CoordNum> Geometry<T>
impl<T: CoordNum> Geometry<T>
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>>
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>>
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>>
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>>
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>>
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>>
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>>
If this Geometry is a MultiPolygon, then return that, else None.
Trait Implementations§
source§impl<T: AbsDiffEq<Epsilon = T> + CoordNum> AbsDiffEq<Geometry<T>> for Geometry<T>
impl<T: AbsDiffEq<Epsilon = T> + CoordNum> AbsDiffEq<Geometry<T>> for Geometry<T>
source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::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);
source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq
.source§impl<'de, T> Deserialize<'de> for Geometry<T>where
T: Deserialize<'de> + CoordNum,
impl<'de, T> Deserialize<'de> for Geometry<T>where
T: Deserialize<'de> + CoordNum,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<T: CoordNum> From<LineString<T>> for Geometry<T>
impl<T: CoordNum> From<LineString<T>> for Geometry<T>
source§fn from(x: LineString<T>) -> Self
fn from(x: LineString<T>) -> Self
source§impl<T: CoordNum> From<MultiLineString<T>> for Geometry<T>
impl<T: CoordNum> From<MultiLineString<T>> for Geometry<T>
source§fn from(x: MultiLineString<T>) -> Self
fn from(x: MultiLineString<T>) -> Self
source§impl<T: CoordNum> From<MultiPoint<T>> for Geometry<T>
impl<T: CoordNum> From<MultiPoint<T>> for Geometry<T>
source§fn from(x: MultiPoint<T>) -> Self
fn from(x: MultiPoint<T>) -> Self
source§impl<T: CoordNum> From<MultiPolygon<T>> for Geometry<T>
impl<T: CoordNum> From<MultiPolygon<T>> for Geometry<T>
source§fn from(x: MultiPolygon<T>) -> Self
fn from(x: MultiPolygon<T>) -> Self
source§impl<T: PartialEq + CoordNum> PartialEq<Geometry<T>> for Geometry<T>
impl<T: PartialEq + CoordNum> PartialEq<Geometry<T>> for Geometry<T>
source§impl<T> RelativeEq<Geometry<T>> for Geometry<T>where
T: AbsDiffEq<Epsilon = T> + CoordNum + RelativeEq,
impl<T> RelativeEq<Geometry<T>> for Geometry<T>where
T: AbsDiffEq<Epsilon = T> + CoordNum + RelativeEq,
source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::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);
source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
source§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
RelativeEq::relative_eq
.source§impl<T: CoordNum> TryFrom<Geometry<T>> for Line<T>
impl<T: CoordNum> TryFrom<Geometry<T>> for Line<T>
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.
source§impl<T: CoordNum> TryFrom<Geometry<T>> for LineString<T>
impl<T: CoordNum> TryFrom<Geometry<T>> for LineString<T>
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.
source§impl<T: CoordNum> TryFrom<Geometry<T>> for MultiLineString<T>
impl<T: CoordNum> TryFrom<Geometry<T>> for MultiLineString<T>
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.
source§impl<T: CoordNum> TryFrom<Geometry<T>> for MultiPoint<T>
impl<T: CoordNum> TryFrom<Geometry<T>> for MultiPoint<T>
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.
source§impl<T: CoordNum> TryFrom<Geometry<T>> for MultiPolygon<T>
impl<T: CoordNum> TryFrom<Geometry<T>> for MultiPolygon<T>
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.
source§impl<T: CoordNum> TryFrom<Geometry<T>> for Point<T>
impl<T: CoordNum> TryFrom<Geometry<T>> for Point<T>
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.
source§impl<T: CoordNum> TryFrom<Geometry<T>> for Polygon<T>
impl<T: CoordNum> TryFrom<Geometry<T>> for Polygon<T>
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.
source§impl<T: CoordNum> TryFrom<Geometry<T>> for Rect<T>
impl<T: CoordNum> TryFrom<Geometry<T>> for Rect<T>
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.
source§impl<T: CoordNum> TryFrom<Geometry<T>> for Triangle<T>
impl<T: CoordNum> TryFrom<Geometry<T>> for Triangle<T>
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.