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>

source

pub fn into_point(self) -> Option<Point<T>>

👎Deprecated: 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.,));
source

pub fn into_line_string(self) -> Option<LineString<T>>

👎Deprecated: 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.

source

pub fn into_line(self) -> Option<Line<T>>

👎Deprecated: 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.

source

pub fn into_polygon(self) -> Option<Polygon<T>>

👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<Polygon>

If this Geometry is a Polygon, then return that, else None.

source

pub fn into_multi_point(self) -> Option<MultiPoint<T>>

👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiPoint>

If this Geometry is a MultiPoint, then return that, else None.

source

pub fn into_multi_line_string(self) -> Option<MultiLineString<T>>

👎Deprecated: Will be removed in an upcoming version. Switch to std::convert::TryInto<MultiLineString>

If this Geometry is a MultiLineString, then return that, else None.

source

pub fn into_multi_polygon(self) -> Option<MultiPolygon<T>>

👎Deprecated: 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§

source§

impl<T: AbsDiffEq<Epsilon = T> + CoordNum> AbsDiffEq<Geometry<T>> for Geometry<T>

source§

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

type Epsilon = T

Used for specifying relative comparisons.
source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
source§

impl<T: Clone + CoordNum> Clone for Geometry<T>

source§

fn clone(&self) -> Geometry<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + CoordNum> Debug for Geometry<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

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>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: CoordNum> From<Line<T>> for Geometry<T>

source§

fn from(x: Line<T>) -> Self

Converts to this type from the input type.
source§

impl<T: CoordNum> From<LineString<T>> for Geometry<T>

source§

fn from(x: LineString<T>) -> Self

Converts to this type from the input type.
source§

impl<T: CoordNum> From<MultiLineString<T>> for Geometry<T>

source§

fn from(x: MultiLineString<T>) -> Self

Converts to this type from the input type.
source§

impl<T: CoordNum> From<MultiPoint<T>> for Geometry<T>

source§

fn from(x: MultiPoint<T>) -> Self

Converts to this type from the input type.
source§

impl<T: CoordNum> From<MultiPolygon<T>> for Geometry<T>

source§

fn from(x: MultiPolygon<T>) -> Self

Converts to this type from the input type.
source§

impl<T: CoordNum> From<Point<T>> for Geometry<T>

source§

fn from(x: Point<T>) -> Self

Converts to this type from the input type.
source§

impl<T: CoordNum> From<Polygon<T>> for Geometry<T>

source§

fn from(x: Polygon<T>) -> Self

Converts to this type from the input type.
source§

impl<T: CoordNum> From<Rect<T>> for Geometry<T>

source§

fn from(x: Rect<T>) -> Self

Converts to this type from the input type.
source§

impl<T: CoordNum> From<Triangle<T>> for Geometry<T>

source§

fn from(x: Triangle<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Hash + CoordNum> Hash for Geometry<T>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T: PartialEq + CoordNum> PartialEq<Geometry<T>> for Geometry<T>

source§

fn eq(&self, other: &Geometry<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

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

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

The default relative tolerance for testing values that are far-apart. Read more
source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon ) -> bool

The inverse of RelativeEq::relative_eq.
source§

impl<T> Serialize for Geometry<T>where T: Serialize + CoordNum,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

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.

§

type Error = Error

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

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

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.

§

type Error = Error

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

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

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.

§

type Error = Error

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

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

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.

§

type Error = Error

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

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

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.

§

type Error = Error

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

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

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.

§

type Error = Error

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

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

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.

§

type Error = Error

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

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

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.

§

type Error = Error

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

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

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.

§

type Error = Error

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

fn try_from(geom: Geometry<T>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<T: Eq + CoordNum> Eq for Geometry<T>

source§

impl<T: CoordNum> StructuralEq for Geometry<T>

source§

impl<T: CoordNum> StructuralPartialEq for Geometry<T>

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§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,