Learn R Programming

stormwindmodel (version 0.1.4)

latlon_to_km: Calculate distance between two locations

Description

This function takes latitudes and longitudes for two locations and calculates the distance (in meters) between the locations using the Haversine method.

Usage

latlon_to_km(tclat_1, tclon_1, tclat_2, tclon_2, Rearth = 6378.14)

Arguments

tclat_1

A numeric vector giving latitude of the first location (degrees)

tclon_1

A numeric vector giving longitude of the first location (degrees). This value should be expressed as a positive value for Western hemisphere longitudes.

tclat_2

A numeric vector giving latitude of the second location (degrees)

tclon_2

A numeric vector giving longitude of the second location (degrees). This value should be expressed as a positive value for Western hemisphere longitudes.

Rearth

Radius of the earth (km). Default is 6378.14 km.

Value

A vector with the distance between the two locations, in kilometers.

Details

This function uses the Haversine method with great circle distance to calculate this distance. It is applying the following equations to determine distance (in kilometers) between two latitude-longitude pairs: $$hav(\gamma) = hav(\phi_1 - \phi_2) + cos(\phi_1)*cos(\phi_2)*hav(L_1 - L_2)$$ where:

  • \(\phi_1\): Latitude of first location, in radians

  • \(\phi_2\): Latitude of second location, in radians

  • \(L_1\): Longitude of first location, in radians

  • \(L_2\): Longitude of second location, in radians

  • \(hav(\gamma)\): The haversine function, \(hav(\gamma) = sin^2 \left(\frac{\gamma}{2}\right)\)

  • \(R_earth\): Radius of the earth, here assumed to be 6378.14 kilometers

  • \(D\): Distance between the two locations, in kilometers