An R package to calculate the distances and related measures for angular (longitude/latitude) locations
Questions tagged [geosphere]
170 questions
21
votes
4 answers
find locations within certain lat/lon distance in r
I have a gridded dataset, with data available at the following locations:
lon <- seq(-179.75,179.75, by = 0.5)
lat <- seq(-89.75,89.75, by = 0.5)
I would like to find all of the data points that are within 500 km of the location:
mylat <-…

Emma Tebbs
- 1,457
- 2
- 17
- 29
14
votes
1 answer
geosphere distHaversine() & dplyr - error wrong length for vector, should be 2
I am unable to resolve the error: "wrong length for vector, should be 2" when trying to calculate the (runway length) distance between two points (runway thresholds / ends).
To make things worse, I fail to understand answers like here R error: Wrong…

Rainer
- 195
- 1
- 6
13
votes
1 answer
World map showing day and night regions
I'm trying to add a daytime/nighttime line to a world map using ggplot in order to indicate day and night regions; something like this:
The plan is to animate my map over a 24 hour cycle like this:
The above animation is achieved using a sine…

jogall
- 651
- 6
- 21
12
votes
4 answers
R measuring distance from a coastline
I have a set of coordinates:
d1 <- data_frame(
title = c("base1", "base2", "base3", "base4"),
lat = c(57.3, 58.8, 47.2, 57.8, 65.4, 56.7, 53.3),
long = c(0.4, 3.4, 3.5, 1.2, 1.5, 2.6, 2.7))
I would like to know whether the coordinates fall on land,…

Mrmoleje
- 453
- 1
- 12
- 35
9
votes
1 answer
R calculating distance between 2 points on earth using package geosphere
My question is based upon this question. Using it I wrote below code where first set of coordinates are for LGA airport NY while second set of coordinates are for EWR airport NY. I get the answer 33713. Is that in miles or in kilometers? A quick…

user2543622
- 5,760
- 25
- 91
- 159
7
votes
1 answer
Using the geosphere distm function on a data.table to calculate distances
I've created a data.table in that has 6 columns. My data.table has a columns compairing two locations: Location 1 and Location 2. I'm trying to use the distm function to calculate the distance between the locations on each row, creating a 7th…

Nik
- 71
- 1
- 2
6
votes
3 answers
Calculating distance between two GPS locations in a data frame using distm () in R
This question has been asked previously but never with the following arrangement of the data. Below is a sample of it:
> head(datagps)
Date & Time [Local] Latitude Longitude
1: 2018-06-18 03:01:00 -2.434901 34.85359
2: 2018-06-18 03:06:00…

juansalix
- 503
- 1
- 8
- 21
5
votes
4 answers
Find closest points (lat / lon) from one data set to a second data set
I have two data sets, A and B, which give locations of different points in the UK as such:
A = data.frame(reference = c(C, D, E), latitude = c(55.32043, 55.59062, 55.60859), longitude = c(-2.3954998, -2.0650243, -2.0650542))
B =…

mbf
- 107
- 4
5
votes
4 answers
R: Calculating distance in miles from one point to another
I have the following data frames:
library(dplyr)
d1 <- data_frame(
title = c("base1", "base2", "base3", "base4"),
lat = c(57.3, 58.8, 47.2, 57.8),
long = c(0.4, 3.4, 3.5, 1.2))
d2 <- data_frame(
tas = c("tas1", "tas2", "tas3", "tas4"),
Base= c…

Mrmoleje
- 453
- 1
- 12
- 35
5
votes
4 answers
Calculating geographic distances to data points with dplyr::mutate
I am trying to use R with the tidyverse packages and having trouble applying a function to my data. My data includes lat/long coordinates, and I want to calculate the distance from every location (row of my data frame) to a reference location. I am…

Simon Woodward
- 1,946
- 1
- 16
- 24
5
votes
3 answers
Geosphere/dplyr: create matrix of distance between coordinates
I want to create a "matrix" of the distance between multiple coordinates with each other. Preferably using dplyr/geosphere. I already saw that the geosphere package offers this. I managed to create the distance between two vectors but I have…

Joshua Zecha
- 141
- 1
- 8
4
votes
3 answers
Matrix of distances with Geosphere: avoid repeat calculus
I want to compute the distance among all points in a very large matrix using distm from geosphere.
See a minimal example:
library(geosphere)
library(data.table)
coords <- data.table(coordX=c(1,2,5,9), coordY=c(2,2,0,1))
distances <- distm(coords,…

LocoGris
- 4,432
- 3
- 15
- 30
4
votes
2 answers
R: Distm for big data? Calculating minimum distances between two matrices
I have two matrices, one is 200K rows long, the other is 20K. For each row (which is a point) in the first matrix, I am trying to find which row (also a point) in the second matrix is closest to the point in the first matrix. This is the first…

Ana
- 421
- 3
- 12
4
votes
2 answers
How to calculate all possible combinations of distance and time differences between grouped rows of data in R?
My data consists of distances and times traveled for dollar bills. My data looks like this:
bid ts latitude longitude
1 123 0 38.40513 41.83777
2 123 23 38.41180 41.68493
3 123 45 42.20771 43.36318
4 123 50 40.22803 43.00208
5 456 0…

nateswill
- 151
- 5
4
votes
2 answers
Mapping the shortest flight path across the date line in R leaflet/Shiny, using gcIntermediate
I'm creating a map of Australian airports and their international destinations using R-Leaflet.
Here is my sample data:
df<-data.frame("Australian_Airport" = "Brisbane",
"International" = c("Auckland", "Bandar Seri…

Susan
- 101
- 8