Questions tagged [geosphere]

An R package to calculate the distances and related measures for angular (longitude/latitude) locations

170 questions
3
votes
2 answers

Calculate Distance using Latitude and Longitude data in Different Data frames of different lengths with loop

I have 2 data frames of different lengths, each with a longitude and latitude coordinate. I would like to connect the two data frames by calculating the distance between the lat/long points. For simplicity, Data frame A (starting point) has the…
Jennifer
  • 285
  • 1
  • 3
  • 14
3
votes
1 answer

Distance calculation optimization in R

I would like to know if there is any way to optimize the distance calculation process below. I left a small example below, however I am working with a spreadsheet with more than 6000 rows, and it takes considerable time to calculate the variable d.…
Antonio
  • 1,091
  • 7
  • 24
3
votes
2 answers

Calculate the euclidean distance between points within grouped data

In the data below (included with dput), I have repeat observations (lat and long) for three individuals (IndIDII). Note, there are a different number of locations for each individual. > Dat IndIDII IndYear WintLat WintLong 1 BHS_265…
B. Davis
  • 3,391
  • 5
  • 42
  • 78
3
votes
1 answer

In geosphere package in R, why aren't bearings in 0-360 degrees?

When I calculated bearings between points using the bearing function in the geosphere package, the resulting bearings spanned -180 - 180 degrees. However, based on the geosphere package documentation, I expected the bearings to span 0-360 degrees. …
3
votes
1 answer

Difference (angle) between two bearings

Using geosphere::bearing I can calculate the bearing of two lines, but is it possible to calculate the angle between the two bearings ? Of course you can try and subtract or sum up the bearings but in specific cases where one is negative and the…
adl
  • 1,390
  • 16
  • 36
3
votes
1 answer

conditional which.min function

I have two sets of data, one is coordinates of machines, one is coordinates of the nearest repair shop. I have a working model that has assigned each machine to the nearest store. However one store only has 1 machine and another has 7 machines…
Coopa
  • 213
  • 1
  • 12
3
votes
2 answers

Set static centers for kmeans in R

I want to group a list of Long and Lats (my_long_lats) based on pre determined center points (my_center_Points). When I run:- k <- kmeans(as.matrix(my_long_lats), centers = as.matrix(my_center_Points)) k$centers does not equal my_center_Points.…
Coopa
  • 213
  • 1
  • 12
3
votes
1 answer

How can I calculate the distance between latitude and longitude along rows of columns in R?

My df looks like this: bid ts latitude longitude 1 827566 1999-10-07 42.40944 -88.17822 2 827566 2013-04-11 41.84740 -87.63126 3 1902966 2012-05-02 45.52607 -94.20649 4 1902966 2013-03-25 41.94083 -87.65852 5 3211972 2012-08-14…
nateswill
  • 151
  • 5
3
votes
1 answer

Counting distance takes too long

i have a data frame with more than 10 million rows. I want to count the distance between the lat-lon pairs, and add them to a nem column. I have tried to run the script(see below) , but it takes too long(more than 5 hours). Any tip how can i boost…
dkantor
  • 162
  • 6
3
votes
1 answer

Calculating polygon area with R geosphere package

I'm having trouble with the areaPolygon function in R. Sometimes it appears to produce the correct result, and sometimes the results seem orders of magnitude off. E.g. I have a polygon with these points: lng <- c(-51.74768, -51.74768, -51.74735,…
tiffany
  • 503
  • 2
  • 9
3
votes
1 answer

Distance between two places on earth in R

I am trying to calculate the distance between two points on earth using R. library(geosphere) library(oce) geodDist(StoreLocations$latitude[c(26)], StoreLocations$longitude[c(26)], CustomerLocations$latitude[c(5)],…
3
votes
1 answer

Understanding the output of `areaPolygon()` from package geosphere

From this Question I obtained the great function areaPolygon() which gives me the area within a polygon of coordinates. however, when I experiment with the function the calculations seem odd: I start by creating a set of two points require(fields) …
Seb
  • 5,417
  • 7
  • 31
  • 50
2
votes
2 answers

Calculate distance between multiple latitude and longitude points

I have a dataset that has latitude and longitude information for participants' home and work, and I'd like to create a new column in the dataset containing the euclidean distance between home and work for each participant. I think this should be…
Shannon
  • 93
  • 8
2
votes
2 answers

How to calculate bearing between two lat/lon in R

I want to calculate the bearing(direction) between 2 locations. This is what the sample looks like: # A tibble: 10 x 14 vehicle_id trip_id seg_1_lat seg_1_lon seg_2_lat seg_2_lon seg_3_lat seg_3_lon seg_4_lat seg_4_lon seg_5_lat…
Yasumin
  • 443
  • 2
  • 8
2
votes
2 answers

How to calculate trajectory length in R

I am trying to find the length between start and finish locations. So, which packages and function I should apply. This is what the sample looks like: # A tibble: 10 x 5 trip_id start_location end_location start_time end_time …
Yasumin
  • 443
  • 2
  • 8
1
2
3
11 12