Skip to content

IDW

idw(geodataframe, target_column, resolution, extent=None, 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
resolution Tuple[Number, Number]

The resolution i.e. cell size of the output raster as (pixel_size_x, pixel_size_y).

required
extent Optional[Tuple[Number, Number, Number, Number]]

The extent of the output raster as (x_min, x_max, y_min, y_max). If None, calculate extent from the input vector data.

None
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
Tuple[ndarray, dict]

Rasterized vector data and metadata.

Raises:

Type Description
EmptyDataFrameException

The input GeoDataFrame is empty.

InvalidParameterValueException

Invalid resolution or target_column.

Source code in eis_toolkit/vector_processing/idw_interpolation.py
 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
104
105
106
107
108
109
@beartype
def idw(
    geodataframe: gpd.GeoDataFrame,
    target_column: str,
    resolution: Tuple[Number, Number],
    extent: Optional[Tuple[Number, Number, Number, Number]] = None,
    power: Number = 2,
) -> Tuple[np.ndarray, dict]:
    """Calculate inverse distance weighted (IDW) interpolation.

    Args:
        geodataframe: The vector dataframe to be interpolated.
        target_column: The column name with values for each geometry.
        resolution: The resolution i.e. cell size of the output raster as (pixel_size_x, pixel_size_y).
        extent: The extent of the output raster as (x_min, x_max, y_min, y_max).
            If None, calculate extent from the input vector data.
        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:
        Rasterized vector data and metadata.

    Raises:
        EmptyDataFrameException: The input GeoDataFrame is empty.
        InvalidParameterValueException: Invalid resolution or target_column.
    """

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

    if target_column not in geodataframe.columns:
        raise InvalidParameterValueException(
            f"Expected target_column ({target_column}) to be contained in geodataframe columns."
        )

    if resolution[0] <= 0 or resolution[1] <= 0:
        raise InvalidParameterValueException("Expected height and width greater than zero.")

    interpolated_values, out_meta = _idw_interpolation(geodataframe, target_column, resolution, power, extent)

    return interpolated_values, out_meta