Learn R Programming

McSpatial (version 1.1.1)

geodistance: Calculates distances using the great circle formula

Description

geodistance calculates distances in miles between a set of observations and a location. Distances are calculated in miles using the great circle formula. Geographic coordinates must be expressed in latitudes and longitudes.

Usage

geodistance(longvar, latvar, lotarget, latarget, dcoor = TRUE)

Arguments

longvar
Longitude variable, in degrees.
latvar
Latitude variable, in degrees.
lotarget
Target longitude.
latarget
Target latitude.
dcoor
If dcoor = T, also calculates the distance east (deast) and north (dnorth) of the target point.

Value

  • distA vector with the distance in miles between each data point and the target point.
  • dnorthA vector with the number of miles north of the target point for each data point. dnorth < 0 for observations that are south of the target point.
  • deastA vector with the number of miles east of the target point for each data point. deast < 0 for observations that are west of the target point.

See Also

geodensity geoshape

Examples

Run this code
data(cookdata)
dmat <- geodistance(longvar=cookdata$LONGITUDE ,latvar=cookdata$LATITUDE,  lotarget=-87.627800, 
	latarget=41.881998)
cookdata$dcbd <- dmat$dist
cookdata$dnorth <- dmat$dnorth
cookdata$deast <- dmat$deast

Run the code above in your browser using DataLab