def cells_to_h3shape()

in src/h3/api/numpy_int/__init__.py [0:0]


def cells_to_h3shape(cells, *, tight=True):
    """
    Return an ``H3Shape`` describing the area covered by a collection of H3 cells.
    Will return ``LatLngPoly`` or ``LatLngMultiPoly``.

    Parameters
    ----------
    cells : iterable of H3 cells
    tight : bool
        If True, return ``LatLngPoly`` if possible.
        If False, always return ``LatLngMultiPoly``.

    Returns
    -------
    LatLngPoly | LatLngMultiPoly

    Examples
    --------

    >>> cells = ['8428309ffffffff', '842830dffffffff']
    >>> h3.cells_to_h3shape(cells, tight=True)
    <LatLngPoly: [10]>
    >>> h3.cells_to_h3shape(cells, tight=False)
    <LatLngMultiPoly: [10]>
    """
    cells = _in_collection(cells)
    mpoly = _cy.cells_to_multi_polygon(cells)

    polys = [LatLngPoly(*poly) for poly in mpoly]
    out = LatLngMultiPoly(*polys)

    if tight and len(out) == 1:
        out = out[0]

    return out