Computing Distance Along Loxodrome in R (Example Code)

In this R programming tutorial you’ll learn how to calculate the distance between two geospatial points along a loxodrome.

Example Data

mat_ll <- matrix(c(75.13135, 79.06473,    # Define longitude & latitude points
                   15.28734, 14.29367),
                 ncol = 2)
colnames(mat_ll) <- c("long", "lati")
rownames(mat_ll) <- c("p1", "p2")
mat_ll                                    # Show longitude/latitude matrix in RStudio console
#        long     lati
# p1 75.13135 15.28734
# p2 79.06473 14.29367

Example: Create Rhumb Distance Matrix of a Set of Geographical Points

install.packages("geosphere")             # Install geosphere package
library("geosphere")                      # Load geosphere
distm(mat_ll, fun = distRhumb)            # Return geospatial distance
#          [,1]     [,2]
# [1,]      0.0 437560.1
# [2,] 437560.1      0.0

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top