UtmUps

Struct UtmUps 

Source
pub struct UtmUps { /* private fields */ }
Expand description

Representation of a WGS84 UTM / UPS point. If converted to from lat/lon, it will automatically determine whether it should be UTM/UPS. It becomes a UPS coordinate if the latitude is outside the range [-84,84]. A zone value of 0 designates UPS.

Implementations§

Source§

impl UtmUps

Source

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());
Source

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

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

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

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

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

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

pub fn from_mgrs(value: &Mgrs) -> UtmUps

Converts from Mgrs to 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);
Source

pub fn to_mgrs(&self, precision: i32) -> Mgrs

Converts from UtmUps to 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§

Source§

impl Clone for UtmUps

Source§

fn clone(&self) -> UtmUps

Returns a duplicate 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 Debug for UtmUps

Source§

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

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

impl Display for UtmUps

Source§

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

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

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.