[R-sig-Geo] Spatial Interpolation of Regularly Gridded Data

Tomislav Hengl T.Hengl at uva.nl
Tue Apr 7 12:19:22 CEST 2009


Hi Greg,

Yes, there are many possibilities for downscaling grids in R, so you are at the right place.  :) 

1. If you only wish to downscale climatic grids (e.g. using splines), then probably the most
efficient (fastest; can handle large grids) way is to use the downscaling method in SAGA:

> library(RSAGA)
> library(RCurl)
> out.url <-
getURL("https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20090406/6b460881/attachment.obj",
ssl.verifypeer=F)
> write(out.url, "out.csv")
> out <- read.csv("out.csv", header=T, sep=",")
> str(out)
> coordinates(out) <- ~lon+lat
> proj4string(out) <- CRS("+proj=longlat +datum=WGS84")
> writeOGR(out, ".", "out", "ESRI Shapefile")
# convert to a grid:
> rsaga.geoprocessor(lib="grid_gridding", module=3, param=list(GRID="out5deg.sgrd", INPUT="out.shp",
FIELD=2, LINE_TYPE=0, USER_CELL_SIZE=0.5, USER_FIT_EXTENT=T))
# downscale the grid using Bicubic spline interpolation:
> rsaga.geoprocessor(lib="grid_tools", module=0, param=list(INPUT="out5deg.sgrd",
GRID="out25deg.sgrd", METHOD=0, DIMENSIONS_CELLSIZE=0.25, SCALE_DOWN_METHOD=3))


2. Otherwise, I would really suggest that you try downscaling grids using auxiliary information /
geostatistical modelling, which is explained in e.g. the following two papers:

Hengl, T., Bajat, B., Reuter, H.I., Blagojevic, D., 2008. Geostatistical modelling of topography
using auxiliary maps. Computers & Geosciences, 34: 1886-1899.
http://geomorphometry.org/view_scripts.asp?id=6 
 
Grohmann, C.H., Steiner, S.S., 2008. SRTM resample with Short Distance-Low Nugget Kriging.
International Journal of Geographical Information Science, 22 (8):895-906.
http://dx.doi.org/10.1080/13658810701730152 

HTH,

T. Hengl


> -----Original Message-----
> From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf
> Of Greg King
> Sent: Tuesday, April 07, 2009 12:01 AM
> To: r-sig-geo at stat.math.ethz.ch
> Subject: [R-sig-Geo] Spatial Interpolation of Regularly Gridded Data
> 
> Hi,
> 
> I'm fairly new to R, but finding the experience a good one.  However I am a little overwhelmed by
> the number of packages and not sure I am necessarily using the most appropriate ones.
> 
> Here is the background to what I am trying to achieve:  I have a CSV file which contains weather
> forecast data for latitude and longitude points (see attached out.csv, the data I understand is on
> WGS84 http://www.ready.noaa.gov/faq/geodatums.html).  The sample points are at half degree
> intervals.  My objective is to work out what the forecast data is at any specific given
> latitude/longitude by interpolating data from the 0.5x0.5 degree grid.  I am doing this for a
> number of different time points using the following functions:
> 
> 
> library(akima)
> library(rgdal)
> 
> gks <- function(inLat,inLon,dframe,variab) {
>     wind.grid <- expand.grid(lat=inLat, lon=inLon)
>     coordinates(wind.grid) <- ~ lat+lon
>     proj4string(wind.grid) <- CRS("+init=epsg:4326")
>     pnt<-interpp(coordinates(dframe)[,1], coordinates(dframe)[,2], z=as.data.frame(dframe)[,1],
> coordinates(wind.grid)[,1],coordinates(wind.grid)[,2],linear=TRUE)
>     return(pnt$z)
> }
> 
> interp_gk <- function(lat, lon) {
>     wind<-read.csv(file="/Users/greg/Out.csv",head=TRUE,sep=",",
> colClasses=c("POSIXct","numeric","numeric","numeric","numeric"))
>     coordinates(wind)=~lat+lon
>     proj4string(wind) <- CRS("+init=epsg:4326")
> 
>     times<-unique(wind$vt)
>     columns<-names(wind)[2:length(names(wind))]
> 
>     dOut<-data.frame(dateTime=times[1])
> 
>     for (i in 1:length(times)) {
>     dOut[i,"dateTime"]<-times[i]
>         for (j in 1:length(columns)) {
>             sset<-subset(wind, wind$vt==times[i], select=c(columns[j]))
>             dOut[i,columns[j]]<-gks(lat,lon,sset,columns[j])
>         }
>     }
>     dOut<-cbind(dOut, mag=sqrt(dOut$ugrd_0^2+dOut$vgrd_0^2))
>     return(dOut)
> }
> 
> 
> However, I have the following concerns:
> 
> 
> *	Should I really be using akima?  The documentation states it is not for use on regularly
> spaced grids - what are my alternatives?
> *	The interp funcrtion will not work for cubic spline "linear=FALSE" interpolation (is it
> because my data is regularly gridded?).  How can I achieve cubic spline interpolation?
> *	Is my function really using the Cordinate reference system specified?  When I comment out
> the CRS lines, my functions return the same values?
> 
> 
> Lots of questions I appreciate, but I am curious!  It seems R can achieve what I am trying to
> do... but I may just be missing some vital bits of information.
> 
> Thanks,
> 
> Greg
>



More information about the R-sig-Geo mailing list