GetDistance: Find distance between points on Earth

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/GetDistance.R

Description

This is a general function to calculate the distance on Earth between a target location and all points in a field of coordinates. It provides a straighforward interface to the function distGeo from package geosphere.

Usage

1
GetDistance(lat0, lon0, lat, lon, get.nearest = FALSE, verbose = FALSE)

Arguments

lat0

numeric vector of length 1 with the latitude (in degree) of the target location relative to which distances are to be calculated.

lon0

numeric vector of length 1 with the longitude (in degree) of the target location.

lat

numeric vector of latitudes (in degree) of the positions for which distances from the target position are to be calculated.

lon

numeric vector of longitudes (in degree) of the positions for which distances from the target position are to be calculated. Must have the same length as lat.

get.nearest

logical; specify whether the given 'lat0' - 'lon0' pair shall be used _as is_ as the target location (FALSE), or instead the nearest point of the positions specified by 'lat' and 'lon' (TRUE). Selection of the nearest point is currently implemented with MinimizeSpherical, for which the "pfields" package needs to be installed.

verbose

logical; if TRUE an informative message regarding the selected target location is printed.

Details

This is a wrapper function whose purpose it is to provide a straighforward interface to the function distGeo; this includes:

Value

Numeric vector of the same length as lat with the distances in km from the target location.

Author(s)

Thomas Münch

See Also

MinimizeSpherical; GetDistanceField; https://github.com/EarthSystemDiagnostics/pfields

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# some coordinates
lat0 <- -75
lon0 <- 0
lat <- seq(-74, -80, -2)
lon <- seq(-2, 7, 3)

d <- GetDistance(lat0, lon0, lat, lon, verbose = TRUE)
range(d)

d <- GetDistance(lat0, lon0, lat, lon, get.nearest = TRUE, verbose = TRUE)
range(d)

EarthSystemDiagnostics/ecustools documentation built on Jan. 15, 2022, 5:22 p.m.