pub struct Point { /* private fields */ }Expand description
A geographic point with longitude/latitude coordinates.
This wraps geo::Point and provides additional functionality for
GeoJSON conversion, distance calculations, and other operations.
§Examples
use spatio_types::geo::Point;
let nyc = Point::new(-74.0060, 40.7128);
assert_eq!(nyc.x(), -74.0060);
assert_eq!(nyc.y(), 40.7128);Implementations§
Source§impl Point
impl Point
Sourcepub fn into_inner(self) -> Point<f64>
pub fn into_inner(self) -> Point<f64>
Convert into the inner geo::Point.
Sourcepub fn haversine_distance(&self, other: &Point) -> f64
pub fn haversine_distance(&self, other: &Point) -> f64
Calculate haversine distance to another point in meters.
Uses the haversine formula which accounts for Earth’s curvature.
§Examples
use spatio_types::geo::Point;
let nyc = Point::new(-74.0060, 40.7128);
let la = Point::new(-118.2437, 34.0522);
let distance = nyc.haversine_distance(&la);
assert!(distance > 3_900_000.0); // ~3,944 kmSourcepub fn geodesic_distance(&self, other: &Point) -> f64
pub fn geodesic_distance(&self, other: &Point) -> f64
Calculate geodesic distance to another point in meters.
Uses the Vincenty formula which is more accurate than haversine but slightly slower.
§Examples
use spatio_types::geo::Point;
let p1 = Point::new(-74.0060, 40.7128);
let p2 = Point::new(-74.0070, 40.7138);
let distance = p1.geodesic_distance(&p2);Sourcepub fn euclidean_distance(&self, other: &Point) -> f64
pub fn euclidean_distance(&self, other: &Point) -> f64
Calculate euclidean distance to another point.
This calculates straight-line distance in the coordinate space, which is only accurate for small distances.
§Examples
use spatio_types::geo::Point;
let p1 = Point::new(0.0, 0.0);
let p2 = Point::new(3.0, 4.0);
let distance = p1.euclidean_distance(&p2);
assert_eq!(distance, 5.0); // 3-4-5 triangleTrait Implementations§
Source§impl<'de> Deserialize<'de> for Point
impl<'de> Deserialize<'de> for Point
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>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Point
impl StructuralPartialEq for Point
Auto Trait Implementations§
impl Freeze for Point
impl RefUnwindSafe for Point
impl Send for Point
impl Sync for Point
impl Unpin for Point
impl UnwindSafe for Point
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more