in src/h3/api/basic_str/__init__.py [0:0]
def h3shape_to_cells(h3shape, res):
"""
Return the set of H3 cells at a given resolution whose center points
are contained within an `H3Poly` or `H3MultiPoly`.
Parameters
----------
h3shape : H3shape
res : int
Resolution of the output cells
Returns
-------
unordered collection of H3Cell
Examples
--------
>>> poly = H3Poly(
... [(37.68, -122.54), (37.68, -122.34), (37.82, -122.34),
... (37.82, -122.54)],
... )
>>> h3.h3shape_to_cells(poly, 6)
{'862830807ffffff',
'862830827ffffff',
'86283082fffffff',
'862830877ffffff',
'862830947ffffff',
'862830957ffffff',
'86283095fffffff'}
Notes
-----
There is currently no guaranteed order of the output cells.
"""
# todo: not sure if i want this dispatch logic here. maybe in the objects?
if isinstance(h3shape, H3Poly):
poly = h3shape
mv = _cy.polygon_to_cells(poly.outer, res, holes=poly.holes)
elif isinstance(h3shape, H3MultiPoly):
mpoly = h3shape
mv = _cy.polygons_to_cells(mpoly.polys, res)
elif isinstance(h3shape, H3Shape):
raise ValueError('Unrecognized H3Shape: ' + str(h3shape))
else:
raise ValueError('Unrecognized type: ' + str(type(h3shape)))
return _out_collection(mv)