compute_dist: Compute distance between points on the globe

Description Usage Arguments Value Examples

View source: R/compute_dist.R

Description

This function computes distances between an arbitrary number of points on the globe

Usage

1
compute_dist(lon, lat, lon0, lat0, Rearth = 6371)

Arguments

lon,lat

points from which distance is measured (in degree)

lon0,lat0

points to which distance is measured (in degree)

Rearth

Earth's radius (defaults to 6371km)

Value

Distance between points in km

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## read in some netcdf data
tas <- readNetCDF(system.file("extdata", "annual_CRUTEMv3_1961-90.nc", package="geoutils"), varname="temp")
lons <- attr(tas, 'lon')
lats <- attr(tas, 'lat')
## compute distance from greenwich
gdist <- compute_dist(lons, lats, 0, 50)

## set up new netcdf object for plotting
gdist <- as.matrix(gdist)
class(gdist) <- 'NetCDF'
attr(gdist, 'lon') <- lons
attr(gdist, 'lat') <- lats

## plot the distances
plot(gdist, type='mean', ti=1)
map(add=T, interior=F)

jonasbhend/geoutils documentation built on May 19, 2019, 7:27 p.m.