Questions tagged [geosphere]

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

170 questions
2
votes
1 answer

Calculating Distance Between Two Lat's and Longs Within A Data Frame

I have a data set that includes the latitude and longitude for each individual property address. As well, I have created two new columns (icelat, icelog) that include the latitude and longitude for one specific building in the state of Utah. The…
bcongelio
  • 81
  • 9
2
votes
3 answers

Calculate a centre point of multiple lat, long points in a data-frame

I have a dataset that looks like this: site lat long bras2 41.21 -115.11 tex4 45.3 -112.31 bras2 41.15 -115.15 bras2 41.12 -115.19 For samples with the same site name, I want to calculate their centre point and then add it as…
fifigoblin
  • 395
  • 1
  • 8
2
votes
1 answer

Add point at map centre in ggplot in r

I want to add point at every state centre. I know centroid() from geosphere package can do this. It can only compute one longitude and latitude, but I have 49 states and I do not want to compute it one by one. I also know coordinates() from sp…
zhiwei li
  • 1,635
  • 8
  • 26
2
votes
2 answers

Calculate distance between consecutive rows, by group

Morning, afternoon, evening I have the following boat data: set.seed(123) df <- data.frame( fac = as.factor(c("A", "A", "A", "A", "B", "B", "B", "C", "C", "C", "C", "C")), lat = runif(12, min = 45, max =…
Jim
  • 558
  • 4
  • 13
2
votes
2 answers

Find the Number of Points Within a Certain Radius of a Data Point in R

I have 2 datasets one for hospitals and another for procedures. Each dataset has latitude and longitude coordinates. Procedures are either given in or out of the hospital, though the coordinates are not necessarily precise if given in the…
aport550
  • 119
  • 1
  • 9
2
votes
0 answers

R (Geosphere Library) - "Error in if (antipodal(p1, p2)) { : missing value where TRUE/FALSE needed"

I have an issue that I have tried for seven hours to fix without any success. Basically, I am trying to visualize the airport and flight data from openflights.org. This was supposed to be a simple, straightforward visualization, but it has turned in…
Tal
  • 43
  • 2
2
votes
2 answers

Leaflet Polylines do not go over date line Leaflet

For a Shiny uni project I'm facing problems with polylines crossing the date line in the Pacific Ocean. From one center (Wuhan) I would like to create 72 lines showing their connection different regions. I have already created a loop to make sure…
2
votes
3 answers

Evaluating the closest distance from one point between multiple options?

I have a set of longitude/latitude points in a data frame called person_location +----+-----------+-----------+ | id | longitude | latitude | +----+-----------+-----------+ | 1 | -76.67707 | 39.399754 | | 2 | -76.44519 | 39.285084 | | 3 |…
user12061051
2
votes
2 answers

Points within a distance from a point

I have been trying to git this right, in fact it is working but the distance is wrong: 1- I have a collection of points 2- I have a point within which I need to find all points that are 200m far 3- Normally, It should return 6 points,…
roger
  • 89
  • 10
2
votes
1 answer

How to determine the cause of, Error in if: missing value where TRUE/FALSE needed, that only occurs when running as Shiny App

I'm working on a map project and have plotted two datasets of markers in a leaflet map (shiny app). One dataset is larger than the other, and I'm drawing great circle arcs connecting the many to few. Everything was working fine. I updated R from…
Nick
  • 179
  • 1
  • 11
2
votes
2 answers

Iterate in R with a function that requires four vectors

I'm trying to find the distance between multiple cities using the distHaversine function in the geosphere package. This code requires a variety of arguments: The longitude and latitude of the first place. The longitude and latitude of the second…
J.Sabree
  • 2,280
  • 19
  • 48
2
votes
3 answers

R Find the Distance between Two US Zipcode columns

I was wondering what the most efficient method of calculating the distance in miles between two US zipcode columns would be using R. I have heard of the geosphere package for computing the difference between zipcodes but do not fully understand it…
mrsquid
  • 605
  • 2
  • 9
  • 24
2
votes
1 answer

Mapping address to nearest metropolitan area

I have a dataset and I am trying to get a group locations to its nearest metropolitan. I have dataset 1 (df1) which contains the address locations with longitude and latitude. I want to map these address to all the nearest metropolitans (in a data…
user3570187
  • 1,743
  • 3
  • 17
  • 34
2
votes
2 answers

grouping locations based on 50 mile radius

Hi I have a dataset and I am trying to get a group cluster id based on the 50 mile radius. Here is the structure of the dataset g_lat<- c(45.52306, 40.26719, 34.05223, 37.38605, 37.77493) g_long<- c(-122.67648,-86.13490, -118.24368, -122.08385,…
user3570187
  • 1,743
  • 3
  • 17
  • 34
2
votes
1 answer

Calculating distance between two points using the distm function inside mutate

I am trying to calculate the distance between two sets of longitude and latitude coordinates. I am using the function distm() from the package geosphere to do this. It works fine if I manually put in the values in the distm() function, but I can't…
Steen Harsted
  • 1,802
  • 2
  • 21
  • 34
1 2
3
11 12