Learn R Programming

insol (version 1.2.2)

GCdistance: Great circle distance

Description

Great circle or geodesic distance.

Usage

GCdistance(lat1,lon1,lat2,lon2)

Arguments

lat1

Latitude of points of origin.

lon1

Longitude of points of origin.

lat2

Latitude of points of destination.

lon2

Longitude of points of destination.

Value

Distance between origin and destination points in metres.

References

https://edwilliams.org/avform.htm,

http://mathworld.wolfram.com/GreatCircle.html.

Examples

Run this code
# NOT RUN {
GCdistance(0,0,0,180)*2

# distance between the center of US states 
data(state)
ddd = matrix(nrow=50,ncol=50,dimnames=list(state.name,state.name))
for (i in 1:50){
	for (j in 1:50){
		distij = GCdistance(state.center$y[i],state.center$x[i],
			state.center$y[j],state.center$x[j])
		# round to miles
		ddd[i,j]=round(distij/1609.344,2)
	}
}
# format and print results for the 10 firsts states
as.dist(ddd[1:10,1:10])


# }

Run the code above in your browser using DataLab