Skip to content

haversine

relationalai.semantics.std.math
haversine(
lat1: NumberValue,
lon1: NumberValue,
lat2: NumberValue,
lon2: NumberValue,
radius: NumberValue = 1.0,
) -> Expression

Compute the haversine distance between two points on a sphere.

The haversine formula determines the great-circle distance between two points on a sphere given their longitudes and latitudes.

  • lat1

    (NumberValue) - Latitude of the first point in radians.
  • lon1

    (NumberValue) - Longitude of the first point in radians.
  • lat2

    (NumberValue) - Latitude of the second point in radians.
  • lon2

    (NumberValue) - Longitude of the second point in radians.
  • radius

    (NumberValue, default: 1.0) - Radius of the sphere. Default: 1.0.
  • Expression - An Expression computing the haversine distance. Returns Float.

Calculate distance between two points on Earth (radius ~6371 km):

>>> math.haversine(lat1, lon1, lat2, lon2, radius=6371)