def test_validation(): h = '8a28308280fffff' # invalid hex 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)
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
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
def test7(): expected = { '89283082803ffff', '89283082807ffff', '8928308280bffff', '8928308283bffff', '89283082873ffff', '89283082877ffff' } out = h3.hex_ring('8928308280fffff', 1) assert out == expected
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
def test_2_polys(): h = '8928308280fffff' hexes = h3.hex_ring(h, 2) hexes = hexes | {h} # hexes should be a center hex, and the 2-ring around it # (with the 1-ring being absent) out = [ h3.polyfill_polygon(poly[0], 9, holes=poly[1:], lnglat_order=False) for poly in h3.h3_set_to_multi_polygon(hexes, geo_json=False) ] assert set.union(*out) == hexes
def test_hex_ring_pentagon(): h = '821c07fffffffff' out = h3.hex_ring(h, 1) expected = { '821c17fffffffff', '821c1ffffffffff', '821c27fffffffff', '821c2ffffffffff', '821c37fffffffff', } assert out == expected
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)
def test_2_polys_not_json(): h = '8928308280fffff' hexes = h3.hex_ring(h, 2) hexes = hexes | {h} # hexes should be a center hex, and the 2-ring around it # (with the 1-ring being absent) # not deterministic which poly is first.. poly1, poly2 = h3.h3_set_to_multi_polygon(hexes, geo_json=False) assert {len(poly1), len(poly2)} == {1, 2} for poly in poly1, poly2: for loop in poly: assert loop[0] != loop[-1]
def test_from_local_ij_error(): h = h3.geo_to_h3(0, 0, 0) baddies = [(1, -1), (-1, 1), (-1, -1)] for i, j in baddies: with pytest.raises(H3ValueError): h3.experimental_local_ij_to_h3(h, i, j) # inverting output should give good data nb = h3.hex_ring(h, k=1) goodies = {h3.experimental_h3_to_local_ij(h, p) for p in nb} out = {h3.experimental_local_ij_to_h3(h, i, j) for i, j in goodies} assert out == nb
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)
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', } assert out == expected assert out == h3.k_ring(h, 2) - h3.k_ring(h, 1)
def test6(): expected = {'8928308280fffff'} out = h3.hex_ring('8928308280fffff', 0) assert out == expected
def test_hex_ring_distance(): with pytest.raises(H3DistanceError): h3.hex_ring('8928308280fffff', -10)
# -*- coding: utf-8 -*- import h3 data=[] mylist=['86186c877ffffff'] for i, name in enumerate(['A','B','C','D','E','F']): mylist = [item for sublist in (h3.hex_ring(elem,5) for elem in mylist) for item in sublist] mylist = list(set(mylist)) for j,myh3 in enumerate(mylist): data.append(["%.2d:00:00"%(j%(i+1)), myh3, name, 0.0, 0]) datasets = [{"version": "v1", "data": {"id": "wve3blg3s", "label": "data.csv", "color": [143, 47, 191], "allData": data, "fields": [ {"name": "hour", "type": "timestamp", "format": "H:m:s", "analyzerType": "TIME"}, {"name": "H3", "type": "string", "format": "", "analyzerType": "STRING"}, {"name": "name", "type": "string", "format": "", "analyzerType": "STRING"},