Skip to content
Prev 14891 / 29559 Next

near neighbor using decimal degree or projected coord system

On Mon, 23 Apr 2012, Gabriele Cozzi wrote:

            
If longlat=TRUE, RANN is ignored, as it cannot handle non-planar 
coordinates.
nbdists() also takes a longlat= argument - which you haven't used here. If 
you do, you'll get the distances you want. You can forget the argument if 
you make coord into a SpatialPoints object with a CRS:

library(spdep)
set.seed(1)
xy <- cbind(x=runif(50, 0, 10), y=runif(50, 0, 10))
k1 <- knn2nb(knearneigh(xy, k=1, longlat=TRUE, RANN=TRUE))
summary(unlist(nbdists(k1, xy)))
summary(unlist(nbdists(k1, xy, longlat=TRUE)))
SP <- SpatialPoints(xy, proj4string=CRS("+proj=longlat"))
k1 <- knn2nb(knearneigh(SP, k=1))
summary(unlist(nbdists(k1, SP)))

Hope this helps,

Roger