haversine_distance_km

Description

Computes the great circle approximate distance between two latitude/longitude coordinates, using the haversine formula. Arguments are in decimal degrees, and the result unit is kilometers, and is approximate to within about 1% because it does not compensate for the full shape distortion of the Earth.

The argument order is lat1, lon2, lat2, lon2, where each latitude must be in the range -90.0 to 90.0 degrees, and each longitude must be in the range -180.0 to 180.0 degrees. Invalid input values result in a null output.

Return type

float64

Domain

This is a scalar function (calculates a single output value for a single input row.)

Categories

Usage

haversine_distance_km( lat1, lon1, lat2, lon2 )

Argument

Type

Required

Multiple

Constant

lat1

float64

Required

Only one

Variable

lon1

float64

Required

Only one

Variable

lat2

float64

Required

Only one

Variable

lon2

float64

Required

Only one

Variable

Examples

make_col distance:haversine_distance_km(
    37.563, -122.326,   // San Mateo
    47.377,    8.542    // Zurich
    )

Make a new column distance which computes the approximate distance in kilometers between San Mateo, CA (37.563 N, 122.326 W) and Zurich, CH (47.377 N, 8.542 E), which is about 9386 kilometers.