Skip to content

H3Net Api H3Index

Richard Vasquez edited this page Feb 3, 2021 · 3 revisions

H3Index

An H3Index is, internally, a readonly 64 bit unsigned long integer wrapped in a readonly struct that has a handful of derivable properties. A breakdown of the bits can be found at [https://h3geo.org/docs/core-library/h3indexing].

Being a readonly type, its value can only be changed via assignment. There are direct mutater assignments available, as well as a fluid interface for chaining assignments together.

Examples:

Constructor plus assignment

H3Index h3 = new H3Index();
h3 = h3.SetResolution(12);

Constructor with fluid assignment

H3Index h3 = new H3Index().SetResolution(12);

Information provided at this point is non-comprehensive. Further information can be found in the source code.

Constructors

  • H3Index() - Will result in an H3Index that is considered invalid.

  • H3Index(ulong number) - Undetermined result, depends on each of the bits.

  • H3Index(int res, int baseCell, int initDigit) - Much higer odds of creating a valid H3Index, depending on the values. There are still combinations that are invalid due to how pentagons work.

    • res - Resolution, should be 0 to 15 inclusive.
    • baseCell - base cell the H3Index is on, should be 0 to 121 inclusive
    • initDigit - should be a value from 0 to 6 inclusive

For all practical putposes, let other data types or the Uber API create your H3Index values.

Properties

  • Value - The actual 64 bit unsigned long.
  • Resolution - Wheat resolution the cell is in
  • BaseCell - What the base cell is the cell is on.
  • LeadingNonZeroDigit - The highest resolution non-sero digit of the cell.
  • IsPentagon - if the cell is a pentagon or not
  • Mode - Whether the H3Index is a cell or a directed edge.
  • HighBit - The value of the highest bit in the H3Index
  • ReservedBits - the value of the reserved bits with the lowest bit shifted to 2^0
  • IsResClassIii - Indicates if the cell is in a resolution known as Claa III.

Methods

The following methods are attached and available to an H3Index. Using a function on the wrong mode will produce unpredictable results.

Cell mode methods

  • decimal CellAreaKm2() - Exact area of a specific cell in square kilometers
  • decimal CellAreaM2() - Exact area of a specific cell in square meters
  • decimal CellAreaRads2() - Exact area of a specific cell in square radians
  • bool IsBeighborTo(H3Index cell) - indicates if the cell parameter is a neighbor sharing an edge
  • H3Index UniDirectionalEdgeTo(H3Index neighbor) - Returns a Unidirectional edge that goes from the originating cell to the neighbor cell.
  • H3Index[] GetUniEdgesFromCell() - Returns an array of edges originating from the cell to all of its neighbors.
  • GeoBoundary ToGeoBoundary() - Returns a GeoBoundary that contains the vertices that make up the cell. As a cell may overlap more than one face, there exists the possibility that additional vertices will be added between the main corner points of a pentagon or hexagon.
  • List<H3Index> KRing(int k) - Generates a ring of hexagons that is k radius away from the cell, with a k value of 0 indicating only the origin cell.
  • Dictionary<H3Index, int> KRingDistances(int k) - Returns a dictionary of cells within k distance, with the KeyValuePair being an H3Index cell in range, and the value being its distance from the origin.
  • Tuple<int, List<H3Index>> HexRange(int k) - Item1 of the tuple being 0 means it worked correctly. Item2 of the tuple will have a list of H3Index cells within k distance.
  • Tuple<int, List<H3Index>> HexRing(int k) - Item1 of the tuple being 0 means it worked correctly. Item2 Will be the H3Index cells that make up the hollow "ring" of heagons k distance away from the origin cell.
  • Tuple<int, List<H3Index>> LineTo(H3Index destination) - Item1 of the tuple being 0 means it worked correctly. Item2 returns a "line" of connecting cells from the origin to the destination.
  • int LineSize(H3Index destination) - Returns how many cells the line connecting from the origin to the destination will be.
  • int DistanceTo(H3Index destination) - If the distance is not too far, or there's no pentagon to cross, this will determine how far away another cell is.
  • Tuple<int, CoordIj> ToLocalIjExperimental(H3Index h3) - This provides the CoordIj location of the h3 Index in relation to the origin cell being used as a reference point.
  • H3Index ToParent(int res) - Returns a courser resolution (res) cell that this cell is "under".
  • List<H3Index> ToChildren(int res) - Returns the collection of finer resolution (res) cells that are "under" the origin cell.
  • long MaxH3ToChildrenSize(int res) - Returns the amount of children that will result from ToChildren().
  • H3Index ToCenterChild(int res) - Returns the center child of the given hexagon at the specified resolution

Edge mode methods

  • decimal EdgeLengthKM() - Exact length of a unidirectional edge in kilometers
  • decimal EdgeLengthM() - Exact length of a unidirectional edge in meters
  • decimal EdgeLengthRads() - Exact length of a uniderectional edge in radians
  • bool IsValidUniEdge() - Indicates if the unidirectional edge is valid
  • H3Index OriginFromUniDirectionalEdge() - Returns the originating cell of an edge
  • H3Index DestinationFromUniDirectionalEdge() - Returns the destination cell of an edge
  • Tuple<H3Index, H3Index> GetH3IndexesFromUniEdge() - Returns a tuple containing the orgin cell and the destination cell
  • GeoBoundary UniEdgeToGeoBoundary() - Provides the coordinates that define the edge