Esempio n. 1
0
 def test_hex_range2(self):
     hexagons = h3.hex_range('8928308280fffff', 2)
     self.assertEqual(1 + 6 + 12, len(hexagons),
                      'got the expected number of hexagons for two rings')
     expected_hexagons = [
         '89283082813ffff',
         '89283082817ffff',
         '8928308281bffff',
         '89283082863ffff',
         '89283082823ffff',
         '89283082873ffff',
         '89283082877ffff',
         '8928308287bffff',
         '89283082833ffff',
         '8928308282bffff',
         '8928308283bffff',
         '89283082857ffff',
         '892830828abffff',
         '89283082847ffff',
         '89283082867ffff',
         '89283082803ffff',
         '89283082807ffff',
         '8928308280bffff',
         '8928308280fffff',
     ]
     for hexagon in expected_hexagons:
         self.assertIn(hexagon, hexagons, 'found an expected hexagon')
def occupied_neighbors(hex,
                       density_tgt,
                       density_max,
                       N,
                       hex_density,
                       method='siblings'):
    """

    :param hex: hex to query
    :param density_tgt: target density for hexs at this resolution
    :param density_max: maximum density at this resolution
    :param hex_density: dictionary of densities at each hex
    :param N:
    :param method: either siblings or neighbors
    :return:
    """
    # neigbhors = h3.hex_range(h, 1)
    #neigbhors = h3.h3_to_children(h3.h3_to_parent(h, resolution - 1), resolution)
    res = h3.h3_get_resolution(hex)
    if method == 'siblings':
        neighbors = h3.h3_to_children(h3.h3_to_parent(hex, res - 1), res)
    elif method == 'neighbors':
        neighbors = h3.hex_range(hex, 1)

    neighbors_above_tgt = 0
    for n in neighbors:
        if n not in hex_density:
            continue
        if hex_density[n]['clipped'] >= density_tgt:
            neighbors_above_tgt += 1
    clip = min(density_max, density_tgt * max(1,
                                              (neighbors_above_tgt - N + 1)))
    return clip
Esempio n. 3
0
 def test_hex_range(self):
     hexagons = h3.hex_range('8928308280fffff', 1)
     self.assertEqual(
         1 + 6, len(hexagons),
         'got the expected number of hexagons for a single ring')
     expected_hexagons = [
         '8928308280fffff',
         '8928308280bffff',
         '89283082807ffff',
         '89283082877ffff',
         '89283082803ffff',
         '89283082873ffff',
         '8928308283bffff',
     ]
     for hexagon in expected_hexagons:
         self.assertIn(hexagon, hexagons, 'found an expected hexagon')
Esempio n. 4
0
    def test_hex_range_pentagon(self):
        with pytest.raises(ValueError) as e_info:
            h3.hex_range('821c07fffffffff', 1)

        self.assertTrue(isinstance(e_info.value, ValueError))