An R package to calculate the distances and related measures for angular (longitude/latitude) locations
Questions tagged [geosphere]
170 questions
1
vote
2 answers
Alter a column based on results from geodistance matrix
I've got a dataframe that looks like this:
long lat site
-141.37 61.13 x1
-149.1833 66.7333 x2
-149.667 67.667 x3
-141.3667 61.1157 x4
I want to calculate the distances between all of the site's using…

fifigoblin
- 395
- 1
- 8
1
vote
0 answers
Create normalized pairwise matrix from trajectories with geographic coordinates R
I am dealing with a R list of geographic coordinates that embodies trajectories of drifters during a given period.
My list of data frames looks like this :
> str(traj_svp_sarg_from_d)
List of 5
$ SVP_undrogued_ID_4101647 :'data.frame': …

Sarah.B
- 11
- 3
1
vote
1 answer
Trying to find the distance between pairs of latitude and longitude coordinates
Currently have a data frame of 4 columns, "lon.x," "lat.x," "lon.y," "lat.y." with 581 rows.
I would like to find the distance between each pair of coordinates.
I tried:
library(geosphere)
distm(c(coords$lon_x, coords$lat_x),c(coords$lon_y,…

Angie
- 183
- 3
- 13
1
vote
1 answer
How to use longitude and latitude data effectively with distHarvesine()?
This is mostly a follow-up question on an older post (2017) see old post here
I have been working on a similar project and I appreciate the 2017 post for its usefulness. However, I struggle to understand and cannot find any documentation or…

Yach
- 357
- 3
- 16
1
vote
1 answer
Imputation missing environmental data based on geospatial distance
I want to impute missing values of Temp at a Station by replacing the mean of the Temp at two closest Stations.
library(tidyverse)
library(lubridate)
tb1 <-
tibble::tibble(
Date = as_date(rep(c("2019-01-01", "2019-01-02"), each = 4))
,…

MYaseen208
- 22,666
- 37
- 165
- 309
1
vote
1 answer
Average distance between subsets of points with ggmap /geosphere
I would like to determine the geographical distances from a number of addresses and determine the mean value (the mean distance) from these.
In case the dataframe has only one row, I have found a solution:
# Pakete…

Holger Esch
- 21
- 3
1
vote
2 answers
geosphere/R: Calculate intersection points between two great circles defined with 4 points
I'm trying to use geosphere to calculate intersection points between two great circles that are given in a dataframe format like this:
library(dplyr)
library(geosphere)
df <- data.frame(
# first line
ln1_lonb = 1:4,
ln1_lone = 2:5,
ln1_latb…

adl
- 1,390
- 16
- 36
1
vote
3 answers
How to use doParallel for calculating distance between zipcodes in R?
I have a large dataset (2.6M rows) with two zip codes and the corresponding latitudes and longitudes, and I am trying to compute the distance between them. I am primarily using the package geosphere to calculate Vincenty Ellipsoid distance between…

FightMilk
- 174
- 1
- 12
1
vote
1 answer
How to calculate shortest distance between longitude-latitude points in one dataset with those in another in a short time
I have two datasets, one with 488,286 rows and longitude and latitude coordinates and a second with 245,077 rows and longitude and latitiude coordinates. The second also has additional data relating for the coordinates. I want to find the closest…

user5481267
- 117
- 1
- 15
1
vote
1 answer
leaflet R combine markers and geodesic lines (coordonates connected in pairs)
Here is my data :
InitialLat InitialLong NewLat NewLong
62.46972 6.187194 51.4749 -0.221619
48.09750 16.310800 51.4882 -0.302621
I can connect my coordonates in pairs in leaflet with the geosphere library
(according to How…

Wilcar
- 2,349
- 2
- 21
- 48
1
vote
3 answers
Calculate step length using R
I would like to know if there's a specific function in R that calculates step length, as being the distance (in meters) between two consecutive GPS time-registered locations.
I have a dataset looking as follows:
> head(datagps)
Date & Time…

juansalix
- 503
- 1
- 8
- 21
1
vote
1 answer
Calculate multiple distances between two GPS coordinates and classify results in two columns
I'm new to R so I hope this question will be interesting enough. I'm working with GPS location data for which I have both latitude and longitude positions and an associated time and date.
Here's a sample of the data:
>…

juansalix
- 503
- 1
- 8
- 21
1
vote
2 answers
Calculating distance between two points for multiple records for matching rows - loop over rows of two matrices
I have got two matrices with coordinates and I am trying to compute distances between points in matching rows, i.e. between row 1 in first matrix and row 1 in second matrix.
What I am getting is computed distance between row 1 and all the other…

Kacper Rossa
- 77
- 7
1
vote
1 answer
While loop inside a for loop to calculate geospatial distance between 2 datasets in R
I have a data.table with 957 geocodes. I want to match it with another dataset with 317 geocodes. The matching condition is geospatial proximity. I want to match each observation from the first dataset to an observation from the second one such…

Arturo Sbr
- 5,567
- 4
- 38
- 76
1
vote
2 answers
Match two datasets by minimum geospatial distance (R)
I have the two following datasets:
houses <- data.table(house_number = c(1:3),
lat_decimal = seq(1.1, 1.3, by = 0.1),
lon_decimal = seq(1.4, 1.6, by = 0.1))
stations <- data.table(station_numer = c(1:11),
…

Arturo Sbr
- 5,567
- 4
- 38
- 76