2013-03-26 39 views

回答

1

展望真正优秀的raster包,它看起来像你的直觉是正确的源...

# From gridDistance() when lonlat is true 
if (lonlat) { 
    distance <- pointDistance(

# From pointDistance() 
if (! longlat) { 
    return(.planedist(p1[,1], p1[,2], p2[,1], p2[,2])) 
} else { 
    return(.haversine(p1[,1], p1[,2], p2[,1], p2[,2], r=6378137)) 
} 

# Finally from .haversine() 
.haversine <- function(x1, y1, x2, y2, r=6378137) { 
adj <- pi/180 
x1 <- x1 * adj 
y1 <- y1 * adj 
x2 <- x2 * adj 
y2 <- y2 * adj 
x <- sqrt((cos(y2) * sin(x1-x2))^2 + (cos(y1) * sin(y2) - sin(y1) * cos(y2) * cos(x1-x2))^2) 
y <- sin(y1) * sin(y2) + cos(y1) * cos(y2) * cos(x1-x2) 
return (r * atan2(x, y)) 
} 

因此,在短期,是的,你得到超级准确的测量距离。

+0

好!谢谢! – Oritteropus 2013-03-26 19:57:54