Skip to content

Calculate geometry

calculate_geometry(geodataframe)

Calculate the length or area of the given geometries.

Parameters:

Name Type Description Default
geodataframe GeoDataFrame

Geometries to be calculated.

required

Returns:

Name Type Description
calculated_gdf GeoDataFrame

Geometries and calculated values.

Source code in eis_toolkit/vector_processing/calculate_geometry.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
@beartype
def calculate_geometry(geodataframe: gpd.GeoDataFrame) -> gpd.GeoDataFrame:
    """Calculate the length or area of the given geometries.

    Args:
        geodataframe: Geometries to be calculated.

    Returns:
        calculated_gdf: Geometries and calculated values.

    Raises:
        EmptyDataFrameException if input geodataframe is empty.
    """
    if geodataframe.shape[0] == 0:
        raise EmptyDataFrameException("Expected geodataframe to contain geometries.")

    calculated_gdf = geodataframe.copy()
    calculated_gdf["value"] = calculated_gdf.apply(lambda row: _calculate_value(row), axis=1)

    return calculated_gdf