geo_point_dist: Distance Between Two Latitude and Longitude Points

Description Usage Arguments Value Author(s) See Also Examples

View source: R/geo_point_dist.R

Description

Calculates the distance in kilometers between up to a combination of three latitude, longitude points

Usage

1
geo_point_dist(coordinate_matrix, matrix = FALSE)

Arguments

coordinate_matrix

A matrix of latitude and longitude columns and up to three rows of points

matrix

Generates a matrix that shows/preseves the relationship between point combinations and the respective distance between them

Value

An input matrix with two rows returns a vector of length 1 containing the calculated distance. If the matrix argument is set to FALSE and an input matrix with three rows is given as the coordinate_matrix argument a vector of length 3 containing the calculated distances is returned. If the matrix argument is set to TRUE and an input matrix with three rows is given as the coordinate_matrix argument a 3 by 3 matrix of distances is returned.

Author(s)

Shant Sukljian

See Also

geo_sed geo_point_dist

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Load required packages
require(mapview)
require(sp)

# Create sample geo dataset
sample_coord <-
   matrix(
        c(
            sample(327131680:419648450, 3) / 10000000,
            sample(-1147301410:-1241938690, 3) / 10000000
        ),
        ncol = 2
    )

# Calculate distances
(gpd <- geo_point_dist(sample_coord))

# Calculate distances and preserve relationship (Useful for three input points)
(gpd <- geo_point_dist(sample_coord, matrix = TRUE))

# Create SpacialPoints object and pass to mapview for visualization
mapview(
    SpatialPoints(
        sample_coord[,c(2, 1)],
        proj4string = CRS("+proj=longlat +datum=WGS84")
    )
)

geosed documentation built on Sept. 3, 2019, 9:04 a.m.