Skip to content

IntersectionJoiner

srai.joiners.IntersectionJoiner

Bases: Joiner

Intersection Joiner.

Intersection Joiner allows to join two GeoDataFrames and find all overlapping geometries. It does not apply any grouping or aggregation.

transform(regions, features, return_geom=False)

Join features to regions based on an 'intersects' predicate.

Does not apply any grouping to regions.

PARAMETER DESCRIPTION
regions

regions with which features are joined

TYPE: gpd.GeoDataFrame

features

features to be joined

TYPE: gpd.GeoDataFrame

return_geom

whether to return geometry of the joined features. Defaults to False.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
gpd.GeoDataFrame

GeoDataFrame with an intersection of regions and features, which contains

gpd.GeoDataFrame

a MultiIndex and optionaly a geometry with the intersection

Source code in srai/joiners/intersection_joiner.py
def transform(
    self, regions: gpd.GeoDataFrame, features: gpd.GeoDataFrame, return_geom: bool = False
) -> gpd.GeoDataFrame:
    """
    Join features to regions based on an 'intersects' predicate.

    Does not apply any grouping to regions.

    Args:
        regions (gpd.GeoDataFrame): regions with which features are joined
        features (gpd.GeoDataFrame): features to be joined
        return_geom (bool): whether to return geometry of the joined features.
            Defaults to False.

    Returns:
        GeoDataFrame with an intersection of regions and features, which contains
        a MultiIndex and optionaly a geometry with the intersection
    """
    if GEOMETRY_COLUMN not in regions.columns:
        raise ValueError("Regions must have a geometry column.")
    if GEOMETRY_COLUMN not in features.columns:
        raise ValueError("Features must have a geometry column.")

    if len(regions) == 0:
        raise ValueError("Regions must not be empty.")
    if len(features) == 0:
        raise ValueError("Features must not be empty.")

    result_gdf: gpd.GeoDataFrame

    if return_geom:
        result_gdf = self._join_with_geom(regions, features)
    else:
        result_gdf = self._join_without_geom(regions, features)

    return result_gdf