mat_geo_dist: Compute Euclidean geographic distances between points

Description Usage Arguments Details Value Author(s) Examples

View source: R/mat_geo_dist.R

Description

The function computes Euclidean geographic distance between points given their spatial coordinates either in a metric projected Coordinate Reference System or in a polar coordinates system.

Usage

1
2
3
4
5
6
7
8
mat_geo_dist(
  data,
  ID = NULL,
  x = NULL,
  y = NULL,
  crds_type = "proj",
  gc_formula = "vicenty"
)

Arguments

data

An object of class :

  • data.frame with 3 columns: 2 columns with the point spatial coordinates and another column with point IDs

  • SpatialPointsDataFrame

ID

(if data is of class data.frame) A character string indicating the name of the column of data with the point IDs

x

(if data is of class data.frame) A character string indicating the name of the column of data with the point longitude

y

(if data is of class data.frame) A character string indicating the name of the column of data with the point latitude

crds_type

A character string indicating the type of coordinate reference system:

  • 'proj' (default): a projected coordinate reference system

  • 'polar': a polar coordinate reference system, such as WGS84

gc_formula

A character string indicating the formula used to compute the Great Circle distance:

  • 'vicenty'(default): Vincenty inverse formula for ellipsoids

  • 'slc': Spherical Law of Cosines

  • 'hvs': Harversine formula

Details

When a projected coordinate reference system is used, it calculates classical Euclidean geographic distance between two points using Pythagora's theorem. When a polar coordinate reference system is used, it calculates the Great circle distance between points using different methods. Unless method = "polar", when data is a data.frame, it assumes projected coordinates by default.

Value

A pairwise matrix of geographic distances between points in meters

Author(s)

P. Savary

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Projected CRS
data(pts_pop_simul)
mat_dist <- mat_geo_dist(data=pts_pop_simul,
             ID = "ID",
             x = "x",
             y = "y")

#Polar CRS
city_us <- data.frame(name = c("New York City", "Chicago",
                               "Los Angeles", "Atlanta"),
                      lat  = c(40.75170,  41.87440,
                               34.05420,  33.75280),
                      lon  = c(-73.99420, -87.63940,
                              -118.24100, -84.39360))
mat_geo_us <- mat_geo_dist(data = city_us,
                           ID = "name", x = "lon", y = "lat",
                           crds_type = "polar")

graph4lg documentation built on March 16, 2021, 5:09 p.m.