0

I'm trying to calculate a lat lng point from a starting point and a distance travelled south and east. what geosphere function would I use to calculate that?

new_coordinate <- nc(latitude, longitude, km_south, km_east)
new_coordinate
[1]   49.49578 -101.48574

Ive tried manual calculations from internet, but nothing seems to work for me. Ive made sure to use radians.

coords <- function(cells_south, cells_east) {
  start_lat <- 52.285883
  start_lng <- -101.497821
  cells_south <- 3000
  cells_east <- 2500
  kmeast<-cells_east/10 #each cell 100 m
  kmsouth<-cells_south/10 
  #Latitude: 1 deg = 110.574 km
  #Longitude: 1 deg = 111.320*cos(latitude) km
  #lng_east <- (kmeast / (111.320 * cos(start_lat*(pi/180)))) + start_lng
  #lat_south <- start_lat - (kmsouth /110.574)
  #elevation <- dem$data[cells_south,cells_east] #elevation from ascii grid

  #Lets try calculating the distance from the north west origin
  theta <- 270 * pi /180
  cos_a = cos(theta)
  sin_a = sin(theta)
  cl <- cos(start_lat)
 # r = 100 meters.
  east_displacement = 100 * 0.5 / cl / 111111
  south_displacement = 100 * cos_a / 111111
  ret<-(c(start_lat-south_displacement,start_lng+east_displacement))

  lat1<-start_lat
  tc <- 0*pi / 270
  d<-kmsouth
  lon1 <- start_lng
  lat =asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
  dlon=atan2(sin(tc)*sin(d)*cos(lat1),cos(d)-sin(lat1)*sin(lat))
  lon=(lon1-dlon +pi %% 2*pi )-pi
}

52.28588 -101.49886

figured it should be around

57.760 -99.764

(guessed from google maps 300 km 250 km east.)

r2evans
  • 141,215
  • 6
  • 77
  • 149
Lawrence
  • 1
  • 1
  • (Is `nc` a function or a typo?) Have you tried `geosphere::destPoint`? You might need to calculate east first (heading 090) then south (heading 180). – r2evans Oct 06 '19 at 22:45
  • Its a hypothetical function to make sure I'm being clear what I'm expecting as a return value – Lawrence Oct 06 '19 at 23:30
  • `geosphere::destPoint()` gives you a destination point given a bearing and distance – SymbolixAU Oct 14 '19 at 22:19

0 Answers0