Distance and Azimuth from two points

Description

Calculate distance, Azimuth and Back-Azimuth from two points on Globe.

Usage

1
distaz(olat, olon, tlat, tlon)

Arguments

olat

origin latitude, degrees

olon

origin longitude, degrees

tlat

target latitude, degrees

tlon

target longitude, degrees

Details

Program is set up for one origin (olat, olon) pair and many target (tlat, tlon) pairs given as vectors.

If multiple olat and olon are given, the program returns a list of outputs for each.

If olat or any tlat is greater than 90 or less than -90 NA is returned and error flag is 0.

If any tlat and tlon is equal to olat and olon, the points are coincident. In that case the distances are set to zero, but the az and baz are NA, and the error flag is set to 0.

Value

List:

del

Delta, angle in degrees

az

Azimuth, angle in degrees

baz

back Azimuth, (az+180) in degrees

dist

distance in km

err

0 or 1, error flag. 0=error, 1=no error, see details

Author(s)

Jonathan M. Lees<jonathan.lees@unc.edu>

See Also

along.great, getgreatarc

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
####  one point
d = distaz(12, 23, -32,    -65)
d

####  many random target points
org = c(80.222, -100.940)
targ = cbind(runif(10, 10, 50), runif(10, 20, 100))


distaz(org[1], org[2], targ[,1], targ[,2])

############  if origin and target are identical
#####  the distance is zero, but the az and baz are not defined
distaz(80.222, -100.940, 80.222, -100.940)


########################   set one of the targets equal to the origin
targ[7,1] = org[1]
targ[7,2] = org[2]

distaz(org[1], org[2], targ[,1], targ[,2])

####  put in erroneous latitude data

targ[3,1] = -91.3


distaz(org[1], org[2], targ[,1], targ[,2])

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.