Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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]
]
)
def test3():
expected = (
(37.775197782893386, -122.41719971841658),
(37.77688044840226, -122.41612835779264),
(37.778385004930925, -122.4173879761762),
(37.77820687262238, -122.41971895414807),
(37.77652420699321, -122.42079024541877),
(37.775019673792606, -122.4195306280734),
)
out = h3.h3_to_geo_boundary('8928308280fffff')
assert approx2(out, expected)
def test4():
expected = (
(-122.41719971841658, 37.775197782893386),
(-122.41612835779264, 37.77688044840226),
(-122.4173879761762, 37.778385004930925),
(-122.41971895414807, 37.77820687262238),
(-122.42079024541877, 37.77652420699321),
(-122.4195306280734, 37.775019673792606),
(-122.41719971841658, 37.775197782893386)
)
out = h3.h3_to_geo_boundary('8928308280fffff', geo_json=True)
assert approx2(out, expected)
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],
]
)
def test_h3_to_geo_boundary_geo_json():
out = h3.h3_to_geo_boundary('85283473fffffff', True)
expected = [
[-121.91508032705622, 37.271355866731895],
[-121.86222328902491, 37.353926450852256],
[-121.9235499963016, 37.42834118609435],
[-122.0377349642703, 37.42012867767778],
[-122.09042892904395, 37.33755608435298],
[-122.02910130919, 37.26319797461824],
[-121.91508032705622, 37.271355866731895],
]
assert len(out) == len(expected)
for o, e in zip(out, expected):
assert o == approx(e)
def test_validation_geo():
h = '8a28308280fffff' # invalid cell
with pytest.raises(H3CellError):
h3.h3_to_geo(h)
with pytest.raises(H3ResolutionError):
h3.geo_to_h3(0, 0, 17)
with pytest.raises(H3CellError):
h3.h3_to_geo_boundary(h)
with pytest.raises(H3CellError):
h3.h3_indexes_are_neighbors(h, h)
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],
vertices0[5],
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],
vertices0[5],
vertices1[4],