calc_distance_on_unit_sphere

pyhelpers.geom.calc_distance_on_unit_sphere(pt1, pt2, verbose=False)

Calculate distance between two points.

Parameters
  • pt1 (shapely.geometry.Point or list or tuple or numpy.ndarray) – a point

  • pt2 (shapely.geometry.Point or list or tuple or numpy.ndarray) – another point

  • verbose (bool or int) – whether to print relevant information in console as the function runs, defaults to False

Returns

distance (in miles) between pt1 and pt2 (relative to the earth’s radius)

Return type

float

Note

This function is modified from the original code available at [GEOM-CDOUS-1]. It assumes the earth is perfectly spherical and returns the distance based on each point’s longitude and latitude.

Examples:

>>> from pyhelpers.geom import calc_distance_on_unit_sphere
>>> from pyhelpers._cache import example_dataframe

>>> example_df = example_dataframe()
>>> example_df
            Longitude   Latitude
City
London      -0.127647  51.507322
Birmingham  -1.902691  52.479699
Manchester  -2.245115  53.479489
Leeds       -1.543794  53.797418

>>> london, birmingham = example_df.loc[['London', 'Birmingham']].values
>>> arc_len_in_miles = calc_distance_on_unit_sphere(london, birmingham)
>>> arc_len_in_miles
101.10431101941569