---
id: uniedge
title: Directed edge functions
sidebar_label: Directed edges
slug: /api/uniedge
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

Directed edges allow encoding the directed (that is, which cell is the origin and which is the destination can be determined)
edge from one cell to a neighboring cell.

## areNeighborCells

Determines whether or not the provided H3 cells are neighbors.

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
    {label: 'Python', value: 'python'},
    {label: 'Go', value: 'go'},
    {label: 'DuckDB', value: 'duckdb'},
    {label: 'Shell', value: 'shell'},
  ]
}>
<TabItem value="c">

```c
H3Error areNeighborCells(H3Index origin, H3Index destination, int *out);
```

`out` will be 1 if the indexes are neighbors, 0 otherwise.

Returns 0 (`E_SUCCESS`) on success.

</TabItem>
<TabItem value="java">

```java
boolean areNeighborCells(long origin, long destination);
boolean areNeighborCells(String origin, String destination);
```

</TabItem>
<TabItem value="javascript">

```js
h3.areNeighborCells(origin, destination)
```

```js live
function example() {
  const origin = '85283473fffffff';
  const destination = '85283477fffffff';
  return h3.areNeighborCells(origin, destination);
}
```

</TabItem>
<TabItem value="python">

```py
h3.are_neighbor_cells(origin, destination)
```

</TabItem>
<TabItem value="go">

```go
origin.IsNeighbor(destination)
```

</TabItem>
<TabItem value="duckdb">

```sql
h3_are_neighbor_cells(origin, destination)
```

</TabItem>
<TabItem value="shell">

```sh
$ h3 areNeighborCells --help
h3: Determines if the provided H3 cells are neighbors (have a shared border)
H3 4.1.0

	areNeighborCells	Determines if the provided H3 cells are neighbors (have a shared border)
	-o, --origin <CELL>	Required. Origin H3 Cell
	-d, --destination <CELL>	Required. Destination H3 Cell
	-h, --help	Show this help message.
	-f, --format <FMT>	'json' for true or false, 'numeric' for 1 or 0 (Default: json)
```

```bash
$ h3 areNeighborCells -o 85283473fffffff -d 85283477fffffff
true
```

</TabItem>
</Tabs>


## cellsToDirectedEdge

Provides a directed edge H3 index based on the provided origin and
destination.

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
    {label: 'Python', value: 'python'},
    {label: 'Go', value: 'go'},
    {label: 'DuckDB', value: 'duckdb'},
    {label: 'Shell', value: 'shell'},
  ]
}>
<TabItem value="c">

```c
H3Error cellsToDirectedEdge(H3Index origin, H3Index destination, H3Index *out);
```

Returns 0 (`E_SUCCESS`) on success.

</TabItem>
<TabItem value="java">

```java
long cellsToDirectedEdge(long origin, long destination);
String cellsToDirectedEdge(String origin, String destination);
```

</TabItem>
<TabItem value="javascript">

```js
h3.cellsToDirectedEdge(h3Index)
```

```js live
function example() {
  const origin = '85283473fffffff';
  const destination = '85283477fffffff';
  return h3.cellsToDirectedEdge(origin, destination);
}
```

</TabItem>
<TabItem value="python">

```py
h3.cells_to_directed_edge(origin, destination)
```

</TabItem>
<TabItem value="go">

```go
origin.DirectedEdge(destination)
```

</TabItem>
<TabItem value="duckdb">

```sql
h3_cells_to_directed_edge(origin, destination)
```

</TabItem>
<TabItem value="shell">

```sh
$ h3 cellsToDirectedEdge --help
h3: Converts neighboring cells into a directed edge index (or errors if they are not neighbors)
H3 4.1.0

	cellsToDirectedEdge	Converts neighboring cells into a directed edge index (or errors if they are not neighbors)
	-o, --origin <CELL>	Required. Origin H3 Cell
	-d, --destination <CELL>	Required. Destination H3 Cell
	-h, --help	Show this help message.
	-f, --format <FMT>	'json' for "CELL"\n, 'newline' for CELL\n (Default: json)
```

```bash
$ h3 cellsToDirectedEdge -o 85283473fffffff -d 85283477fffffff
"115283473fffffff"
```

</TabItem>
</Tabs>

## isValidDirectedEdge

Determines if the provided H3Index is a valid unidirectional edge index.

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
    {label: 'Python', value: 'python'},
    {label: 'Go', value: 'go'},
    {label: 'DuckDB', value: 'duckdb'},
    {label: 'Shell', value: 'shell'},
  ]
}>
<TabItem value="c">

```c
int isValidDirectedEdge(H3Index edge);
```

Returns `1` if it is a unidirectional edge H3Index, otherwise `0`.

</TabItem>
<TabItem value="java">

```java
boolean isValidDirectedEdge(long edge);
boolean isValidDirectedEdge(String edgeAddress);
```

</TabItem>
<TabItem value="javascript">

```js
h3.isValidDirectedEdge(edge)
```

```js live
function example() {
  const edge = '115283473fffffff';
  return h3.isValidDirectedEdge(edge);
}
```

</TabItem>
<TabItem value="python">

```py
h3.is_valid_directed_edge(edge)
```

</TabItem>
<TabItem value="go">

```go
edge.IsValid()
```

</TabItem>
<TabItem value="duckdb">

```sql
h3_is_valid_directed_edge(edge)
```

</TabItem>
<TabItem value="shell">

```sh
$ h3 isValidDirectedEdge --help
h3: Checks if the provided H3 directed edge is actually valid
H3 4.1.0

	isValidDirectedEdge	Checks if the provided H3 directed edge is actually valid
	-h, --help	Show this help message.
	-c, --cell <index>	Required. H3 Cell
	-f, --format <FMT>	'json' for true or false, 'numeric' for 1 or 0 (Default: json)
```

```bash
$ h3 isValidDirectedEdge -c 115283473fffffff
true
```

</TabItem>
</Tabs>

## getDirectedEdgeOrigin

Provides the origin hexagon from the directed edge H3Index.

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
    {label: 'Python', value: 'python'},
    {label: 'Go', value: 'go'},
    {label: 'DuckDB', value: 'duckdb'},
    {label: 'Shell', value: 'shell'},
  ]
}>
<TabItem value="c">

```c
H3Error getDirectedEdgeOrigin(H3Index edge, H3Index *out);
```

Returns 0 (`E_SUCCESS`) on success.

</TabItem>
<TabItem value="java">

```java
long getDirectedEdgeOrigin(long edge);
String getDirectedEdgeOrigin(String edgeAddress);
```

</TabItem>
<TabItem value="javascript">

```js
h3.getDirectedEdgeOrigin(h3Index)
```

```js live
function example() {
  const edge = '115283473fffffff';
  return h3.getDirectedEdgeOrigin(edge);
}
```

</TabItem>
<TabItem value="python">

```py
h3.get_directed_edge_origin(edge)
```

</TabItem>
<TabItem value="go">

```go
edge.Origin()
```

</TabItem>
<TabItem value="duckdb">

```sql
h3_get_directed_edge_origin(edge)
```

</TabItem>
<TabItem value="shell">

```sh
$ h3 getDirectedEdgeOrigin --help
h3: Returns the origin cell from the directed edge
H3 4.1.0

	getDirectedEdgeOrigin	Returns the origin cell from the directed edge
	-c, --cell <index>	Required. H3 Cell
	-h, --help	Show this help message.
	-f, --format <FMT>	'json' for "CELL"\n, 'newline' for CELL\n (Default: json)
```

```bash
$ h3 getDirectedEdgeOrigin -c 115283473fffffff
"85283473fffffff"
```

</TabItem>
</Tabs>

## getDirectedEdgeDestination

Provides the destination hexagon from the directed edge H3Index.

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
    {label: 'Python', value: 'python'},
    {label: 'Go', value: 'go'},
    {label: 'DuckDB', value: 'duckdb'},
    {label: 'Shell', value: 'shell'},
  ]
}>
<TabItem value="c">

```c
H3Error getDirectedEdgeDestination(H3Index edge, H3Index *out);
```

Returns 0 (`E_SUCCESS`) on success.

</TabItem>
<TabItem value="java">

```java
long getDirectedEdgeDestination(long edge);
String getDirectedEdgeDestination(String edgeAddress);
```

</TabItem>
<TabItem value="javascript">

```js
h3.getDirectedEdgeDestination(edge)
```

```js live
function example() {
  const edge = '115283473fffffff';
  return h3.getDirectedEdgeDestination(edge);
}
```

</TabItem>
<TabItem value="python">

```py
h3.get_directed_edge_destination(edge)
```

</TabItem>
<TabItem value="go">

```go
edge.Destination()
```

</TabItem>
<TabItem value="duckdb">

```sql
h3.get_directed_edge_destination(edge)
```

</TabItem>
<TabItem value="shell">

```sh
$ h3 getDirectedEdgeDestination --help
h3: Returns the destination cell from the directed edge
H3 4.1.0

	getDirectedEdgeDestination	Returns the destination cell from the directed edge
	-c, --cell <index>	Required. H3 Cell
	-h, --help	Show this help message.
	-f, --format <FMT>	'json' for "CELL"\n, 'newline' for CELL\n (Default: json)
```

```bash
$ h3 getDirectedEdgeDestination -c 115283473fffffff
"85283477fffffff"
```

</TabItem>
</Tabs>


## directedEdgeToCells

Provides the origin-destination pair of cells for the given directed edge.

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
    {label: 'Python', value: 'python'},
    {label: 'Go', value: 'go'},
    {label: 'DuckDB', value: 'duckdb'},
    {label: 'Shell', value: 'shell'},
  ]
}>
<TabItem value="c">

```c
H3Error directedEdgeToCells(H3Index edge, H3Index* originDestination);
```

The origin and destination are placed at
`originDestination[0]` and `originDestination[1]`, respectively.

Returns 0 (`E_SUCCESS`) on success.

</TabItem>
<TabItem value="java">

```java
List<Long> directedEdgeToCells(long edge);
List<String> directedEdgeToCells(String edgeAddress);
```

</TabItem>
<TabItem value="javascript">

```js
h3.directedEdgeToCells(edge)
```

```js live
function example() {
  const edge = '115283473fffffff';
  return h3.directedEdgeToCells(edge);
}
```

</TabItem>
<TabItem value="python">

```py
h3.directed_edge_to_cells(edge)
```

</TabItem>
<TabItem value="go">

```go
edge.Cells()
```

</TabItem>
<TabItem value="duckdb">

```sql
h3_directed_edge_to_cells(edge)
```

</TabItem>
<TabItem value="shell">

```sh
$ h3 directedEdgeToCells --help
h3: Returns the origin, destination pair of cells from the directed edge
H3 4.1.0

	directedEdgeToCells	Returns the origin, destination pair of cells from the directed edge
	-c, --cell <index>	Required. H3 Cell
	-h, --help	Show this help message.
	-f, --format <FMT>	'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json)
```

```bash
$ h3 directedEdgeToCells -c 115283473fffffff
["85283473fffffff", "85283477fffffff"]
```

</TabItem>
</Tabs>

## originToDirectedEdges

Provides all of the directed edges from the current cell.

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
    {label: 'Python', value: 'python'},
    {label: 'Go', value: 'go'},
    {label: 'DuckDB', value: 'duckdb'},
    {label: 'Shell', value: 'shell'},
  ]
}>
<TabItem value="c">

```c
H3Error originToDirectedEdges(H3Index origin, H3Index* edges);
```

`edges` must be of length 6,
and the number of directed edges placed in the array may be less than 6.
If this is the case, one of the members of the array will be `0`.

Returns 0 (`E_SUCCESS`) on success.

</TabItem>
<TabItem value="java">

```java
List<Long> originToDirectedEdges(long h3);
List<String> originToDirectedEdges(String h3);
```

</TabItem>
<TabItem value="javascript">

```js
h3.originToDirectedEdges(h3Index)
```

```js live
function example() {
  const h = '85283473fffffff';
  return h3.originToDirectedEdges(h);
}
```

</TabItem>
<TabItem value="python">

```py
h3.origin_to_directed_edges(h)
```

</TabItem>
<TabItem value="go">

```go
origin.DirectedEdges()
```

</TabItem>
<TabItem value="duckdb">

```sql
h3_origin_to_directed_edges(h)
```

</TabItem>
<TabItem value="shell">

```sh
$ h3 originToDirectedEdges --help
h3: Returns all of the directed edges from the specified origin cell
H3 4.1.0

	originToDirectedEdges	Returns all of the directed edges from the specified origin cell
	-c, --cell <index>	Required. H3 Cell
	-h, --help	Show this help message.
	-f, --format <FMT>	'json' for ["CELL", ...], 'newline' for CELL\n... (Default: json)
```

```bash
$ h3 originToDirectedEdges -c 85283473fffffff
["115283473fffffff", "125283473fffffff", "135283473fffffff", "145283473fffffff", "155283473fffffff", "165283473fffffff"]
```

</TabItem>
</Tabs>


## directedEdgeToBoundary

Provides the geographic lat/lng coordinates defining the directed edge.
Note that this may be more than two points for complex edges.

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
    {label: 'Python', value: 'python'},
    {label: 'Go', value: 'go'},
    {label: 'DuckDB', value: 'duckdb'},
    {label: 'Shell', value: 'shell'},
  ]
}>
<TabItem value="c">

```c
H3Error directedEdgeToBoundary(H3Index edge, CellBoundary* gb);
```

Returns 0 (`E_SUCCESS`) on success.

</TabItem>
<TabItem value="java">

```java
List<LatLng> directedEdgeToBoundary(long edge);
List<LatLng> directedEdgeToBoundary(String edgeAddress);
```

</TabItem>
<TabItem value="javascript">

```js
h3.directedEdgeToBoundary(edge, [formatAsGeoJson])
```

```js live
function example() {
  const edge = '115283473fffffff';
  return h3.directedEdgeToBoundary(edge);
}
```

</TabItem>
<TabItem value="python">

```py
h3.directed_edge_to_boundary(edge)
```

</TabItem>
<TabItem value="go">

```go
edge.Boundary()
```

</TabItem>
<TabItem value="duckdb">

```sql
h3_directed_edge_to_boundary(edge)
```

</TabItem>
<TabItem value="shell">

```sh
$ h3 directedEdgeToBoundary --help
h3: Provides the coordinates defining the directed edge
H3 4.1.0

	directedEdgeToBoundary	Provides the coordinates defining the directed edge
	-c, --cell <index>	Required. H3 Cell
	-h, --help	Show this help message.
	-f, --format <FMT>	'json' for [[lat, lng], ...], 'wkt' for a WKT POLYGON, 'newline' for lat\nlng\n... (Default: json)
```

```bash
$ h3 directedEdgeToBoundary -c 115283473fffffff
[[37.4201286777, -122.0377349643], [37.3375560844, -122.0904289290]]
```

</TabItem>
</Tabs>


## reverseDirectedEdge

Returns the directed edge index that represents the same edge in the opposite direction (i.e., with origin and destination cells swapped).

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
    {label: 'Python', value: 'python'},
    {label: 'Go', value: 'go'},
    {label: 'DuckDB', value: 'duckdb'},
    {label: 'Shell', value: 'shell'},
  ]}
>
<TabItem value="c">

```c
H3Error reverseDirectedEdge(H3Index edge, H3Index* out);
```

Takes a directed edge H3Index and returns (via out) the directed edge H3Index representing the edge in the reverse direction. Returns an error if the input is not a valid directed edge.

</TabItem>
<TabItem value="java">

```java
long reverseDirectedEdge(long edge);
String reverseDirectedEdge(String edgeAddress);
```

</TabItem>
<TabItem value="javascript">

```js
h3.reverseDirectedEdge(edge)
```

```js live
function example() {
  const edge = '115283473fffffff';
  return h3.reverseDirectedEdge(edge);
}
```

</TabItem>
<TabItem value="python">

```py
h3.reverse_directed_edge(edge)
```

</TabItem>
<TabItem value="go">

```go
edge.Reverse()
```

</TabItem>
<TabItem value="duckdb">

```sql
h3_reverse_directed_edge(edge)
```

</TabItem>
<TabItem value="shell">

```sh
$ h3 reverseDirectedEdge --help
h3: Returns the directed edge index representing the same edge in the opposite direction
H3 4.1.0

  reverseDirectedEdge Returns the directed edge index representing the same edge in the opposite direction
  -e, --edge <EDGE> Required. Directed edge H3 index
  -h, --help  Show this help message.
  -f, --format <FMT>  'json' for "EDGE"\n, 'newline' for EDGE\n (Default: json)
```

```bash
$ h3 reverseDirectedEdge -e 115283473fffffff
"115283477fffffff"
```

</TabItem>
</Tabs>
