How to use the h3.compact 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
(45.3052400000002, -71.08482),
        (45.46022288673396, -70.6600225491012),
        (45.914794623389355, -70.30495378282376),
        (46.69317088478567, -70.00014034695016),
        (47.44777598732787, -69.23708614772835),
        (47.184794623394396, -68.90478084987546),
        (47.35462921812177, -68.23430497910454),
        (47.066248887716995, -67.79035274928509),
        (45.702585354182816, -67.79141211614706),
        (45.137451890638886, -67.13734351262877)
    ]

    res = 5

    h_uncomp = h3.polyfill_polygon(maine, res)
    h_comp = h3.compact(h_uncomp)

    expected = {'852b114ffffffff', '852b189bfffffff', '852b1163fffffff', '842ba9bffffffff', '842bad3ffffffff', '852ba9cffffffff', '842badbffffffff', '852b1e8bfffffff', '852a346ffffffff', '842b1e3ffffffff', '852b116ffffffff', '842b185ffffffff', '852b1bdbfffffff', '852bad47fffffff', '852ba9c3fffffff', '852b106bfffffff', '852a30d3fffffff', '842b1edffffffff', '852b12a7fffffff', '852b1027fffffff', '842baddffffffff', '852a349bfffffff', '852b1227fffffff', '852a3473fffffff', '852b117bfffffff', '842ba99ffffffff', '852a341bfffffff', '852ba9d3fffffff', '852b1067fffffff', '852a3463fffffff', '852baca7fffffff', '852b116bfffffff', '852b1c6bfffffff', '852a3493fffffff', '852ba9dbfffffff', '852b180bfffffff', '842bad7ffffffff', '852b1063fffffff', '842ba93ffffffff', '852a3693fffffff', '852ba977fffffff', '852b1e9bfffffff', '852bad53fffffff', '852b100ffffffff', '852b102bfffffff', '852a3413fffffff', '852ba8b7fffffff', '852bad43fffffff', '852b1c6ffffffff', '852a340bfffffff', '852b103bfffffff', '852b1813fffffff', '852b12affffffff', '842a34dffffffff', '852b1873fffffff', '852b106ffffffff', '852b115bfffffff', '852baca3fffffff', '852b114bfffffff', '852b1143fffffff', '852a348bfffffff', '852a30d7fffffff', '852b181bfffffff', '842a345ffffffff', '852b1e8ffffffff', '852b1883fffffff', '852b1147fffffff', '852a3483fffffff', '852b12a3fffffff', '852a346bfffffff', '852ba9d7fffffff', '842b18dffffffff', '852b188bfffffff', '852a36a7fffffff', '852bacb3fffffff', '852b187bfffffff', '852bacb7fffffff', '842b1ebffffffff', '842b1e5ffffffff', '852ba8a7fffffff', '842bad9ffffffff', '852a36b7fffffff', '852a347bfffffff', '832b13fffffffff', '852ba9c7fffffff', '832b1afffffffff', '842ba91ffffffff', '852bad57fffffff', '852ba8affffffff', '852b1803fffffff', '842b1e7ffffffff', '852bad4ffffffff', '852b102ffffffff', '852b1077fffffff', '852b1237fffffff', '852b1153fffffff', '852a3697fffffff', '852a36b3fffffff', '842bad1ffffffff', '842b1e1ffffffff', '852b186bfffffff', '852b1023fffffff'} # noqa

    assert h_comp == expected

    return h_uncomp, h_comp, res
github uber / h3-py / tests / test_h3.py View on Github external
def test_compact_malformed_input():
    hexes = ['89283082813ffff'] * 13

    with pytest.raises(Exception):
        h3.compact(hexes)
github uber / h3-py / tests / test_cells_and_edges.py View on Github external
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_compact_and_uncompact_nothing():
    assert h3.compact([]) == set()
    assert h3.uncompact([], 9) == set()
github uber / h3-py / tests / test_h3.py View on Github external
'type': 'Polygon',
        'coordinates': [
            [
                [37.813318999983238, -122.4089866999972145],
                [37.7866302000007224, -122.3805436999997056],
                [37.7198061999978478, -122.3544736999993603],
                [37.7076131999975672, -122.5123436999983966],
                [37.7835871999971715, -122.5247187000021967],
                [37.8151571999998453, -122.4798767000009008],
            ]
        ]
    }

    hexes = h3.polyfill(geo, 9)

    compact_hexes = h3.compact(hexes)
    assert len(compact_hexes) == 209

    uncompact_hexes = h3.uncompact(compact_hexes, 9)
    assert len(uncompact_hexes) == 1253