An R package to calculate the distances and related measures for angular (longitude/latitude) locations
Questions tagged [geosphere]
170 questions
1
vote
1 answer
quick, correct distance calculations
I have a large dataframe (> 8 million rows), with observations of individuals and different sites. I'm interested in looking at the proximity of these sites to a few key location (1 location in 2014 and 2 locations in 2015).
To minimize the number…

tnt
- 1,149
- 14
- 24
1
vote
2 answers
get distm results in column rather than matrix
I'm trying to calculate the distance between two different sets of locations (145 in total), but the output is a matrix, rather than a column of the values.
my dataframe looks as follows:
head(df)
site1 Lon1 Lat1 site2 lon2…

tnt
- 1,149
- 14
- 24
1
vote
1 answer
Tidying messy coordinates for use in measurements
I have some rather messy degrees, decimal minutes coordinates (the source of which is out of my control) in the following format (see below). I am trying to work out the distance between the points ultimately.
minlat <- "51 12.93257'"
maxlat <-…

Jim
- 558
- 4
- 13
1
vote
2 answers
How to efficiently calculate distance between GPS points in one dataset and GPS points in another data set using data.table
I am facing a coding (optimization) problem in R. I have a long data set with GPS coordinates (lon, lat, timestamp) and for every row I need to check whether the location is near a bus stop. I have a .csv file with all the bus stops (in the…

L Smeets
- 888
- 4
- 17
1
vote
2 answers
Calculate large number of permutations in R
I have 2 large dataframes in R, both with circa 100k rows, which hold lists of geo coordinates (lat/ long). I am looking to iterate across them getting all combinations between items and thereafter, applying a function to it.
Because the number of…

Jo Costa
- 421
- 1
- 6
- 17
1
vote
1 answer
Estimate distance between one reference column and several columns in r using a for loop?
I have a data frame (df) with the following structure:
ID Long_Ref Lat_Ref Long_1 Lat_1 Long_2 Lat_2
A -71.69 -33.39 -70.29 -33.39 -71.69 -34.19
B -72.39 -34.34 -74.29 -31.19 -70.54 -33.38
C -70.14 …
1
vote
0 answers
Horizontal and vertical distance for geospatial points in R?
My question is based upon this question. I would like to have horizontal and vertical distance shown as x and y below, between 2 geospatial points p1 and p2.
Shall I find the M coordinate by :
M$lat = p1$lat
M$lon = p2$lon
and then compute x and y…

Haribo
- 2,071
- 17
- 37
1
vote
0 answers
creating multiple new mutate columns in dplyr iteratively - latitudes and longitudes
I have a list of latitudes and longitudes (each row contains a labeling number, 2 points, which form a line between them), and I am trying to find the distance from one of the endpoints in each row to the line created by every other row in the list.…

Alex C Fleming
- 11
- 2
1
vote
1 answer
R- Calculating the minimum distance between points and lines
I have a large set of polygon shapefiles of parcels (for 50+ counties) and I would like to loop through each of them and calculate the distance from the center of each parcel to the nearest railroad, stored nationally in a line shapefile.
I had…

winitheju
- 65
- 1
- 7
1
vote
1 answer
Plot connecting lines on a projected map (mapproj, gcIntermediate)
I am unsuccessfully trying to plot lines on a world map with Mollweide projection. I also plotted points on that same map, and it worked out fine. For the lines, I tried to adapt this example to my needs:…

noschmi
- 11
- 2
1
vote
2 answers
Pairwise distance calculation nested data frame
I am looking for a way to calculate the separation distance between points in a pairwise fashion and store the results for each individual point in an accompanying nested data frame.
For example, I have this data frame (from the maps package) that…

Jamesm131
- 145
- 1
- 10
1
vote
1 answer
How to compute big geographic distance matrix
I have a dataframe of ids and coordinates. I need to calculate the geographic distance between all my ids, drop the ones that are too far from each other, and then go on with my analysis.
I have 30k ids, which would generate a 30k x 30k matrix. Here…

Felipe Alvarenga
- 2,572
- 1
- 17
- 36
1
vote
1 answer
Calculating geographic distance of edge in iGraph
I have geographic coordinates for every vertex in an iGraph object. Now I want to calculate distance between existing edges.
library(igraph)
library(ggmap)
library(geosphere)
g <- graph.ring(6)
V(grph)$postcode <- c("Johannesburg 2017",
…

aterhorst
- 625
- 4
- 14
1
vote
1 answer
distVincentyEllipsoid() yielding NA values (geosphere package)
I am using the function distVincentyEllipsoid() from the geosphere package to calculate distances between the world's ports. This function takes as input the longitude and latitude of two places and gives the distance in meters as output. It appears…

Anthony S.
- 361
- 1
- 11
1
vote
2 answers
R - Error in if (antipodal(p1, p2)) when creating greatcircles - library(geosphere)
I'm having an issue when attempting to reproduce the greatcircle connection map over at http://flowingdata.com/2011/05/11/how-to-map-connections-with-great-circles/ . I am encountering the following error when running the loop for the…

Praxis
- 934
- 2
- 17
- 31