/pCalcGeodist

Compute the distance between two geographic points (python code)

Primary LanguagePythonMIT LicenseMIT

pCalcGeodist

Compute the distance between two geographic points (python code)

Version

Release date

License

Programming language

OS

Requirements

import math

Function list

  1. calculate_distance Computes the distance between two points on the Earth's surface using the Haversine formula.

Arguments:

lat1: Latitude of the first point in degrees

lon1: Longitude of the first point in degrees

lat2: Latitude of the second point in degrees

lon2: Longitude of the second point in degrees

Returns: distance Distance between the two points in degrees

  1. convert_distance Converts the distance to the specified unit

Arguments:

distance: Distance to convert

unit: Unit of measurement to convert to ("km", "miles", or "nm")

Returns: Converted distance

Usage example

lat1 = -2
lon1 = -30
lat2 = -1
lon2 = -30
    
distance = calculate_distance(lat1, lon1, lat2, lon2)
converted_distance = convert_distance(distance, "km")

print("The distance between the two points is approximately {:.2f} {}.".format(converted_distance, unit))