Skip to content

weighting

Weighting functions for spatial data.

add_binary_distance_band_column(dataframe, threshold, include_zero_distance_neighbors=True, include_self=False, geometry=None, use_spheroid=False)

Annotates a dataframe with a weights column containing the other records within the threshold and their weight.

Weights will always be 1.0. The dataframe should contain at least one GeometryType column. Rows must be unique. If one geometry column is present it will be used automatically. If two are present, the one named 'geometry' will be used. If more than one are present and neither is named 'geometry', the column name must be provided. The new column will be named 'cluster'.

Parameters:

Name Type Description Default
dataframe DataFrame

DataFrame with geometry column

required
threshold float

Distance threshold for considering neighbors

required
include_zero_distance_neighbors bool

whether to include neighbors that are 0 distance. If 0 distance neighbors are included and binary is false, values are infinity as per the floating point spec (divide by 0)

True
include_self bool

whether to include self in the list of neighbors

False
geometry Optional[str]

name of the geometry column

None
use_spheroid bool

whether to use a cartesian or spheroidal distance calculation. Default is false

False

Returns:

Type Description
DataFrame

The input DataFrame with a weight column added containing neighbors and their weights (always 1) added to each

DataFrame

row.

add_distance_band_column(dataframe, threshold, binary=True, alpha=-1.0, include_zero_distance_neighbors=False, include_self=False, self_weight=1.0, geometry=None, use_spheroid=False)

Annotates a dataframe with a weights column containing the other records within the threshold and their weight.

The dataframe should contain at least one GeometryType column. Rows must be unique. If one geometry column is present it will be used automatically. If two are present, the one named 'geometry' will be used. If more than one are present and neither is named 'geometry', the column name must be provided. The new column will be named 'cluster'.

Parameters:

Name Type Description Default
dataframe DataFrame

DataFrame with geometry column

required
threshold float

Distance threshold for considering neighbors

required
binary bool

whether to use binary weights or inverse distance weights for neighbors (dist^alpha)

True
alpha float

alpha to use for inverse distance weights ignored when binary is true

-1.0
include_zero_distance_neighbors bool

whether to include neighbors that are 0 distance. If 0 distance neighbors are included and binary is false, values are infinity as per the floating point spec (divide by 0)

False
include_self bool

whether to include self in the list of neighbors

False
self_weight float

the value to use for the self weight

1.0
geometry Optional[str]

name of the geometry column

None
use_spheroid bool

whether to use a cartesian or spheroidal distance calculation. Default is false

False

Returns:

Type Description
DataFrame

The input DataFrame with a weight column added containing neighbors and their weights added to each row.