[R] nearest neighbour interpolation

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Fri Jan 31 13:38:02 CET 2003

Roger Bivand wrote:
> Point-in-polygon functions are in the splancs 
> package, but there you need the polygons.

  There's also nearest-neighbour functions in Splancs - the nn2d 
function returns the distances and indices of the nearest points in one 
set (the grid) to another set (the data points). 'Interpolation' is then 
just a matter of taking the value of the factor indexed by the result. 
Its easier to do than describe.

  It is inefficient though, since it computes all Npts x Ngrid neighbour 
distances. Horrible if you want to do a large number of simulations, but 
if it takes twenty minutes and you only have to do it once, put the 
kettle on and have a cup of tea while the Computer Scientists tell you 
how to improve the algorithm. The function will be finished and your tea 
drunk by the time they've explained it.

> There are functions in package spatstat too, for instance 
> nearest.raster.point() does the reverse of what you want - which raster 
> cells are nearest to point coordinates - not which are closer.

  Hopefully Rasp will have better point/polygon/nearest-neighbour 

> Please contact me off-list if I can help further.

  I've emailed Matt the splancs-based solution.


More information about the R-help mailing list