[R-sig-Geo] IDW example

Ashton Shortridge ashton at msu.edu
Mon Oct 17 14:40:00 CEST 2011


On 10/16/11, Hodgess, Erin, wrote:
> Dear R Sig Geo People:
> 
> Here is probably a dumb question, so please forgive me in advance (or
> swear, whatever is most appropriate):  could someone recommend a good
> reference on IDW that has a numeric example, please?

Sure, check out Paul Bolstad's GIS Fundamentals textbook. My third edition has 
a very small worked example on pages 447-448.

It is straightforward to implement a small worked IDW example in a 
spreadsheet. You can mess around with the form of the weight, the distance to 
the point to be interpolated, and so on. Of course, it is not too hard to do 
this in R, either! gstat can do it, and you can roll your own code, e.g.:

# idw
# A function to perform IDW Interpolation to a matrix
# z is a vector of heights, distance is an mxn distance matrix
# indicating distances between the m grid points and n scattered
# sampled points, k is the power (typically 2), and num.neighs is 
# the closest x points to use in the interpolation.
idw <- function(z, distance, k, num.neighs) {
   idw.z <- rep(0, length(distance[,1]))
   for (i in 1:length(distance[,1])) {
      d <- sort(distance[i,], index.return=TRUE)  # sort to find closest points
      w <- 1 / d$x[1:num.neighs]^k         # The vector of the weights
      idw.z[i] <- sum(z[d$ix[1:num.neighs]]*w) / sum(w)  # The value for grid 
cell i
   }
   idw.mat <- matrix(idw.z, nrow=40, ncol=40)  # convert to matrix 
   return(idw.mat)
}


Hope this helps,

Ashton



On 10/16/11, Hodgess, Erin, wrote:
> Dear R Sig Geo People:
> 
> Here is probably a dumb question, so please forgive me in advance (or
> swear, whatever is most appropriate):  could someone recommend a good
> reference on IDW that has a numeric example, please?
> 
> I like to work things out on a small scale to see how they work.
> 
> thanks,
> Erin
> 
> 
> Erin M. Hodgess, PhD
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: hodgesse at uhd.edu
> 
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-----
Ashton Shortridge
Associate Professor			ashton at msu.edu
Dept of Geography			http://www.msu.edu/~ashton
235 Geography Building		ph (517) 432-3561
Michigan State University		fx (517) 432-1671



More information about the R-sig-Geo mailing list