[R] 2 dimensional interpolation from matlab to R
Charlie Sharpsteen
chuck at sharpsteen.net
Fri Feb 5 19:30:05 CET 2010
On Thu, Feb 4, 2010 at 4:03 AM, karine heerah <karine.heerah at hotmail.fr> wrote:
>
> Hi everybody.
>
>
>
> i have 2 datasets : one with a long grid a lat grid and a bathymetry grid
>
> the second one only has the long and lat coordinates.
>
> So i want to know the bathymetry associated to the second dataset. I thought it was a good idea to do an interpolation between the two datasets. I find a script doing that on matlab but i want to do it on R. Do you how to do it?
>
>
>
> for ii = 1:length(seal_dive_depth07)
>
> seal_bathy_depth07(ii) = interp2(long,latg,A,seal_lon07(ii),seal_lat07(ii));
> end
>
>
>
> Karine HEERAH
There are several interpolation routines available that will take you
between these two grids. The ones I used when preparing bathymetry
data for SWAN and ADCIRC models were:
>From the fields package:
regular grid to regular grid -> interp.surface.grid()
regular grid to irregular grid -> interp.surface()
>From the akima package:
irregular grid to regular grid -> interp()
As far as I recall, each of these routines uses either bilinear or
bicubic interpolation.
The routine as.image() may help you organize your data into the input
forms required by these functions. The "sp" package may also help you
handle the spatial nature of the data. "sp" contains a routine called
as.image.SpatialGridDataFrame() that performs the same function as
as.image() on spatially gridded data.
There are several other packages available that implement methods
other than bilinear/cubic interpolation such as kriging, but I don't
have any first hand experience with them.
Hope this helps!
-Charlie
More information about the R-help
mailing list