Class H3Core
This class is thread safe and can be used as a singleton.
Any function in this class may throw H3Exception.
-
Method Summary
Modifier and TypeMethodDescriptionbooleanareNeighborCells(long a, long b) Returnstrueif the two indexes are neighbors.booleanareNeighborCells(String a, String b) Returnstrueif the two indexes are neighbors.cellAddressesToMultiPolygon(Collection<String> h3Addresses, boolean geoJson) Create polygons from a set of contiguous indexesdoubleCalculates the area of the given H3 cell.doubleCalculates the area of the given H3 cell.longcellsToDirectedEdge(long a, long b) Returns a unidirectional edge index representingatowardsb.cellsToDirectedEdge(String a, String b) Returns a unidirectional edge index representingatowardsb.cellsToMultiPolygon(Collection<Long> h3, boolean geoJson) Create polygons from a set of contiguous indexescellToBoundary(long h3) Find the cell boundary in latitude, longitude (degrees) coordinates for the cellcellToBoundary(String h3Address) Find the cell boundary in latitude, longitude (degrees) coordinates for the celllongcellToCenterChild(long h3, int childRes) Returns the center child at the given resolution.cellToCenterChild(String h3, int childRes) Returns the center child at the given resolution.cellToChildren(long h3, int childRes) Provides the children of the index at the given resolution.cellToChildren(String h3Address, int childRes) Provides the children of the index at the given resolution.cellToLatLng(long h3) Find the latitude, longitude (both in degrees) center point of the cell.cellToLatLng(String h3Address) Find the latitude, longitude (degrees) center point of the cell.cellToLocalIj(long origin, long h3) Convertsh3to IJ coordinates in a local coordinate space defined byorigin.cellToLocalIj(String originAddress, String h3Address) Convertsh3Addressto IJ coordinates in a local coordinate space defined byoriginAddress.longcellToParent(long h3, int res) Returns the parent of the index at the given resolution.cellToParentAddress(String h3Address, int res) Returns the parent of the index at the given resolution.longcellToVertex(long h3, int vertexNum) cellToVertex(String h3Address, int vertexNum) cellToVertexes(long h3) cellToVertexes(String h3Address) compactCellAddresses(Collection<String> h3Addresses) Returns a compacted set of indexes, at possibly coarser resolutions.compactCells(Collection<Long> h3) Returns a compacted set of indexes, at possibly coarser resolutions.directedEdgeToBoundary(long h3) Returns a list of coordinates representing the given edge.Returns a list of coordinates representing the given edge.directedEdgeToCells(long h3) Returns the origin and destination indexes (in that order) of the given unidirectional edge.Returns the origin and destination indexes (in that order) of the given unidirectional edge.doubleedgeLength(long edge, LengthUnit unit) Calculate the edge length of the given H3 edge.doubleedgeLength(String edgeAddress, LengthUnit unit) Calculate the edge length of the given H3 edge.intgetBaseCellNumber(long h3) Returns the base cell number for this index.intgetBaseCellNumber(String h3Address) Returns the base cell number for this index.longgetDirectedEdgeDestination(long h3) Returns the destination index of the given unidirectional edge.Returns the destination index of the given unidirectional edge.longgetDirectedEdgeOrigin(long h3) Returns the origin index of the given unidirectional edge.Returns the origin index of the given unidirectional edge.doublegetHexagonAreaAvg(int res, AreaUnit unit) Returns the average area inunitfor indexes at resolutionres.doublegetHexagonEdgeLengthAvg(int res, LengthUnit unit) Returns the average edge length inunitfor indexes at resolutionres.getIcosahedronFaces(long h3) Find all icosahedron faces intersected by a given H3 index, represented as integers from 0-19.Find all icosahedron faces intersected by a given H3 index, represented as integers from 0-19.longgetNumCells(int res) Returns the number of unique H3 indexes at resolutionres.getPentagonAddresses(int res) Returns a collection of all topologically pentagonal cells at the given resolution.getPentagons(int res) Returns a collection of all topologically pentagonal cells at the given resolution.Returns a collection of all base cells (H3 indexes are resolution 0).Returns a collection of all base cells (H3 indexes are resolution 0).intgetResolution(long h3) Returns the resolution of the provided indexintgetResolution(String h3Address) Returns the resolution of the provided indexdoublegreatCircleDistance(LatLng a, LatLng b, LengthUnit unit) Return the distance along the sphere between two points.gridDisk(long h3, int k) Neighboring indexes in all directions.Neighboring indexes in all directions.gridDiskDistances(long h3, int k) Neighboring indexes in all directions, ordered by distance from the origin index.gridDiskDistances(String h3Address, int k) Neighboring indexes in all directions, ordered by distance from the origin index.gridDiskUnsafe(long h3, int k) Returns in order neighbor traversal.gridDiskUnsafe(String h3Address, int k) Returns in order neighbor traversal.longgridDistance(long a, long b) Returns the distance betweenaandb.longgridDistance(String a, String b) Returns the distance betweenaandb.gridPathCells(long start, long end) Given two H3 indexes, return the line of indexes between them (inclusive of endpoints).gridPathCells(String startAddress, String endAddress) Given two H3 indexes, return the line of indexes between them (inclusive of endpoints).gridRingUnsafe(long h3, int k) Returns in order neighbor traversal, of indexes with distance ofk.gridRingUnsafe(String h3Address, int k) Returns in order neighbor traversal, of indexes with distance ofk.h3ToString(long h3) Converts fromlongrepresentation of an index toStringrepresentation.booleanisPentagon(long h3) Returnstrueif this index is one of twelve pentagons per resolution.booleanisPentagon(String h3Address) Returnstrueif this index is one of twelve pentagons per resolution.booleanisResClassIII(long h3) Determines if an index is Class III or Class II.booleanisResClassIII(String h3Address) Determines if an index is Class III or Class II.booleanisValidCell(long h3) Returns true if this is a valid H3 index.booleanisValidCell(String h3Address) Returns true if this is a valid H3 index.booleanisValidDirectedEdge(long h3) Returnstrueif the given index is a valid unidirectional edge.booleanReturnstrueif the given index is a valid unidirectional edge.booleanisValidVertex(long h3) booleanisValidVertex(String h3Address) longlatLngToCell(double lat, double lng, int res) Find the H3 index of the resolutionrescell containing the lat/lon (in degrees)latLngToCellAddress(double lat, double lng, int res) Find the H3 index of the resolutionrescell containing the lat/lon (in degrees)longlocalIjToCell(long origin, CoordIJ ij) Converts the IJ coordinates to an index, using a local IJ coordinate space anchored byorigin.localIjToCell(String originAddress, CoordIJ ij) Converts the IJ coordinates to an index, using a local IJ coordinate space anchored byorigin.static H3CoreCreate by unpacking the H3 native library to disk and loading it.static H3CorenewInstance(H3CoreLoader.OperatingSystem os, String arch) Create by unpacking the H3 native library to disk and loading it.static H3CoreCreate by using the H3 native library already installed on the system.originToDirectedEdges(long h3) Returns all unidirectional edges originating from the given index.Returns all unidirectional edges originating from the given index.Finds indexes within the given geofence.Finds indexes within the given geofence.longstringToH3(String h3Address) Converts fromStringrepresentation of an index tolongrepresentation.uncompactCellAddresses(Collection<String> h3Addresses, int res) Uncompacts all the given indexes to resolutionres.uncompactCells(Collection<Long> h3, int res) Uncompacts all the given indexes to resolutionres.vertexToLatLng(long h3) vertexToLatLng(String h3Address)
-
Method Details
-
newInstance
Create by unpacking the H3 native library to disk and loading it. The library will attempt to detect the correct operating system and architecture of native library to unpack.- Throws:
SecurityException- Loading the library was not allowed by the SecurityManager.UnsatisfiedLinkError- The library could not be loadedIOException- The library could not be extracted to disk.
-
newInstance
Create by unpacking the H3 native library to disk and loading it. The library will attempt to extract the native library matching the given arguments to disk.- Throws:
SecurityException- Loading the library was not allowed by the SecurityManager.UnsatisfiedLinkError- The library could not be loadedIOException- The library could not be extracted to disk.
-
newSystemInstance
Create by using the H3 native library already installed on the system.- Throws:
SecurityException- The library could not be loadedUnsatisfiedLinkError- The library could not be loaded
-
isValidCell
public boolean isValidCell(long h3) Returns true if this is a valid H3 index. -
isValidCell
Returns true if this is a valid H3 index. -
getBaseCellNumber
public int getBaseCellNumber(long h3) Returns the base cell number for this index. -
getBaseCellNumber
Returns the base cell number for this index. -
isPentagon
public boolean isPentagon(long h3) Returnstrueif this index is one of twelve pentagons per resolution. -
isPentagon
Returnstrueif this index is one of twelve pentagons per resolution. -
latLngToCell
public long latLngToCell(double lat, double lng, int res) Find the H3 index of the resolutionrescell containing the lat/lon (in degrees)- Parameters:
lat- Latitude in degrees.lng- Longitude in degrees.res- Resolution, 0 <= res <= 15- Returns:
- The H3 index.
-
latLngToCellAddress
Find the H3 index of the resolutionrescell containing the lat/lon (in degrees)- Parameters:
lat- Latitude in degrees.lng- Longitude in degrees.res- Resolution, 0 <= res <= 15- Returns:
- The H3 index.
-
cellToLatLng
Find the latitude, longitude (both in degrees) center point of the cell. -
cellToLatLng
Find the latitude, longitude (degrees) center point of the cell. -
cellToBoundary
Find the cell boundary in latitude, longitude (degrees) coordinates for the cell -
cellToBoundary
Find the cell boundary in latitude, longitude (degrees) coordinates for the cell -
gridDisk
Neighboring indexes in all directions.- Parameters:
h3Address- Origin indexk- Number of rings around the origin
-
gridDisk
Neighboring indexes in all directions.- Parameters:
h3- Origin indexk- Number of rings around the origin
-
gridDiskDistances
Neighboring indexes in all directions, ordered by distance from the origin index.- Parameters:
h3Address- Origin indexk- Number of rings around the origin- Returns:
- A list of rings, each of which is a list of addresses. The rings are in order from closest to origin to farthest.
-
gridDiskDistances
Neighboring indexes in all directions, ordered by distance from the origin index.- Parameters:
h3- Origin indexk- Number of rings around the origin- Returns:
- A list of rings, each of which is a list of addresses. The rings are in order from closest to origin to farthest.
-
gridDiskUnsafe
Returns in order neighbor traversal.- Parameters:
h3Address- Origin hexagon indexk- Number of rings around the origin- Returns:
- A list of rings, each of which is a list of addresses. The rings are in order from closest to origin to farthest.
-
gridDiskUnsafe
Returns in order neighbor traversal.- Parameters:
h3- Origin hexagon indexk- Number of rings around the origin- Returns:
- A list of rings, each of which is a list of addresses. The rings are in order from closest to origin to farthest.
-
gridRingUnsafe
Returns in order neighbor traversal, of indexes with distance ofk.- Parameters:
h3Address- Origin indexk- Number of rings around the origin- Returns:
- All indexes
kaway from the origin
-
gridRingUnsafe
Returns in order neighbor traversal, of indexes with distance ofk.- Parameters:
h3- Origin indexk- Number of rings around the origin- Returns:
- All indexes
kaway from the origin
-
gridDistance
Returns the distance betweenaandb. This is the grid distance, or distance expressed in number of H3 cells.In some cases H3 cannot compute the distance between two indexes. This can happen because:
- The indexes are not comparable (difference resolutions, etc)
- The distance is greater than the H3 core library supports
- The H3 library does not support finding the distance between the two cells, because of pentagonal distortion.
- Parameters:
a- An H3 indexb- Another H3 index- Returns:
- Distance between the two in grid cells
-
gridDistance
public long gridDistance(long a, long b) Returns the distance betweenaandb. This is the grid distance, or distance expressed in number of H3 cells.In some cases H3 cannot compute the distance between two indexes. This can happen because:
- The indexes are not comparable (difference resolutions, etc)
- The distance is greater than the H3 core library supports
- The H3 library does not support finding the distance between the two cells, because of pentagonal distortion.
- Parameters:
a- An H3 indexb- Another H3 index- Returns:
- Distance between the two in grid cells
-
cellToLocalIj
Convertsh3to IJ coordinates in a local coordinate space defined byorigin.The local IJ coordinate space may have deleted regions and warping due to pentagon distortion. IJ coordinates are only comparable if they came from the same origin.
This function is experimental, and its output is not guaranteed to be compatible across different versions of H3.
- Parameters:
origin- Anchoring index for the local coordinate space.h3- Index to find the coordinates of.- Returns:
- Coordinates for
h3in the local coordinate space.
-
cellToLocalIj
Convertsh3Addressto IJ coordinates in a local coordinate space defined byoriginAddress.The local IJ coordinate space may have deleted regions and warping due to pentagon distortion. IJ coordinates are only comparable if they came from the same origin.
This function is experimental, and its output is not guaranteed to be compatible across different versions of H3.
- Parameters:
originAddress- Anchoring index for the local coordinate space.h3Address- Index to find the coordinates of.- Returns:
- Coordinates for
h3in the local coordinate space.
-
localIjToCell
Converts the IJ coordinates to an index, using a local IJ coordinate space anchored byorigin.The local IJ coordinate space may have deleted regions and warping due to pentagon distortion. IJ coordinates are only comparable if they came from the same origin.
This function is experimental, and its output is not guaranteed to be compatible across different versions of H3.
- Parameters:
origin- Anchoring index for the local coordinate space.ij- Coordinates in the local IJ coordinate space.- Returns:
- Index represented by
ij
-
localIjToCell
Converts the IJ coordinates to an index, using a local IJ coordinate space anchored byorigin.The local IJ coordinate space may have deleted regions and warping due to pentagon distortion. IJ coordinates are only comparable if they came from the same origin.
This function is experimental, and its output is not guaranteed to be compatible across different versions of H3.
- Parameters:
originAddress- Anchoring index for the local coordinate space.ij- Coordinates in the local IJ coordinate space.- Returns:
- Index represented by
ij
-
gridPathCells
Given two H3 indexes, return the line of indexes between them (inclusive of endpoints).This function may fail to find the line between two indexes, for example if they are very far apart. It may also fail when finding distances for indexes on opposite sides of a pentagon.
Notes:
- The specific output of this function should not be considered stable across library versions. The only guarantees the library provides are that the line length will be `h3Distance(start, end) + 1` and that every index in the line will be a neighbor of the preceding index.
- Lines are drawn in grid space, and may not correspond exactly to either Cartesian lines or great arcs.
- Parameters:
startAddress- Start index of the lineendAddress- End index of the line- Returns:
- Indexes making up the line.
-
gridPathCells
Given two H3 indexes, return the line of indexes between them (inclusive of endpoints).This function may fail to find the line between two indexes, for example if they are very far apart. It may also fail when finding distances for indexes on opposite sides of a pentagon.
Notes:
- The specific output of this function should not be considered stable across library versions. The only guarantees the library provides are that the line length will be `h3Distance(start, end) + 1` and that every index in the line will be a neighbor of the preceding index.
- Lines are drawn in grid space, and may not correspond exactly to either Cartesian lines or great arcs.
- Parameters:
start- Start index of the lineend- End index of the line- Returns:
- Indexes making up the line.
-
polygonToCellAddresses
Finds indexes within the given geofence.- Parameters:
points- Outline geofenceholes- Geofences of any internal holesres- Resolution of the desired indexes
-
polygonToCells
Finds indexes within the given geofence.- Parameters:
points- Outline geofenceholes- Geofences of any internal holesres- Resolution of the desired indexes- Throws:
IllegalArgumentException- Invalid resolution
-
cellAddressesToMultiPolygon
public List<List<List<LatLng>>> cellAddressesToMultiPolygon(Collection<String> h3Addresses, boolean geoJson) Create polygons from a set of contiguous indexes -
cellsToMultiPolygon
Create polygons from a set of contiguous indexes -
getResolution
Returns the resolution of the provided index -
getResolution
public int getResolution(long h3) Returns the resolution of the provided index -
cellToParent
public long cellToParent(long h3, int res) Returns the parent of the index at the given resolution.- Parameters:
h3- H3 index.res- Resolution of the parent,0 <= res <= h3GetResolution(h3)- Throws:
IllegalArgumentException-resis not between 0 and the resolution ofh3, inclusive.
-
cellToParentAddress
Returns the parent of the index at the given resolution.- Parameters:
h3Address- H3 index.res- Resolution of the parent,0 <= res <= h3GetResolution(h3)
-
cellToChildren
Provides the children of the index at the given resolution.- Parameters:
childRes- Resolution of the children
-
cellToChildren
Provides the children of the index at the given resolution.- Parameters:
h3- H3 index.childRes- Resolution of the children- Throws:
IllegalArgumentException- Invalid resolution
-
cellToCenterChild
Returns the center child at the given resolution.- Parameters:
h3- Parent H3 indexchildRes- Resolution of the child- Throws:
IllegalArgumentException- Invalid resolution (e.g. coarser than the parent)
-
cellToCenterChild
public long cellToCenterChild(long h3, int childRes) Returns the center child at the given resolution.- Parameters:
h3- Parent H3 indexchildRes- Resolution of the child- Throws:
IllegalArgumentException- Invalid resolution (e.g. coarser than the parent)
-
isResClassIII
Determines if an index is Class III or Class II.- Returns:
trueif the index is Class III
-
isResClassIII
public boolean isResClassIII(long h3) Determines if an index is Class III or Class II.- Parameters:
h3- H3 index.- Returns:
trueif the index is Class III
-
compactCellAddresses
Returns a compacted set of indexes, at possibly coarser resolutions. -
compactCells
Returns a compacted set of indexes, at possibly coarser resolutions. -
uncompactCellAddresses
Uncompacts all the given indexes to resolutionres. -
uncompactCells
Uncompacts all the given indexes to resolutionres. -
h3ToString
Converts fromlongrepresentation of an index toStringrepresentation. -
stringToH3
Converts fromStringrepresentation of an index tolongrepresentation. -
cellArea
Calculates the area of the given H3 cell.- Parameters:
h3Address- Cell to find the area of.unit- Unit to calculate the area in.- Returns:
- Cell area in the given units.
-
cellArea
Calculates the area of the given H3 cell.- Parameters:
h3- Cell to find the area of.unit- Unit to calculate the area in.- Returns:
- Cell area in the given units.
-
greatCircleDistance
Return the distance along the sphere between two points.- Parameters:
a- First pointb- Second pointunit- Unit to return the distance in.- Returns:
- Distance from point
ato pointb
-
edgeLength
Calculate the edge length of the given H3 edge.- Parameters:
edgeAddress- Edge to find the edge length of.unit- Unit of measure to use.- Returns:
- Length of the given edge.
-
edgeLength
Calculate the edge length of the given H3 edge.- Parameters:
edge- Edge to find the edge length of.unit- Unit of measure to use.- Returns:
- Length of the given edge.
-
getHexagonAreaAvg
Returns the average area inunitfor indexes at resolutionres.- Throws:
IllegalArgumentException- Invalid parameter value
-
getHexagonEdgeLengthAvg
Returns the average edge length inunitfor indexes at resolutionres.- Throws:
IllegalArgumentException- Invalid parameter value
-
getNumCells
public long getNumCells(int res) Returns the number of unique H3 indexes at resolutionres.- Throws:
IllegalArgumentException- Invalid resolution
-
getRes0CellAddresses
Returns a collection of all base cells (H3 indexes are resolution 0). -
getRes0Cells
Returns a collection of all base cells (H3 indexes are resolution 0). -
getPentagonAddresses
Returns a collection of all topologically pentagonal cells at the given resolution.- Throws:
IllegalArgumentException- Invalid resolution.
-
getPentagons
Returns a collection of all topologically pentagonal cells at the given resolution.- Throws:
IllegalArgumentException- Invalid resolution.
-
areNeighborCells
public boolean areNeighborCells(long a, long b) Returnstrueif the two indexes are neighbors. -
areNeighborCells
Returnstrueif the two indexes are neighbors. -
cellsToDirectedEdge
public long cellsToDirectedEdge(long a, long b) Returns a unidirectional edge index representingatowardsb.- Throws:
IllegalArgumentException- The indexes are not neighbors.
-
cellsToDirectedEdge
Returns a unidirectional edge index representingatowardsb.- Throws:
IllegalArgumentException- The indexes are not neighbors.
-
isValidDirectedEdge
public boolean isValidDirectedEdge(long h3) Returnstrueif the given index is a valid unidirectional edge. -
isValidDirectedEdge
Returnstrueif the given index is a valid unidirectional edge. -
getDirectedEdgeOrigin
public long getDirectedEdgeOrigin(long h3) Returns the origin index of the given unidirectional edge. -
getDirectedEdgeOrigin
Returns the origin index of the given unidirectional edge. -
getDirectedEdgeDestination
public long getDirectedEdgeDestination(long h3) Returns the destination index of the given unidirectional edge. -
getDirectedEdgeDestination
Returns the destination index of the given unidirectional edge. -
directedEdgeToCells
Returns the origin and destination indexes (in that order) of the given unidirectional edge. -
directedEdgeToCells
Returns the origin and destination indexes (in that order) of the given unidirectional edge. -
originToDirectedEdges
Returns all unidirectional edges originating from the given index. -
originToDirectedEdges
Returns all unidirectional edges originating from the given index. -
directedEdgeToBoundary
Returns a list of coordinates representing the given edge. -
directedEdgeToBoundary
Returns a list of coordinates representing the given edge. -
getIcosahedronFaces
Find all icosahedron faces intersected by a given H3 index, represented as integers from 0-19.- Parameters:
h3- Index to find icosahedron faces for.- Returns:
- A collection of faces intersected by the index.
-
getIcosahedronFaces
Find all icosahedron faces intersected by a given H3 index, represented as integers from 0-19.- Parameters:
h3- Index to find icosahedron faces for.- Returns:
- A collection of faces intersected by the index.
-
cellToVertex
public long cellToVertex(long h3, int vertexNum) -
cellToVertex
-
cellToVertexes
-
cellToVertexes
-
vertexToLatLng
-
vertexToLatLng
-
isValidVertex
public boolean isValidVertex(long h3) -
isValidVertex
-