Skip to content

IDW

idw(geodataframe, target_column, raster_profile, power=2)

Calculate inverse distance weighted (IDW) interpolation.

Parameters:

Name Type Description Default
geodataframe GeoDataFrame

The vector dataframe to be interpolated.

required
target_column str

The column name with values for each geometry.

required
raster_profile Union[Profile, dict]

The raster profile used for output grid properties. Needs to include at least crs, transform, width and height.

required
power Number

The value for determining the rate at which the weights decrease. As power increases, the weights for distant points decrease rapidly. Defaults to 2.

2

Returns:

Type Description
ndarray

Numpy array containing the interpolated values.

Raises:

Type Description
EmptyDataFrameException

The input GeoDataFrame is empty.

InvalidParameterValueException

Invalid resolution or target_column.

NonMatchingCrsException

The input GeoDataFrame and raster profile have mismatching CRS.

Source code in eis_toolkit/vector_processing/idw_interpolation.py
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
@beartype
def idw(
    geodataframe: gpd.GeoDataFrame,
    target_column: str,
    raster_profile: Union[profiles.Profile, dict],
    power: Number = 2,
) -> np.ndarray:
    """Calculate inverse distance weighted (IDW) interpolation.

    Args:
        geodataframe: The vector dataframe to be interpolated.
        target_column: The column name with values for each geometry.
        raster_profile: The raster profile used for output grid properties. Needs to include at least
            crs, transform, width and height.
        power: The value for determining the rate at which the weights decrease. As power increases,
            the weights for distant points decrease rapidly. Defaults to 2.

    Returns:
        Numpy array containing the interpolated values.

    Raises:
        EmptyDataFrameException: The input GeoDataFrame is empty.
        InvalidParameterValueException: Invalid resolution or target_column.
        NonMatchingCrsException: The input GeoDataFrame and raster profile have mismatching CRS.
    """
    if geodataframe.empty:
        raise EmptyDataFrameException("Expected geodataframe to contain geometries.")
    if raster_profile.get("crs") != geodataframe.crs:
        raise NonMatchingCrsException("Expected coordinate systems to match between raster and GeoDataFrame.")
    if target_column not in geodataframe.columns:
        raise InvalidParameterValueException(
            f"Expected target_column ({target_column}) to be contained in geodataframe columns."
        )
    check_raster_profile(raster_profile)

    raster_width = raster_profile.get("width")
    raster_height = raster_profile.get("height")
    raster_transform = raster_profile.get("transform")

    interpolated_values = _idw_interpolation(
        geodataframe, target_column, raster_width, raster_height, raster_transform, power
    )

    return interpolated_values