osbng.bng_reference.BNGReference.bng_distance#

BNGReference.bng_distance(bng_ref2: BNGReference, *, edge_to_edge: bool = False) float[source]#

Returns the euclidean distance between bng_ref2 and this BNGReference.

When edge_to_edge is False, the distance is the centroid-to-centroid distance in metres. When edge_to_edge is True, the distance is the shortest distance between any two parts of the grid squares.

Notes

The other BNGReference object does not necessarily need to share a common resolution. When edge_to_edge = True and the two BNGReference objects have a parent-child relationship, the returned distance is 0.

Parameters:

bng_ref2 (BNGReference) – A BNGReference object .

Keyword Arguments:

edge_to_edge (bool, optional) – If False (default), distance will be centroid-to-centroid distance. If True, distance will be the shortest distance between any point in the grid squares.

Returns:

The euclidean distance between the centroids of the two BNGReference objects.

Return type:

float

Raises:

Examples

>>> BNGReference("SE1433").bng_distance(BNGReference("SE1533"))
1000.0
>>> BNGReference("SE1433").bng_distance(
...     BNGReference("SE1533"), edge_to_edge=True
... )
0.0
>>> BNGReference("SE1433").bng_distance(BNGRerence("SE1631"))
2828.42712474619
>>> BNGReference("SE1433").bng_distance(BNGRerence("SE"))
39147.158262126766
>>> BNGReference("SE1433").bng_distance(BNGRerence("SENW"))
42807.709586007986
>>> BNGReference("SE").bng_distance(BNGRerence("OV"))
141421.35623730952
>>> BNGReference("SU").bng_distance(
...     BNGReference("SU2345"), edge_to_edge=True
... )
0.0

See also

The equivalent osbng.traversal.bng_distance() function.