Struct h3ron::H3Cell

source ·
pub struct H3Cell(/* private fields */);
Expand description

H3 Index representing a H3 Cell (hexagon)

Implementations§

source§

impl H3Cell

source

pub fn from_point(pt: Point<f64>, h3_resolution: u8) -> Result<Self, Error>

Build a new Index from a Point.

Returns

If the built index is invalid, returns an Error.

source

pub fn from_coordinate(c: Coord<f64>, h3_resolution: u8) -> Result<Self, Error>

Build a new Index from coordinates.

Returns

If the built index is invalid, returns an Error.

source

pub fn is_parent_of(&self, other: &Self) -> Result<bool, Error>

Checks if self is a parent of other

source

pub fn is_child_of(&self, other: &Self) -> Result<bool, Error>

Checks if other is a parent of self

source

pub fn contains(&self, other: &Self) -> Result<bool, Error>

Checks if self is a parent of other

source

pub fn get_parent(&self, parent_resolution: u8) -> Result<Self, Error>

Retrieves the parent (or grandparent, etc) cell of the given cell

source

pub fn get_children( &self, child_resolution: u8 ) -> Result<IndexVec<Self>, Error>

Retrieves all children of self at resolution child_resolution

source

pub fn are_neighbor_cells(&self, other: Self) -> Result<bool, Error>

Checks if the current index and other are neighbors.

source

pub fn grid_disk(&self, k: u32) -> Result<IndexVec<Self>, Error>

grid_disk produces all cells within k distance of the origin cell.

k=0 is defined as the origin cell, k=1 is defined as k=0 + all neighboring cells, and so on.

Note

For repeated building of grid disks, there is also super::iter::GridDiskBuilder.

source

pub fn grid_ring_unsafe(&self, k: u32) -> Result<IndexVec<Self>, Error>

hollow hexagon ring at self

source

pub fn grid_disk_distances( &self, k_min: u32, k_max: u32 ) -> Result<Vec<(u32, Self)>, Error>

Retrieves indexes around self through K Rings.

Arguments
  • k_min - the minimum k ring distance
  • k_max - the maximum k ring distance
Returns

A Vec of (u32, Index) tuple is returned. The u32 value is the K Ring distance of the Index value.

Note

For repeated building of k-rings, there is also super::iter::GridDiskBuilder.

source

pub fn grid_disk_distances_unsafe( &self, k_min: u32, k_max: u32 ) -> Result<Vec<(u32, Self)>, Error>

source

pub fn grid_distance_to(&self, other: Self) -> Result<usize, Error>

Retrieves the number of K Rings between self and other.

For distance in miles or kilometers use haversine algorithms.

source

pub fn is_pentagon(&self) -> bool

determines if an H3 cell is a pentagon

source

pub fn get_base_cell_number(&self) -> u8

returns the base cell “number” (0 to 121) of the provided H3 cell

source

pub fn directed_edge_to( &self, destination: Self ) -> Result<H3DirectedEdge, Error>

Gets the directed edge from self to destination

Returns

If the built index is invalid, returns an Error. Use the unidirectional_edge_to_unchecked to avoid error.

source

pub fn directed_edges(&self) -> Result<IndexVec<H3DirectedEdge>, Error>

Retrieves all directed H3 edges around self where self is the origin

For repeated creation of H3DirectedEdge around a H3Cell also see crate::iter::H3DirectedEdgesBuilder, which is more efficient.

source

pub fn area_avg_m2(resolution: u8) -> Result<f64, Error>

get the average cell area at resolution in square meters.

use h3ron::H3Cell;

assert_eq!(15047, H3Cell::area_avg_m2(10).unwrap() as i32);
source

pub fn area_avg_km2(resolution: u8) -> Result<f64, Error>

get the average cell area at resolution in square kilometers.

source

pub fn area_m2(&self) -> Result<f64, Error>

Retrieves the exact area of self in square meters

source

pub fn area_km2(&self) -> Result<f64, Error>

Retrieves the exact area of self in square kilometers

source

pub fn area_rads2(&self) -> Result<f64, Error>

Retrieves the exact area of self in square radians

source

pub fn center_child(&self, resolution: u8) -> Result<Self, Error>

returns the center child of self at the specified resolution.

source§

impl H3Cell

source

pub fn from_localij(origin_cell: Self, coordij: CoordIj) -> Result<Self, Error>

Produces an H3Cell for the given coordij coordinates anchored by origin_cell.

The coordinate space used by this function may have deleted regions or warping due to pentagonal distortion.

Failure may occur if the index is too far away from the origin or if the index is on the other side of a pentagon.

This function’s output is not guaranteed to be compatible across different versions of H3.

source

pub fn to_localij(&self, origin_cell: Self) -> Result<CoordIj, Error>

Produces CoordIj coordinates for this H3Cell instance anchored by an origin H3Cell origin_cell.

The coordinate space used by this function may have deleted regions or warping due to pentagonal distortion.

Failure may occur if the index is too far away from the origin or if the index is on the other side of a pentagon.

This function’s output is not guaranteed to be compatible across different versions of H3.

Trait Implementations§

source§

impl CellAndValue<()> for H3Cell

source§

fn cell(&self) -> H3Cell

source§

fn value(self)

source§

impl Clone for H3Cell

source§

fn clone(&self) -> H3Cell

Returns a copy 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 H3Cell

source§

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

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

impl Deref for H3Cell

§

type Target = u64

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<'de> Deserialize<'de> for H3Cell

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 FromH3Index for H3Cell

source§

fn from_h3index(h3index: H3Index) -> Self

source§

impl FromStr for H3Cell

source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parse a hex-representation of a H3Cell from a string.

With the parse feature enabled this function is also able to parse strings containing integers and a custom coordinate-based format in the form of "x,y,resolution".

Examples:

use h3ron::{H3Cell, Index};
use std::str::FromStr;

let index = H3Cell::from_str("89283080ddbffff").unwrap();

#[cfg(feature = "parse")]
{
    // parse from a string containing an integer
    let index = H3Cell::from_str("617700169518678015").unwrap();

    // parse from coordinates and resolution
    let index = H3Cell::from_str("23.3,12.3,6").unwrap();
}
§

type Err = Error

The associated error which can be returned from parsing.
source§

impl Hash for H3Cell

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Index for H3Cell

source§

fn h3index(&self) -> H3Index

Get the u64 H3 Index address
source§

fn new(h3index: H3Index) -> Self

create an index from the given u64. Read more
source§

fn validate(&self) -> Result<(), Error>

Checks the validity of the index
source§

fn resolution(&self) -> u8

Gets the index resolution (0-15)
source§

fn is_valid(&self) -> bool

Checks the validity of the index
source§

fn direction(&self) -> H3Direction

Retrieves the direction of the current index Read more
source§

fn direction_checked(&self) -> Result<H3Direction, Error>

Retrieves the direction of the current index Read more
source§

fn direction_to_parent_resolution( &self, target_resolution: u8 ) -> Result<H3Direction, Error>

Retrieves the direction of the current index relative to a parent at target_resolution
source§

impl Ord for H3Cell

source§

fn cmp(&self, other: &H3Cell) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for H3Cell

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for H3Cell

source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for H3Cell

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 ToCoordinate for H3Cell

source§

fn to_coordinate(&self) -> Result<Coord<f64>, Self::Error>

the centroid coordinate of the h3 index

§

type Error = Error

source§

impl ToPolygon for H3Cell

source§

fn to_polygon(&self) -> Result<Polygon<f64>, Self::Error>

the polygon spanning the area of the index

§

type Error = Error

source§

impl ToString for H3Cell

source§

fn to_string(&self) -> String

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

impl TryFrom<u64> for H3Cell

convert to index including validation

§

type Error = Error

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

fn try_from(h3index: H3Index) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Copy for H3Cell

source§

impl Eq for H3Cell

source§

impl StructuralEq for H3Cell

source§

impl StructuralPartialEq for H3Cell

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
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<IX> HasH3Resolution for IX
where IX: Index,

source§

fn h3_resolution(&self) -> u8

Gets the index resolution (0-15)
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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

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>,

§

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>,

§

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<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

source§

fn is_within(&self, b: &G2) -> bool

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,