Skip to content

Extract shared lines

extract_shared_lines(polygons)

Extract shared lines/borders/edges between polygons.

Parameters:

Name Type Description Default
polygons GeoDataFrame

The geodataframe that contains the polygon geometries to be examined for shared lines.

required

Returns:

Type Description
GeoDataFrame

Geodataframe containing the shared lines that were found between the polygons.

Source code in eis_toolkit/vector_processing/extract_shared_lines.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@beartype
def extract_shared_lines(polygons: gpd.GeoDataFrame) -> gpd.GeoDataFrame:
    """Extract shared lines/borders/edges between polygons.

    Args:
        polygons: The geodataframe that contains the polygon geometries to be examined
            for shared lines.

    Returns:
        Geodataframe containing the shared lines that were found between the polygons.

    Raises:
        EmptyDataFrameException if input geodataframe is empty.
        InvalidParameterValueException if input geodataframe doesn't contain at least 2 polygons.
    """
    if polygons.shape[0] == 0:
        raise EmptyDataFrameException("Geodataframe is empty.")

    if polygons.shape[0] < 2:
        raise InvalidParameterValueException("Expected GeoDataFrame to have at least 2 polygons.")

    shared_lines = _extract_shared_lines(polygons)

    return shared_lines