Further to Rolf's comment: The next release of spatstat (1.32-0) will include new methods nncross.pp3 and nncross.ppx for this purpose.
(spatstat already contains the C code routines for nearest neighbours in arbitrary dimensions, so it is only necessary to write the R interface.) Adrian Prof Adrian Baddeley FAA University of Western Australia /and/ CSIRO Mathematics, Informatics & Statistics Mail: <cet.uwa.edu.au> Skype: adrian.baddeley ________________________________________ From: Rolf Turner [r.tur...@auckland.ac.nz] Sent: Friday, 28 June 2013 7:34 AM To: Carsten Neumann Cc: r-sig-geo@r-project.org; Adrian Baddeley Subject: Re: [R-sig-Geo] nearest neighbor 3d point pattern On 27/06/13 23:40, Carsten Neumann wrote: > Dear list members, > > after searching R mailing lists, I wonder if there is a R function that > can find the nearest neighbor/or just euclidean distance of points in > one 3D coordinate system to points in another 3D coordinate system. The > function nncross {spatstat} can only deal with 2D point pattern. Any > idea or experiences with such procedures? > > ######################Test Data############################ > point1<-array(c(seq(0,1,0.1),seq(0,1,0.1),seq(0,1,0.1)),dim=c(11,11,11)) > point2<-array(c(0.8,0.3,0.5),dim=c(1,1,1)) > ######################################################### > question: where is point2 in point1? You are correct in that nncross() has not (yet) been extended to three dimensional point patterns. However a workaround can be found by using crossdist.pp3(). E.g.: set.seed(42) X <- ppx(data.frame(x=rnorm(20),y=rnorm(20),z=rnorm(20))) Y <- ppx(data.frame(x=0,y=0,z=0)) M <- crossdist(Y,X) min(M) which.min(M) This will tell you that the nearest point in X to c(0,0,0) is point number 15 and the distance from c(0,0,0) to this point is 0.5299162. I'm afraid I could not comprehend your example. The object point1 is a 3-dimensional array (11 x 11 x 11). How is this to be interpreted as a 3-dimensional *point pattern*? And point2 is a single number --- 0.8, and not actually a point in 3-space. Furthermore what does the question "where is point2 in point1?" mean? I cannot parse this question. Perhaps (quite possibly) I am just being stupid. If so, please enlighten me. cheers, Rolf Turner _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo