Calculate nearest neighbours for two point patterns

n2dist(pts1,pts2)

Arguments

pts1,pts2

Point data sets

Value

Returns a list with components $dists and $neighs. $dists[i] is the distance of the nearest neighbour of point pts2[i,]

in pts1 and $neighs[i]

is the index in pts1 of the point nearest to pts2[i,]. Documentation and example by Alun Pope, 2007-08-23.

See also

References

Rowlingson, B. and Diggle, P. 1993 Splancs: spatial point pattern analysis code in S-Plus. Computers and Geosciences, 19, 627-655; the original sources can be accessed at: https://www.maths.lancs.ac.uk/~rowlings/Splancs/. See also Bivand, R. and Gebhardt, A. 2000 Implementing functions for spatial statistical analysis using the R language. Journal of Geographical Systems, 2, 307-317.

Examples

(test1 <- matrix(c(151.1791, -33.86056, 151.1599, -33.88729, 151.1528,
-33.90685, 151.1811, -33.85937),nrow=4,byrow=TRUE))
#>          [,1]      [,2]
#> [1,] 151.1791 -33.86056
#> [2,] 151.1599 -33.88729
#> [3,] 151.1528 -33.90685
#> [4,] 151.1811 -33.85937
(test2 <- as.points(151.15, -33.9))
#>        [,1]  [,2]
#> [1,] 151.15 -33.9
n2dist(test1,test2)
#> $dists
#> [1] 0.007400169
#> 
#> $neighs
#> [1] 3
#> 
n2dist(test2,test1)
#> $dists
#> [1] 0.049013504 0.016110683 0.007400169 0.051166463
#> 
#> $neighs
#> [1] 1 1 1 1
#>