How to use the h3.hex_ring function in h3

To help you get started, we’ve selected a few h3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uber / h3-py / tests / test_cells_and_edges.py View on Github external
def test6():
    expected = {'8928308280fffff'}
    out = h3.hex_ring('8928308280fffff', 0)
    assert out == expected
github uber / h3-py / tests / test_cells_and_edges.py View on Github external
def test_distance():
    h = '8a28308280c7fff'
    assert h3.h3_distance(h, h) == 0

    n = h3.hex_ring(h, 1).pop()
    assert h3.h3_distance(h, n) == 1

    n = h3.hex_ring(h, 2).pop()
    assert h3.h3_distance(h, n) == 2
github uber / h3-py / tests / test_cells_and_edges.py View on Github external
def test_edges():
    h = '8928308280fffff'

    with pytest.raises(H3ValueError):
        h3.get_h3_unidirectional_edge(h, h)

    h2 = h3.hex_ring(h, 2).pop()
    with pytest.raises(H3ValueError):
        h3.get_h3_unidirectional_edge(h, h2)

    e_bad = '14928308280ffff1'
    assert not h3.h3_unidirectional_edge_is_valid(e_bad)

    with pytest.raises(H3EdgeError):
        h3.get_origin_h3_index_from_unidirectional_edge(e_bad)

    with pytest.raises(H3EdgeError):
        h3.get_destination_h3_index_from_unidirectional_edge(e_bad)

    with pytest.raises(H3EdgeError):
        h3.get_h3_indexes_from_unidirectional_edge(e_bad)
github uber / h3-py / tests / test_cells_and_edges.py View on Github external
def test_hex_ring_distance():
    with pytest.raises(H3DistanceError):
        h3.hex_ring('8928308280fffff', -10)
github uber / h3-py / tests / test_cells_and_edges.py View on Github external
def test_edges_from_cell():
    h = '8928308280fffff'
    edges = h3.get_h3_unidirectional_edges_from_hexagon(h)
    destinations = {
        h3.get_destination_h3_index_from_unidirectional_edge(e)
        for e in edges
    }
    neighbors = h3.hex_ring(h, 1)

    assert neighbors == destinations
github uber / h3-py / tests / test_cells_and_edges.py View on Github external
def test7():
    expected = {
        '89283082803ffff',
        '89283082807ffff',
        '8928308280bffff',
        '8928308283bffff',
        '89283082873ffff',
        '89283082877ffff'
    }

    out = h3.hex_ring('8928308280fffff', 1)
    assert out == expected
github uber / h3-py / tests / test_h3.py View on Github external
def test_hex_ring_pentagon():
    h = '821c07fffffffff'
    out = h3.hex_ring(h, 1)

    expected = {
        '821c17fffffffff',
        '821c1ffffffffff',
        '821c27fffffffff',
        '821c2ffffffffff',
        '821c37fffffffff',
    }

    assert out == expected
github uber / h3-py / tests / test_cells_and_edges.py View on Github external
h3.h3_get_base_cell(h)

    with pytest.raises(H3CellError):
        h3.h3_get_resolution(h)

    with pytest.raises(H3CellError):
        h3.h3_to_parent(h, 9)

    with pytest.raises(H3CellError):
        h3.h3_distance(h, h)

    with pytest.raises(H3CellError):
        h3.k_ring(h, 1)

    with pytest.raises(H3CellError):
        h3.hex_ring(h, 1)

    with pytest.raises(H3CellError):
        h3.h3_to_children(h, 11)

    with pytest.raises(H3CellError):
        h3.compact({h})

    with pytest.raises(H3CellError):
        h3.uncompact({h}, 10)
github uber / h3-py / tests / test_cells_and_edges.py View on Github external
def test_to_local_ij_error():
    h = h3.geo_to_h3(0, 0, 0)

    # error if we cross a face
    nb = h3.hex_ring(h, k=2)
    with pytest.raises(H3ValueError):
        [h3.experimental_h3_to_local_ij(h, p) for p in nb]

    # should be fine if we do not cross a face
    nb = h3.hex_ring(h, k=1)
    out = {h3.experimental_h3_to_local_ij(h, p) for p in nb}
    expected = {(-1, 0), (0, -1), (0, 1), (1, 0), (1, 1)}

    assert out == expected
github uber / h3-py / tests / test_h3.py View on Github external
def test_hex_ring2():
    h = '8928308280fffff'
    out = h3.hex_ring(h, 2)

    expected = {
        '89283082813ffff',
        '89283082817ffff',
        '8928308281bffff',
        '89283082863ffff',
        '89283082823ffff',
        '8928308287bffff',
        '89283082833ffff',
        '8928308282bffff',
        '89283082857ffff',
        '892830828abffff',
        '89283082847ffff',
        '89283082867ffff',
    }