How to use the h3.h3_set_to_multi_polygon 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_h3.py View on Github external
def test_h3_set_to_multi_polygon_single_geo_json():
    hexes = ['89283082837ffff']
    mp = h3.h3_set_to_multi_polygon(hexes, True)
    vertices = h3.h3_to_geo_boundary(hexes[0], True)

    # We shift the expected circular list so that it starts from
    # multi_polygon[0][0][0], since output starting from any vertex
    # would be correct as long as it's in order.
    expected_coords = shift_circular_list(
        mp[0][0][0],
        [
            vertices[2],
            vertices[3],
            vertices[4],
            vertices[5],
            vertices[0],
            vertices[1]
        ]
    )
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'
    }

    mp2 = h3.h3_set_to_multi_polygon(hexes2)
github uber / h3-py / tests / test_h3.py View on Github external
def test_h3_set_to_multi_polygon_empty():
    out = h3.h3_set_to_multi_polygon([])
    assert out == []
github uber / h3-py / tests / test_h3.py View on Github external
def test_h3_set_to_multi_polygon_hole():
    # Six hexagons in a ring around a hole
    hexes = [
        '892830828c7ffff', '892830828d7ffff', '8928308289bffff',
        '89283082813ffff', '8928308288fffff', '89283082883ffff',
    ]
    mp = h3.h3_set_to_multi_polygon(hexes)

    assert len(mp) == 1  # polygon count matches expected
    assert len(mp[0]) == 2  # loop count matches expected
    assert len(mp[0][0]) == 6 * 3  # outer coord count matches expected
    assert len(mp[0][1]) == 6  # inner coord count matches expected
github uber / h3-py / tests / test_h3.py View on Github external
def test_h3_set_to_multi_polygon_contiguous():
    # the second hexagon shares v0 and v1 with the first
    hexes = ['89283082837ffff', '89283082833ffff']

    # multi_polygon
    mp = h3.h3_set_to_multi_polygon(hexes)
    vertices0 = h3.h3_to_geo_boundary(hexes[0])
    vertices1 = h3.h3_to_geo_boundary(hexes[1])

    # We shift the expected circular list so that it starts from
    # multi_polygon[0][0][0], since output starting from any vertex
    # would be correct as long as it's in order.
    expected_coords = shift_circular_list(
        mp[0][0][0],
        [
            vertices1[0],
            vertices1[1],
            vertices1[2],
            vertices0[1],
            vertices0[2],
            vertices0[3],
            vertices0[4],
github uber / h3-py / tests / test_h3.py View on Github external
def test_h3_set_to_multi_polygon_non_contiguous():
    # the second hexagon does not touch the first
    hexes = {'89283082837ffff', '8928308280fffff'}
    # multi_polygon
    mp = h3.h3_set_to_multi_polygon(hexes)

    assert len(mp) == 2  # polygon count matches expected
    assert len(mp[0]) == 1  # loop count matches expected
    assert len(mp[0][0]) == 6  # coord count 1 matches expected
    assert len(mp[1][0]) == 6  # coord count 2 matches expected
github uber / h3-py / tests / test_h3.py View on Github external
def test_h3_set_to_multi_polygon_single():
    h = '89283082837ffff'
    hexes = {h}

    # multi_polygon
    mp = h3.h3_set_to_multi_polygon(hexes)
    vertices = h3.h3_to_geo_boundary(h)

    # We shift the expected circular list so that it starts from
    # multi_polygon[0][0][0], since output starting from any vertex
    # would be correct as long as it's in order.
    expected_coords = shift_circular_list(
        mp[0][0][0],
        [
            vertices[2],
            vertices[3],
            vertices[4],
            vertices[5],
            vertices[0],
            vertices[1],
        ]
    )
github uber / h3-py / tests / test_h3.py View on Github external
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'
    }

    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_h3.py View on Github external
'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