snowflake.snowpark.functions.haversine¶
- snowflake.snowpark.functions.haversine(lat1: Union[snowflake.snowpark.column.Column, str], lon1: Union[snowflake.snowpark.column.Column, str], lat2: Union[snowflake.snowpark.column.Column, str], lon2: Union[snowflake.snowpark.column.Column, str]) Column[source]¶
Calculates the great circle distance in kilometers between two points on Earth using the Haversine formula.
- Parameters:
lat1 (ColumnOrName) – The latitude of the first point in degrees.
lon1 (ColumnOrName) – The longitude of the first point in degrees.
lat2 (ColumnOrName) – The latitude of the second point in degrees.
lon2 (ColumnOrName) – The longitude of the second point in degrees.
- Returns:
The distance in kilometers between the two points.
- Return type:
Example:
>>> df = session.create_dataframe([[40.7127, -74.0059, 34.0500, -118.2500]], schema=["lat1", "lon1", "lat2", "lon2"]) >>> df.select(haversine(df["lat1"], df["lon1"], df["lat2"], df["lon2"]).alias("distance")).collect() [Row(DISTANCE=3936.3850963892937)]