def clip_gdf(gdf, tile_bounds, min_partial_perc=0.0, geom_type='Polygon', use_sindex=True, verbose=False):
    'Clip GDF to a provided polygon.\n\n    Clips objects within `gdf` to the region defined by\n    `poly_to_cut`. Also adds several columns to the output::\n\n        `origarea`\n            The original area of the polygons (only used if `geom_type` ==\n            ``"Polygon"``).\n        `origlen`\n            The original length of the objects (only used if `geom_type` ==\n            ``"LineString"``).\n        `partialDec`\n            The fraction of the object that remains after clipping\n            (fraction of area for Polygons, fraction of length for\n            LineStrings.) Can filter based on this by using `min_partial_perc`.\n        `truncated`\n            Boolean indicator of whether or not an object was clipped.\n\n    Arguments\n    ---------\n    gdf : :py:class:`geopandas.GeoDataFrame`\n        A :py:class:`geopandas.GeoDataFrame` of polygons to clip.\n    tile_bounds : `list` or :class:`shapely.geometry.Polygon`\n        The geometry to clip objects in `gdf` to. This can either be a\n        ``[left, top, right, bottom] `` bounds list or a\n        :class:`shapely.geometry.Polygon` object defining the area to keep.\n    min_partial_perc : float, optional\n        The minimum fraction of an object in `gdf` that must be\n        preserved. Defaults to 0.0 (include any object if any part remains\n        following clipping).\n    geom_type : str, optional\n        Type of objects in `gdf`. Can be one of\n        ``["Polygon", "LineString"]`` . Defaults to ``"Polygon"`` .\n    use_sindex : bool, optional\n        Use the `gdf` sindex be used for searching. Improves efficiency\n        but requires `libspatialindex <http://libspatialindex.github.io/>`__ .\n    verbose : bool, optional\n        Switch to print relevant values.\n\n    Returns\n    -------\n    cut_gdf : :py:class:`geopandas.GeoDataFrame`\n        `gdf` with all contained objects clipped to `poly_to_cut` .\n        See notes above for details on additional clipping columns added.\n\n    '
    if isinstance(tile_bounds, tuple):
        tb = box(*tile_bounds)
    elif isinstance(tile_bounds, list):
        tb = box(*tile_bounds)
    elif isinstance(tile_bounds, Polygon):
        tb = tile_bounds
    if (use_sindex and (geom_type == 'Polygon')):
        gdf = search_gdf_polygon(gdf, tb)
    if ('origarea' in gdf.columns):
        pass
    elif ('geom_type' == 'LineString'):
        gdf['origarea'] = 0
    else:
        gdf['origarea'] = gdf.area
    if ('origlen' in gdf.columns):
        pass
    elif ('geom_type' == 'LineString'):
        gdf['origlen'] = gdf.length
    else:
        gdf['origlen'] = 0
    cut_gdf = gdf.copy()
    cut_gdf.geometry = gdf.intersection(tb)
    if (geom_type == 'Polygon'):
        cut_gdf['partialDec'] = (cut_gdf.area / cut_gdf['origarea'])
        cut_gdf = cut_gdf.loc[(cut_gdf['partialDec'] > min_partial_perc), :]
        cut_gdf['truncated'] = (cut_gdf['partialDec'] != 1.0).astype(int)
    else:
        cut_gdf = cut_gdf[cut_gdf['geometry'].notnull()]
        cut_gdf['partialDec'] = 1
        cut_gdf['truncated'] = 0
        if ((len(cut_gdf) > 0) and verbose):
            print('clip_gdf() - gdf.iloc[0]:', gdf.iloc[0])
            print('clip_gdf() - tb:', tb)
            print('clip_gdf() - gdf_cut:', cut_gdf)
    return cut_gdf
Clip GDF to a provided polygon.

Clips objects within `gdf` to the region defined by
`poly_to_cut`. Also adds several columns to the output::

    `origarea`
        The original area of the polygons (only used if `geom_type` ==
        ``"Polygon"``).
    `origlen`
        The original length of the objects (only used if `geom_type` ==
        ``"LineString"``).
    `partialDec`
        The fraction of the object that remains after clipping
        (fraction of area for Polygons, fraction of length for
        LineStrings.) Can filter based on this by using `min_partial_perc`.
    `truncated`
        Boolean indicator of whether or not an object was clipped.

Arguments
---------
gdf : :py:class:`geopandas.GeoDataFrame`
    A :py:class:`geopandas.GeoDataFrame` of polygons to clip.
tile_bounds : `list` or :class:`shapely.geometry.Polygon`
    The geometry to clip objects in `gdf` to. This can either be a
    ``[left, top, right, bottom] `` bounds list or a
    :class:`shapely.geometry.Polygon` object defining the area to keep.
min_partial_perc : float, optional
    The minimum fraction of an object in `gdf` that must be
    preserved. Defaults to 0.0 (include any object if any part remains
    following clipping).
geom_type : str, optional
    Type of objects in `gdf`. Can be one of
    ``["Polygon", "LineString"]`` . Defaults to ``"Polygon"`` .
use_sindex : bool, optional
    Use the `gdf` sindex be used for searching. Improves efficiency
    but requires `libspatialindex <http://libspatialindex.github.io/>`__ .
verbose : bool, optional
    Switch to print relevant values.

Returns
-------
cut_gdf : :py:class:`geopandas.GeoDataFrame`
    `gdf` with all contained objects clipped to `poly_to_cut` .
    See notes above for details on additional clipping columns added.
def clip_gdf(gdf, tile_bounds, min_partial_perc=0.0, geom_type='Polygon', use_sindex=True, verbose=False):
    'Clip GDF to a provided polygon.\n\n    Clips objects within `gdf` to the region defined by\n    `poly_to_cut`. Also adds several columns to the output::\n\n        `origarea`\n            The original area of the polygons (only used if `geom_type` ==\n            ``"Polygon"``).\n        `origlen`\n            The original length of the objects (only used if `geom_type` ==\n            ``"LineString"``).\n        `partialDec`\n            The fraction of the object that remains after clipping\n            (fraction of area for Polygons, fraction of length for\n            LineStrings.) Can filter based on this by using `min_partial_perc`.\n        `truncated`\n            Boolean indicator of whether or not an object was clipped.\n\n    Arguments\n    ---------\n    gdf : :py:class:`geopandas.GeoDataFrame`\n        A :py:class:`geopandas.GeoDataFrame` of polygons to clip.\n    tile_bounds : `list` or :class:`shapely.geometry.Polygon`\n        The geometry to clip objects in `gdf` to. This can either be a\n        ``[left, top, right, bottom] `` bounds list or a\n        :class:`shapely.geometry.Polygon` object defining the area to keep.\n    min_partial_perc : float, optional\n        The minimum fraction of an object in `gdf` that must be\n        preserved. Defaults to 0.0 (include any object if any part remains\n        following clipping).\n    geom_type : str, optional\n        Type of objects in `gdf`. Can be one of\n        ``["Polygon", "LineString"]`` . Defaults to ``"Polygon"`` .\n    use_sindex : bool, optional\n        Use the `gdf` sindex be used for searching. Improves efficiency\n        but requires `libspatialindex <http://libspatialindex.github.io/>`__ .\n    verbose : bool, optional\n        Switch to print relevant values.\n\n    Returns\n    -------\n    cut_gdf : :py:class:`geopandas.GeoDataFrame`\n        `gdf` with all contained objects clipped to `poly_to_cut` .\n        See notes above for details on additional clipping columns added.\n\n    '
    if isinstance(tile_bounds, tuple):
        tb = box(*tile_bounds)
    elif isinstance(tile_bounds, list):
        tb = box(*tile_bounds)
    elif isinstance(tile_bounds, Polygon):
        tb = tile_bounds
    if (use_sindex and (geom_type == 'Polygon')):
        gdf = search_gdf_polygon(gdf, tb)
    if ('origarea' in gdf.columns):
        pass
    elif ('geom_type' == 'LineString'):
        gdf['origarea'] = 0
    else:
        gdf['origarea'] = gdf.area
    if ('origlen' in gdf.columns):
        pass
    elif ('geom_type' == 'LineString'):
        gdf['origlen'] = gdf.length
    else:
        gdf['origlen'] = 0
    cut_gdf = gdf.copy()
    cut_gdf.geometry = gdf.intersection(tb)
    if (geom_type == 'Polygon'):
        cut_gdf['partialDec'] = (cut_gdf.area / cut_gdf['origarea'])
        cut_gdf = cut_gdf.loc[(cut_gdf['partialDec'] > min_partial_perc), :]
        cut_gdf['truncated'] = (cut_gdf['partialDec'] != 1.0).astype(int)
    else:
        cut_gdf = cut_gdf[cut_gdf['geometry'].notnull()]
        cut_gdf['partialDec'] = 1
        cut_gdf['truncated'] = 0
        if ((len(cut_gdf) > 0) and verbose):
            print('clip_gdf() - gdf.iloc[0]:', gdf.iloc[0])
            print('clip_gdf() - tb:', tb)
            print('clip_gdf() - gdf_cut:', cut_gdf)
    return cut_gdf