(
        self,
        buildings,
        enclosures,
        unique_id,
        enclosure_id="eID",
        threshold=0.05,
        use_dask=True,
        n_chunks=None,
        **kwargs,
    )
return tessellation.append(clean_blocks.drop(columns="position")).reset_index(
            drop=True
        )
Enclosed tessellation
        Generate enclosed tessellation based on barriers defining enclosures and
        building footprints.

        Parameters
        ----------
        buildings : GeoDataFrame
            GeoDataFrame containing building footprints. Expects (Multi)Polygon
            geometry.
        enclosures : GeoDataFrame
            Enclosures geometry. Can  be generated using :func:`momepy.enclosures`.
        unique_id : str
            name of the column with unique id of buildings gdf
        threshold : float (default 0.05)
            The minimum threshold for a building to be considered within an enclosure.
            Threshold is a ratio of building area which needs to be within an enclosure
            to inlude it in the tessellation of that enclosure. Resolves sliver geometry
            issues.
        use_dask : bool (default True)
            Use parallelised algorithm based on ``dask.dataframe``. Requires dask.
        n_chunks : None
            Number of chunks to be used in parallelization. Ideal is one chunk per
            thread. Applies only if ``enclosures`` are passed. Defualt automatically
            uses n == dask.system.cpu_count.
        **kwargs
            Keyword arguments passed to Tessellation algorithm (as ``shrink``
            or ``segment``).

        Returns
        -------
        tessellation : GeoDataFrame
            gdf contains three columns:
                geometry,
                unique_id matching with parental building,
                enclosure_id matching with enclosure integer index

        Examples
        --------
        >>> enclosures = mm.enclosures(streets, admin_boundary, [railway, rivers])
        >>> enclosed_tess = mm.enclosed_tessellation(buildings, enclosures)
Enclosed tessellation
        Generate enclosed tessellation based on barriers defining enclosures and
        building footprints.
Enclosed tessellation Generate enclosed tessellation based on barriers defining enclosures and building footprints .
def _enclosed_tessellation(
        self,
        buildings,
        enclosures,
        unique_id,
        enclosure_id="eID",
        threshold=0.05,
        use_dask=True,
        n_chunks=None,
        **kwargs,
    ):
        """Enclosed tessellation
        Generate enclosed tessellation based on barriers defining enclosures and
        building footprints.

        Parameters
        ----------
        buildings : GeoDataFrame
            GeoDataFrame containing building footprints. Expects (Multi)Polygon
            geometry.
        enclosures : GeoDataFrame
            Enclosures geometry. Can  be generated using :func:`momepy.enclosures`.
        unique_id : str
            name of the column with unique id of buildings gdf
        threshold : float (default 0.05)
            The minimum threshold for a building to be considered within an enclosure.
            Threshold is a ratio of building area which needs to be within an enclosure
            to inlude it in the tessellation of that enclosure. Resolves sliver geometry
            issues.
        use_dask : bool (default True)
            Use parallelised algorithm based on ``dask.dataframe``. Requires dask.
        n_chunks : None
            Number of chunks to be used in parallelization. Ideal is one chunk per
            thread. Applies only if ``enclosures`` are passed. Defualt automatically
            uses n == dask.system.cpu_count.
        **kwargs
            Keyword arguments passed to Tessellation algorithm (as ``shrink``
            or ``segment``).

        Returns
        -------
        tessellation : GeoDataFrame
            gdf contains three columns:
                geometry,
                unique_id matching with parental building,
                enclosure_id matching with enclosure integer index

        Examples
        --------
        >>> enclosures = mm.enclosures(streets, admin_boundary, [railway, rivers])
        >>> enclosed_tess = mm.enclosed_tessellation(buildings, enclosures)

        """
        enclosures = enclosures.reset_index(drop=True)
        enclosures["position"] = range(len(enclosures))

        # determine which polygons should be split
        inp, res = buildings.sindex.query_bulk(
            enclosures.geometry, predicate="intersects"
        )
        unique, counts = np.unique(inp, return_counts=True)
        splits = unique[counts > 1]
        single = unique[counts == 1]

        if use_dask:
            try:
                import dask.bag as db
                from dask.system import cpu_count
            except ImportError:
                use_dask = False

                warnings.warn(
                    "dask.dataframe could not be imported. Setting `use_dask=False`."
                )

        if use_dask:
            if n_chunks is None:
                n_chunks = cpu_count() - 1 if cpu_count() > 1 else 1
            # initialize dask.bag
            bag = db.from_sequence(splits, npartitions=n_chunks)
            # generate enclosed tessellation using dask
            new = bag.map(
                self._tess,
                enclosures,
                buildings,
                inp,
                res,
                threshold,
                unique_id,
            ).compute()

        else:
            new = [
                self._tess(
                    i,
                    enclosures,
                    buildings,
                    inp,
                    res,
                    threshold=threshold,
                    unique_id=unique_id,
                    **kwargs,
                )
                for i in splits
            ]

        # finalise the result
        clean_blocks = enclosures.drop(splits)
        clean_blocks.loc[single, "uID"] = clean_blocks.loc[single, "position"].apply(
            lambda ix: buildings.iloc[res[inp == ix][0]][unique_id]
        )
        tessellation = pd.concat(new)

        return tessellation.append(clean_blocks.drop(columns="position")).reset_index(
            drop=True
        )
def _enclosed_tessellation ( self , buildings , enclosures , unique_id , enclosure_id = "eID" , threshold = 0.05 , use_dask = True , n_chunks = None , * * kwargs , ) : enclosures = enclosures . reset_index ( drop = True ) enclosures [ "position" ] = range ( len ( enclosures ) ) # determine which polygons should be split inp , res = buildings . sindex . query_bulk ( enclosures . geometry , predicate = "intersects" ) unique , counts = np . unique ( inp , return_counts = True ) splits = unique [ counts > 1 ] single = unique [ counts == 1 ] if use_dask : try : import dask . bag as db from dask . system import cpu_count except ImportError : use_dask = False warnings . warn ( "dask.dataframe could not be imported. Setting `use_dask=False`." ) if use_dask : if n_chunks is None : n_chunks = cpu_count ( ) - 1 if cpu_count ( ) > 1 else 1 # initialize dask.bag bag = db . from_sequence ( splits , npartitions = n_chunks ) # generate enclosed tessellation using dask new = bag . map ( self . _tess , enclosures , buildings , inp , res , threshold , unique_id , ) . compute ( ) else : new = [ self . _tess ( i , enclosures , buildings , inp , res , threshold = threshold , unique_id = unique_id , * * kwargs , ) for i in splits ] # finalise the result clean_blocks = enclosures . drop ( splits ) clean_blocks . loc [ single , "uID" ] = clean_blocks . loc [ single , "position" ] . apply ( lambda ix : buildings . iloc [ res [ inp == ix ] [ 0 ] ] [ unique_id ] ) tessellation = pd . concat ( new ) return tessellation . append ( clean_blocks . drop ( columns = "position" ) ) . reset_index ( drop = True )