pub struct UtmUps { /* private fields */ }Expand description
Implementations§
Source§impl UtmUps
impl UtmUps
Sourcepub fn create(
zone: i32,
northp: bool,
easting: f64,
northing: f64,
) -> Result<UtmUps, Error>
pub fn create( zone: i32, northp: bool, easting: f64, northing: f64, ) -> Result<UtmUps, Error>
Tries to create a UTM or UPS point from its constituent parts. Zone
of 0 designates UPS, otherwise it is UTM.
§Errors
Returns Error::InvalidZone if the zone is outside the range [0, 60].
Returns Error::InvalidCoord if the coordinate is otherwise invalid.
§Usage
use geoconvert::UtmUps;
let coord = UtmUps::create(18, true, 585664.121, 4511315.422);
assert!(coord.is_ok());
let coord = coord.unwrap();
assert_eq!(coord.zone(), 18);
assert_eq!(coord.is_north(), true);
assert!((coord.easting() - 585664.121).abs() < 1e-3);
assert!((coord.northing() - 4511315.422).abs() < 1e-3);
let invalid_coord_zone_neg = UtmUps::create(-10, true, 585664.121, 4511315.422);
assert!(invalid_coord_zone_neg.is_err());
let invalid_coord_zone_too_big = UtmUps::create(70, true, 585664.121, 4511315.422);
assert!(invalid_coord_zone_too_big.is_err());Sourcepub fn zone(&self) -> i32
pub fn zone(&self) -> i32
Returns the UTM zone.
§Example
use geoconvert::UtmUps;
let coord = UtmUps::create(18, true, 585664.121, 4511315.422).unwrap();
assert_eq!(coord.zone(), 18);Sourcepub fn is_north(&self) -> bool
pub fn is_north(&self) -> bool
Returns whether the coordinate is in the northern hemisphere.
§Example
use geoconvert::UtmUps;
let coord = UtmUps::create(18, true, 585664.121, 4511315.422).unwrap();
assert_eq!(coord.is_north(), true);Sourcepub fn easting(&self) -> f64
pub fn easting(&self) -> f64
Returns the UTM easting.
§Example
use geoconvert::UtmUps;
let coord = UtmUps::create(18, true, 585664.121, 4511315.422).unwrap();
assert!((coord.easting() - 585664.121).abs() < 1e-3);Sourcepub fn northing(&self) -> f64
pub fn northing(&self) -> f64
Returns the UTM northing.
§Example
use geoconvert::UtmUps;
let coord = UtmUps::create(18, true, 585664.121, 4511315.422).unwrap();
assert!((coord.northing() - 4511315.422).abs() < 1e-3);Sourcepub fn from_latlon(value: &LatLon) -> UtmUps
pub fn from_latlon(value: &LatLon) -> 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 to_latlon(&self) -> LatLon
pub fn to_latlon(&self) -> 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 from_mgrs(value: &Mgrs) -> UtmUps
pub fn from_mgrs(value: &Mgrs) -> UtmUps
§Usage
use geoconvert::{Mgrs, UtmUps};
let coord = Mgrs::parse_str("18TWL856641113154").unwrap();
let coord_utm = UtmUps::create(18, true, 585664.15, 4511315.45).unwrap();
let converted = coord.to_utmups();
// Check if the converted coordinate is accurate to 6 decimals (same as reference)
assert_eq!(coord_utm.zone(), converted.zone());
assert_eq!(coord_utm.is_north(), converted.is_north());
assert!((coord_utm.easting() - converted.easting()).abs() < 1e-2);
assert!((coord_utm.northing() - converted.northing()).abs() < 1e-2);Sourcepub fn to_mgrs(&self, precision: i32) -> Mgrs
pub fn to_mgrs(&self, precision: i32) -> Mgrs
§Usage
use geoconvert::{Mgrs, UtmUps};
let coord = Mgrs::parse_str("18TWL856641113154").unwrap();
let coord_utm = UtmUps::create(18, true, 585664.15, 4511315.45).unwrap();
let converted = Mgrs::from_utmups(&coord_utm, 6);
// Check if the converted coordinate is accurate to 6 decimals (same as reference)
assert_eq!(coord.zone(), converted.zone());
assert_eq!(coord.is_north(), converted.is_north());
assert!((coord.easting() - converted.easting()).abs() < 1e-2);
assert!((coord.northing() - converted.northing()).abs() < 1e-2);
assert_eq!(coord.precision(), converted.precision());Trait Implementations§
impl Copy for UtmUps
Auto Trait Implementations§
impl Freeze for UtmUps
impl RefUnwindSafe for UtmUps
impl Send for UtmUps
impl Sync for UtmUps
impl Unpin for UtmUps
impl UnwindSafe for UtmUps
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