On Jul 23, 2010, at 7:13 AM, Mafalda Viana wrote:
Dear R users, I need to find the coordinates for the point (midpoint) located half way between two pairs of coordinates (lon1,lat1 and lon2,lat2) assuming a straight line between them. What would be the best way? I tried to find an answer in the help archives but without success. I would greatly appreciate any help. df<- data.frame(lon1=c(-4.568,-4.3980), lat1=c(59.235,56.369), lon2=c(-5.123,-4.698), lat2=c(60.258,59.197) )
Wouldn't that just be the arithmetic average of the values? Or to you have some need for a more accurate calculation based on spherical geometry? Or some thing that will handle some other coordinate weirdness?
> df$midlong <- apply(df[,c(1,3)], 1, mean) > df$midlat <- apply(df[,c(2,4)], 1, mean) > df lon1 lat1 lon2 lat2 midlong midlat 1 -4.568 59.235 -5.123 60.258 -4.8455 59.7465 2 -4.398 56.369 -4.698 59.197 -4.5480 57.7830
-- David Winsemius, MD West Hartford, CT ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.