Calculates distances between two vectors of geometries. There are a number of different distance methods that can be utilized.
Usage
distance_euclidean_pairwise(x, y)
distance_hausdorff_pairwise(x, y)
distance_vicenty_pairwise(x, y)
distance_geodesic_pairwise(x, y)
distance_haversine_pairwise(x, y)
distance_euclidean_matrix(x, y)
distance_hausdorff_matrix(x, y)
distance_vicenty_matrix(x, y)
distance_geodesic_matrix(x, y)
distance_haversine_matrix(x, y)
Value
For _matrix
functions, returns a dense matrix of distances whereas _pairwise
functions return a numeric vector.
Details
There are _pairwise()
and _matrix()
suffixed functions to
generate distances pairwise or as a dense matrix respectively.
The pairwise functions calculate distances between the ith element
of each vector. Whereas the matrix functions calculate the distance
between each and every geometry.
Euclidean distance should be used for planar geometries. Haversine, Geodesic, and Vicenty are all methods of calculating distance based on spherical geometries. There is no concept of spherical geometries in rsgeo, so choose your distance measure appropriately.
Examples
set.seed(1)
x <- geom_point(runif(5, -1, 1), runif(5, -1, 1))
y <- rev(x)
distance_euclidean_matrix(x, y)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1.678069 1.3936593 0.7769445 0.2324579 0.0000000
#> [2,] 1.798381 1.2441299 0.6953524 0.0000000 0.2324579
#> [3,] 1.409373 0.6736956 0.0000000 0.6953524 0.7769445
#> [4,] 1.812225 0.0000000 0.6736956 1.2441299 1.3936593
#> [5,] 0.000000 1.8122247 1.4093730 1.7983809 1.6780693
#> attr(,"class")
#> [1] "matrix" "array"
distance_hausdorff_matrix(x, y)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1.678069 1.3936593 0.7769445 0.2324579 0.0000000
#> [2,] 1.798381 1.2441299 0.6953524 0.0000000 0.2324579
#> [3,] 1.409373 0.6736956 0.0000000 0.6953524 0.7769445
#> [4,] 1.812225 0.0000000 0.6736956 1.2441299 1.3936593
#> [5,] 0.000000 1.8122247 1.4093730 1.7983809 1.6780693
#> attr(,"class")
#> [1] "matrix" "array"
distance_vicenty_matrix(x, y)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 185558.6 154980.77 86270.25 25847.36 0.00
#> [2,] 198902.8 138252.31 77059.72 0.00 25847.36
#> [3,] 156131.3 74990.08 0.00 77059.72 86270.25
#> [4,] 201203.9 0.00 74990.08 138252.31 154980.77
#> [5,] 0.0 201203.87 156131.25 198902.84 185558.65
#> attr(,"class")
#> [1] "matrix" "array"
distance_geodesic_matrix(x, y)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 185558.6 154980.77 86270.25 25847.36 0.00
#> [2,] 198902.8 138252.31 77059.72 0.00 25847.36
#> [3,] 156131.3 74990.08 0.00 77059.72 86270.25
#> [4,] 201203.9 0.00 74990.08 138252.31 154980.77
#> [5,] 0.0 201203.87 156131.25 198902.84 185558.65
#> attr(,"class")
#> [1] "matrix" "array"
distance_haversine_matrix(x, y)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 186593.0 154961.98 86389.67 25845.81 0.00
#> [2,] 199970.8 138335.46 77318.22 0.00 25845.81
#> [3,] 156714.0 74910.69 0.00 77318.22 86389.67
#> [4,] 201506.7 0.00 74910.69 138335.46 154961.98
#> [5,] 0.0 201506.69 156714.04 199970.82 186593.01
#> attr(,"class")
#> [1] "matrix" "array"
distance_euclidean_pairwise(x, y)
#> [1] 1.678069 1.244130 0.000000 1.244130 1.678069
distance_hausdorff_pairwise(x, y)
#> [1] 1.678069 1.244130 0.000000 1.244130 1.678069
distance_vicenty_pairwise(x, y)
#> [1] 185558.6 138252.3 0.0 138252.3 185558.6
distance_geodesic_pairwise(x, y)
#> [1] 185558.6 138252.3 0.0 138252.3 185558.6
distance_haversine_pairwise(x, y)
#> [1] 186593.0 138335.5 0.0 138335.5 186593.0