hzar.map.greatCircleDistance: The distance between two points on the Earth's surface.

Description Usage Arguments Details Value Author(s) References Examples

View source: R/21-latLongPrep.R

Description

The distance along a great circle between two points on a spheroid approximation of the Earth's surface.

Usage

1
hzar.map.greatCircleDistance(lat1, long1, lat2, long2, units = "Km", degrees = TRUE)

Arguments

lat1

The latitude of point 1.

long1

The latitude of point 1.

lat2

The latitude of point 2.

long2

The latitude of point 2.

units

The units of distances returned. Only the case sensitive values "Km" for kilometers, "miles" for miles, and "nautical" for nautical miles are valid.

degrees

Are the latitude and longitude in degrees?

Details

The Lambert formula is the approximation used to calculate the distance, due to its high accuracy and robustness.

Geometry of Earth R = 6371.009 #Earth radius in kilometers earthSphd.r = 298.257223563 #WGS84 earthSphd.ep= (2*earthSphd.r -1)/(earthSphd.r-1)^2

dLat=p2$lat.rad-p1$lat.rad; dLong=p2$long.rad-p1$long.rad; dLong=ifelse( dLong>pi, dLong-2*pi, ifelse(-dLong>pi, dLong+2*pi, dLong));

mLat=(p2$lat.rad+p1$lat.rad)/2;

reLat1=atan((earthSphd.r -1)*tan(p1$lat.rad) /earthSphd.r ) reLat2=atan((earthSphd.r -1)*tan(p2$lat.rad) /earthSphd.r ) cenNum=sqrt((cos(reLat2)*sin(dLong))^2+(cos(reLat1)*sin(reLat2)-cos(reLat2)*sin(reLat1)*cos(dLong))^2); cenDen=sin(reLat1)*sin(reLat2)+cos(reLat2)*cos(reLat1)*cos(dLong); central <- atan2(cenNum,cenDen); lFP <- (reLat1+ reLat2)/2 ; lFQ <- (-reLat1+ reLat2)/2 ; lFX <- (central-sin(central))*sin(lFP)^2*cos(lFQ)^2/cos(central/2)^2; lFY <- (central+sin(central))*cos(lFP)^2*sin(lFQ)^2/sin(central/2)^2;

lambertFormulaeD <- ifelse(central==0,0,R*(central-(lFX+lFY)/(2*earthSphd.r)));

Value

The great circle distance between points 1 and 2.

Author(s)

Graham Derryberry asterion@alum.mit.edu

References

Lambert formula, published on the web somewhere.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
hzar.map.greatCircleDistance(89.5,60,89.5,390)
# 28.87587
hzar.map.greatCircleDistance(-89.5,-90,89.5,90)
# 19981.56
hzar.map.greatCircleDistance(-89.5,90,89.5,90)
# 19869.99
hzar.map.greatCircleDistance(0,90,89.5,90)
# 9934.996
hzar.map.greatCircleDistance(0,90,0,-90)
# 20015.12
hzar.map.greatCircleDistance(0,90,0,180)
# 10007.56

Example output

Loading required package: MCMCpack
Loading required package: coda
Loading required package: MASS
##
## Markov Chain Monte Carlo Package (MCMCpack)
## Copyright (C) 2003-2018 Andrew D. Martin, Kevin M. Quinn, and Jong Hee Park
##
## Support provided by the U.S. National Science Foundation
## (Grants SES-0350646 and SES-0350613)
##
Loading required package: foreach
[1] 28.87587
[1] 19981.56
[1] 19869.99
[1] 9934.996
[1] 20015.12
[1] 10007.56

hzar documentation built on May 2, 2019, 7 a.m.