How to use h3 - 10 common examples

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 test5():
    expected = {
        '89283082873ffff',
        '89283082877ffff',
        '8928308283bffff',
        '89283082807ffff',
        '8928308280bffff',
        '8928308280fffff',
        '89283082803ffff'
    }

    out = h3.k_ring('8928308280fffff', 1)
    assert out == expected
github uber / h3-py / tests / test_cells_and_edges.py View on Github external
def test_k_ring_distance():
    with pytest.raises(H3DistanceError):
        h3.k_ring('8928308280fffff', -10)
github uber / h3-py / tests / test_h3.py View on Github external
def test_k_ring2():
    h = '8928308280fffff'
    out = h3.k_ring(h, 2)

    assert len(out) == 1 + 6 + 12

    expected = {
        '89283082813ffff',
        '89283082817ffff',
        '8928308281bffff',
        '89283082863ffff',
        '89283082823ffff',
        '89283082873ffff',
        '89283082877ffff',
        h,
        '8928308287bffff',
        '89283082833ffff',
        '8928308282bffff',
        '8928308283bffff',
github uber / h3-py / tests / test_h3.py View on Github external
'89283082813ffff',
        '89283082817ffff',
        '8928308281bffff',
        '89283082863ffff',
        '89283082823ffff',
        '8928308287bffff',
        '89283082833ffff',
        '8928308282bffff',
        '89283082857ffff',
        '892830828abffff',
        '89283082847ffff',
        '89283082867ffff',
    }

    assert out == expected
    assert out == h3.k_ring(h, 2) - h3.k_ring(h, 1)
github uber / h3-py / tests / test_h3.py View on Github external
def test_k_ring_pentagon():
    h = '821c07fffffffff'  # a pentagon cell
    out = h3.k_ring(h, 1)

    assert len(out) == 1 + 5

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

    assert out == expected
github uber / h3-py / tests / test_h3.py View on Github external
'89300628393ffff', '89300628383ffff', '89300628397ffff',
        '89300628067ffff', '89300628387ffff', '893006283bbffff',
        '89300628313ffff', '893006283cfffff', '89300628303ffff',
        '89300628317ffff', '8930062839bffff', h,
        '8930062806fffff', '8930062838fffff', '893006283d3ffff',
        '893006283c3ffff', '8930062831bffff', '893006283d7ffff',
        '893006283c7ffff'
    }

    mp2 = h3.h3_set_to_multi_polygon(hexes2)

    assert len(mp2) == 1  # polygon count matches expected
    assert len(mp2[0]) == 1  # loop count matches expected
    assert len(mp2[0][0]) == 6 * (2 * 2 + 1)  # coord count matches expected

    hexes3 = list(h3.k_ring(h, 6))
    hexes3.sort()
    mp3 = h3.h3_set_to_multi_polygon(hexes3)

    assert len(mp3[0]) == 1  # loop count matches expected
github uber / h3-py / tests / test_cells_and_edges.py View on Github external
h = '8a28308280fffff'  # invalid cell

    with pytest.raises(H3CellError):
        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_h3.py View on Github external
def test_hex_ring():
    h = '8928308280fffff'
    out = h3.hex_ring(h, 1)
    expected = {
        '8928308280bffff',
        '89283082807ffff',
        '89283082877ffff',
        '89283082803ffff',
        '89283082873ffff',
        '8928308283bffff',
    }

    assert out == expected
    assert out == h3.k_ring(h, 1) - h3.k_ring(h, 0)
github uber / h3-py / tests / test_h3.py View on Github external
def test_h3_set_to_multi_polygon_2k_ring():
    h = '8930062838bffff'
    hexes = h3.k_ring(h, 2)
    # multi_polygon
    mp = h3.h3_set_to_multi_polygon(hexes)

    assert len(mp) == 1  # polygon count matches expected
    assert len(mp[0]) == 1  # loop count matches expected
    assert len(mp[0][0]) == 6 * (2 * 2 + 1)  # coord count matches expected

    hexes2 = {
        '89300628393ffff', '89300628383ffff', '89300628397ffff',
        '89300628067ffff', '89300628387ffff', '893006283bbffff',
        '89300628313ffff', '893006283cfffff', '89300628303ffff',
        '89300628317ffff', '8930062839bffff', h,
        '8930062806fffff', '8930062838fffff', '893006283d3ffff',
        '893006283c3ffff', '8930062831bffff', '893006283d7ffff',
        '893006283c7ffff'
    }
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