def test_subcells(self):
     for rdggs in [WGS84_123, WGS84_123_RADIANS]:
         l = 6
         C = Cell(rdggs, (S, 1, 0, 5, 7, 7, 3))
         s = list(C.subcells(l + 1))
         t = [Cell(rdggs, list(C.suid) + [i]) for i in range(9)]
         for i in range(9):
             self.assertTrue(s[i] == t[i])
def _get_finest_cell(polygon, suid):
    parent_cell = Cell(suid=suid)
    # get the children cells and polygons for these cells
    children_cells = [cell for cell in parent_cell.subcells()]
    children_poly = [
        Polygon(cell.vertices(plane=False)) for cell in children_cells
    ]
    # function and truth list for multipolygon / polygon (polygon) contained within multipolygon / polygon (cell)
    truth = [poly.contains(polygon) for poly in children_poly]
    # if we get something back, check the next level lower
    returned_cells = list(compress(children_cells, truth))
    if returned_cells:
        finest = _get_finest_cell(polygon, returned_cells[0].suid)
    else:
        parent_poly = Polygon(parent_cell.vertices(plane=False))
        if parent_poly.contains(polygon):
            finest = parent_cell
        else:
            finest = None
    return finest