[R-sig-Geo] performing IDW interpolations
Nerak
nerak.t at hotmail.com
Fri Sep 14 15:49:27 CEST 2012
Hi,
I'm happy to say that I think I was able to perform the IDW interpolation.
I was able (thanks to Minti) to import the file in asc format I made in qgis
to use as the grid (newdata). And it worked. Because I know that there are
more people struggeling with IDW, I post hereunder what I did, so maybe I
can help them. I'm not sure that this is a good way but it looks like it's
working fine for me.
I still have a question. I'm looking for a function (or the package) with
which I can extract values out of my IDW output file. I have a file with
several sampling points (several coordinates) for which I want to know the
precipitation which I interpolated between my rain gauges. I was thinking
about the function extract but this one isn't working because:
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function "extract", for signature
"SpatialPixelsDataFrame", "SpatialPointsDataFrame"
I think it only works for a raster, but I don't know how to transform my IDW
output to a raster... If somebody knows how I can extract the values for my
dataframe with coordinates, preferably all at the same time.
Is there a default number that most often is used as idp number? I'm still
looking which one could be most appropriated.
Kind regards,
Nerak
The script I used now:
###Inverse distance weighted interpolation
rm(list = ls(all = TRUE))
library(gstat)
library(rgdal)
library(raster)
library(spatstat)
data<-read.table("D:\\... filecoordinatesandprecipiation.txt",header=TRUE)
coordinates(data) <- c("x", "y")
r2 <- raster("D:\\... IDWrasterfileqgis.asc")
r2 <- as(r2, "SpatialPixelsDataFrame")
gridded(r2) <- TRUE
projection(data) <- "+proj=utm +zone=35 +datum=WGS84"
projection(r2) <- "+proj=utm +zone=35 +datum=WGS84"
idw.out <- idw(X27_5_2002 ~ 1, data, r2, idp = 2.5)
spplot(idw.out, "var1.pred")
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/performing-IDW-interpolations-tp7580956p7580962.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
More information about the R-sig-Geo
mailing list