pub struct LatLon { /* private fields */ }Expand description
Implementations§
Source§impl LatLon
impl LatLon
Sourcepub fn create(lat: f64, lon: f64) -> Result<LatLon, Error>
pub fn create(lat: f64, lon: f64) -> Result<LatLon, Error>
Tries to create a latitude/longitude point from a lat/lon pair. First checks if the values are valid:
- Latitude must be in range [-90,90]
- Longitude must be in range [-180,180]
§Errors
Returns Error::InvalidCoord if either latitude or longitude are invalid.
§Usage
use geoconvert::LatLon;
let coord = LatLon::create(40.748333, -73.985278);
assert!(coord.is_ok());
let coord = coord.unwrap();
assert_eq!(coord.latitude(), 40.748333);
assert_eq!(coord.longitude(), -73.985278);
let invalid_coord_lat = LatLon::create(100.0, 0.0);
assert!(invalid_coord_lat.is_err());
let invalid_coord_lon = LatLon::create(0.0, -200.0);
assert!(invalid_coord_lon.is_err());Sourcepub fn latitude(&self) -> f64
pub fn latitude(&self) -> f64
Returns the latitude value.
§Example
use geoconvert::LatLon;
let coord = LatLon::create(40.748333, -73.985278).unwrap();
assert_eq!(coord.latitude(), 40.748333);Sourcepub fn longitude(&self) -> f64
pub fn longitude(&self) -> f64
Returns the longitude value.
§Example
use geoconvert::LatLon;
let coord = LatLon::create(40.748333, -73.985278).unwrap();
assert_eq!(coord.longitude(), -73.985278);Sourcepub fn is_north(&self) -> bool
pub fn is_north(&self) -> bool
Returns whether the current point is in the northern hemisphere.
§Example
use geoconvert::LatLon;
let coord = LatLon::create(40.748333, -73.985278).unwrap();
assert!(coord.is_north());
let coord = LatLon::create(-40.748333, -73.985278).unwrap();
assert!(!coord.is_north());Sourcepub fn haversine(&self, other: &LatLon) -> f64
pub fn haversine(&self, other: &LatLon) -> f64
Returns the distance in meters between two LatLon points
using the haversine formula.
Uses the mean radius of the Earth
in the calculation: 6371.0088
Sourcepub fn from_utmups(value: &UtmUps) -> LatLon
pub fn from_utmups(value: &UtmUps) -> LatLon
Converts from UtmUps to LatLon
§Usage
use geoconvert::{LatLon, UtmUps};
let coord = LatLon::create(40.748333, -73.985278).unwrap();
let coord_utm = UtmUps::create(18, true, 585664.121, 4511315.422).unwrap();
let converted = LatLon::from_utmups(&coord_utm);
// Check if the converted coordinate is accurate to 6 decimals (same as reference)
assert!((converted.latitude() - coord.latitude()).abs() < 1e-6);
assert!((converted.longitude() - coord.longitude()).abs() < 1e-6);Sourcepub fn to_utmups(&self) -> UtmUps
pub fn to_utmups(&self) -> UtmUps
Converts from LatLon to UtmUps
§Usage
use geoconvert::{LatLon, UtmUps};
let coord = LatLon::create(40.748333, -73.985278).unwrap();
let coord_utm = UtmUps::create(18, true, 585664.121, 4511315.422).unwrap();
let converted = coord.to_utmups();
assert_eq!(converted.zone(), coord_utm.zone());
assert_eq!(converted.is_north(), coord_utm.is_north());
// Check if the converted coordinate is accurate to 3 decimals (same as reference)
assert!((converted.easting() - coord_utm.easting()).abs() < 1e-3);
assert!((converted.northing() - coord_utm.northing()).abs() < 1e-3);Sourcepub fn from_mgrs(value: &Mgrs) -> LatLon
pub fn from_mgrs(value: &Mgrs) -> LatLon
§Usage
use geoconvert::{LatLon, Mgrs};
let coord = LatLon::create(40.748333, -73.985278).unwrap();
let coord_mgrs = Mgrs::parse_str("18TWL856641113154").unwrap();
let converted = LatLon::from_mgrs(&coord_mgrs);
// Check if the converted coordinate is accurate to 6 decimals (same as reference)
assert!((converted.latitude() - coord.latitude()).abs() < 1e-6);
assert!((converted.longitude() - coord.longitude()).abs() < 1e-6);Trait Implementations§
impl Copy for LatLon
Auto Trait Implementations§
impl Freeze for LatLon
impl RefUnwindSafe for LatLon
impl Send for LatLon
impl Sync for LatLon
impl Unpin for LatLon
impl UnwindSafe for LatLon
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