[R] nearest neighbour interpolation
Roger.Bivand at nhh.no
Fri Jan 31 11:48:03 CET 2003
On Thu, 30 Jan 2003, Matthew Oliver wrote:
> Dear Help List,
> My name is Matt Oliver. I have been using R for about a year and find it very
> helpful. However, I have a need for a function that I cannot find. I am not very
> good at programming so I thought I would ask the group.
Maybe this is an opportunity to explore things - they are usually feasible
if the motivation is sufficiently strong.
> I have an irregular grid of data (x = Longitude, y = Latitude). Each pair of my x,y
> has a categorical value. Obviously linear or any other numerically based
> interpolation on categorical data does not make sense, so I want to use a nearest
> neighbor interpolation so that I can extrapolate my irregular grid to a regular grid
> of Longitude and Latitude.
There does not seem to be such a function at present. The pieces are
there, though. In the tripack package, you will find the functions to make
a voronoi class, defining the boundaries of the tesselation of neighbours.
However, plot.voronoi() just draws the lines, I don't think it returns
polygons, but could. Point-in-polygon functions are in the splancs
package, but there you need the polygons. It would be sensible to use
polygon bounding boxes on your regular grid to reduce the number of calls
to point-in-polygon. For a dense grid, more sophistication would be
needed. You would also need to watch the open polygons where boundaries
run to infinity at the edges as far as point-in-polygon is concerned.
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.
Please contact me off-list if I can help further.
> Matt Oliver
> Institute of Marine and Coastal Sciences
> Rutgers University, New Brunswick, NJ
> 07728 oliver at imcs.rutgers.edu
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no
More information about the R-help