Skip to main content

Coordinate

Struct Coordinate 

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

緯度・経度・高度を表す型。

内部的には下記のような構造体として定義されており、空間 ID 上で扱える座標に対する制約が常に満たされる。

この型は PartialOrd を実装していますが、これは主に BTreeSetBTreeMap といった順序付きコレクションにおける格納および探索を目的としたものであり、。空間的な位置関係における「大小」を意味するものではない。

pub struct Coordinate {
    latitude: f64,
    longitude: f64,
    altitude: f64,
}

Implementations§

Source§

impl Coordinate

Source

pub fn new(latitude: f64, longitude: f64, altitude: f64) -> Result<Self, Error>

指定された緯度・経度・高度から Coordinate を生成する。

各引数は、空間 ID 上で扱える座標として有効な範囲に収まっている必要がある。 範囲外の値が指定された場合、この関数は対応するエラーを返す。

§引数
  • latitude - 緯度(-85.0511 〜 85.0511)
  • longitude - 経度(-180.0 〜 180.0)
  • altitude - 高度(-33,554,432.0 〜 33,554,432.0)
§戻り値
  • 有効な値が指定された場合は Ok(Coordinate) を返す。
  • いずれかの値が範囲外の場合は、対応する Error を返す。
§Example
let coord = Coordinate::new(35.0, 139.0, 10.0).unwrap();

assert_eq!(coord.latitude(), 35.0);
assert_eq!(coord.longitude(), 139.0);
assert_eq!(coord.altitude(), 10.0);
Source

pub unsafe fn new_unchecked( latitude: f64, longitude: f64, altitude: f64, ) -> Coordinate

値の妥当性検証を行わずに Coordinate を生成する。

この関数は緯度・経度・高度に対する範囲チェックを一切行わない。 呼び出し側は、渡す値が空間 ID 上で扱える有効な範囲に収まっていることを 保証する責任を負う。

§Safety

この関数は unsafe である。 不正な値を指定した場合、Coordinate が前提としている不変条件が破られ、 以降の処理で未定義な振る舞いまたは論理的な不整合を引き起こす可能性があるため、入力値の正当性が外部で十分に検証されている場合にのみ使用せよ。

Source

pub fn latitude(&self) -> f64

緯度を返す。

返される値は度数法(degree)で表され、 常にWEBメルカトル上で扱える有効な範囲(-85.0511 〜 85.0511)内に収まる。

§Example
let coord = Coordinate::new(43.068564, 41.3507138, 30.0).unwrap();
assert_eq!(coord.latitude(), 43.068564);
Source

pub fn longitude(&self) -> f64

経度を返す。

返される値は度数法(degree)で表され、 常に -180.0 〜 180.0 の範囲内に収まる。

§Example
let coord = Coordinate::new(35.4095198,136.7566027, 0.0).unwrap();
assert_eq!(coord.longitude(), 136.7566027);
Source

pub fn altitude(&self) -> f64

高度を返す。

される値はメートル(m)で表され、 常に-33,554,432.0 ..= 33,554,432.0の範囲内に収まる。

§Example
let coord = Coordinate::new(34.9851603, 135.7584294, 20.0).unwrap();
assert_eq!(coord.altitude(), 20.0);
Source

pub fn set_latitude(&mut self, latitude: f64) -> Result<(), Error>

緯度を設定する。

指定された値が有効な範囲外の場合、この関数はエラーを返し、 内部の値は変更されない。

§Example
let mut coord = Coordinate::new(35.0, 41.3507138, 30.0).unwrap();
coord.set_latitude(43.068564);
assert_eq!(coord.latitude(), 43.068564);
Source

pub fn set_longitude(&mut self, longitude: f64) -> Result<(), Error>

経度を設定する。

指定された値が有効な範囲外の場合、この関数はエラーを返し、 内部の値は変更されない。

§Example
let mut coord = Coordinate::new(35.4095198,130.0, 0.0).unwrap();
coord.set_longitude(136.7566027);
assert_eq!(coord.longitude(), 136.7566027);
Source

pub fn set_altitude(&mut self, altitude: f64) -> Result<(), Error>

高度を設定する。

単位はメートル(m)である。 指定された値が有効な範囲外の場合、この関数はエラーを返し、 内部の値は変更されない。

§Example
let mut coord = Coordinate::new(34.9851603, 135.7584294, -10.0).unwrap();
coord.set_altitude(20.0);
assert_eq!(coord.altitude(), 20.0);
Source

pub fn single_id(&self, z: u8) -> Result<SingleId, Error>

この座標を、指定されたズームレベルに対応する SingleId に変換する。

§引数
  • z - 空間 ID のズームレベル
§戻り値
  • 指定されたズームレベルに対応する SingleId
§Example
let mut coord = Coordinate::new(34.9851603, 135.7584294, 20.0).unwrap();
assert_eq!(
    &coord.single_id(24),
    &SingleId::new(24, 10, 14715409, 6646263)
)
Source

pub fn distance(&self, other: &Coordinate) -> f64

他の Coordinate との距離をメートル単位で返す。

  • 単位はメートル(m)です
  • WGS84 楕円体を前提とした近似距離。
§引数
  • other - 距離を計算する対象の座標
§戻り値
  • 2 点間の距離(メートル)
§Example
let coord_tokyo = Coordinate::new(35.681382, 139.76608399999998, 0.0).unwrap();
let coord_sinagawa = Coordinate::new(35.630152, 139.74044000000004, 10.0).unwrap();
let d = coord_tokyo.distance(&coord_sinagawa);
assert_eq!(&d, &6140.165513581259);
Source

pub fn eq_epsilon(&self, other: &Coordinate, epsilon: f64) -> bool

Coordinateが同じ位置にあるかを判定します 2点間の直線距離が epsilon 以内にあるかを判定します

Source

pub fn center_gravity<I>(coordinates: I) -> Coordinate

与えられた座標群の重心を計算する。

この関数は IntoIterator を受け入れるため、スライス &[Coordinate]Vec<Coordinate>、または iter_coords() などのイテレータを直接渡すことができる。 内部で Borrow トレイトを利用しているため、要素が実体か参照かを問わず動作する。

座標群が空の場合は、Coordinate::default() を返す。

§パラメーター
  • coordinates — 重心を計算する対象となる座標の集合(イテレータ、スライス、Vecなど)
§動作例

スライスからの計算:

let points = [
    Coordinate::new(0.0, 0.0, 10.0).unwrap(),
    Coordinate::new(10.0, 10.0, 20.0).unwrap(),
];
let center = Coordinate::center_gravity(&points);
assert_eq!(center.latitude(), 5.0);

Trait Implementations§

Source§

impl Clone for Coordinate

Source§

fn clone(&self) -> Coordinate

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Coordinate

Source§

impl CoverSingleIds for Coordinate

Source§

fn cover_single_ids( &self, z: u8, ) -> Result<impl Iterator<Item = SingleId>, Error>

指定されたズームレベルのSingleIdを出力する。
Source§

impl Debug for Coordinate

Source§

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

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

impl Default for Coordinate

緯度・経度・高度のすべてが 0.0 に設定された座標を返す。

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Coordinate

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 From<Coordinate> for Ecef

Source§

fn from(value: Coordinate) -> Self

CoordinateEcefへの変換。

let coord = Coordinate::new(43.068564, 41.3507138, 30.0).unwrap();
let ecef: Ecef = coord.into();
print!("{},{},{}", ecef.x(), ecef.y(), ecef.z());
assert_eq!(ecef.x(), 3503254.6369501497);
assert_eq!(ecef.y(), 3083182.6924748584);
assert_eq!(ecef.z(), 4333089.862951963);
Source§

impl PartialEq for Coordinate

Source§

fn eq(&self, other: &Coordinate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Coordinate

Source§

fn partial_cmp(&self, other: &Coordinate) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Point for Coordinate

Source§

impl Serialize for Coordinate

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 StructuralPartialEq for Coordinate

Source§

impl TryFrom<Ecef> for Coordinate

Source§

fn try_from(value: Ecef) -> Result<Self, Self::Error>

地心直交座標系(ECEF)から地理座標(緯度・経度・高度)への変換。

Source§

type Error = Error

The type returned in the event of a conversion error.

Auto Trait Implementations§

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V