[R-sig-Geo] Interpolation

David Unwin ubfa915 at mail.bbk.ac.uk
Wed Apr 25 14:05:00 CEST 2018


a) Create a txt file looking something like:



X     Y     Z

0.3   6.1   870

1.4   6.2   793

2.4   6.1   755

etc

5.7   3     830



b) Thee column names are obvious. Then a possible workflow is:


topo_datatable <- read.table(choose.files(), header = TRUE)#read in

library(maptools)# two packages needed

library(gstat)

coordinates(topo_datatable) <- c("X", "Y")#create spatial object

#create grid for estimates

topo_grid <- spsample(topo_datatable, "regular", n=3720)

gridded(topo_grid) <- TRUE

fullgrid(topo_grid) <- TRUE

#this is simple inverse distance interpolation

#with a distance exponent of 2.0. There are lots of other options

exp<- 2.0

topo_idw <- idw(Z~1,topo_datatable,newdata=topo_grid,idp=exp)

#map the results, lots of options

im <- as.image.SpatialGridDataFrame(topo_idw)

topo_SLDF <- ContourLines2SLDF(contourLines(im))

topo_spl <- list("sp.lines", topo_SLDF)

spplot(topo_idw, "var1.pred", sp.layout=topo_spl)

image(topo_idw, "var1.pred", col=terrain.colors(20))

contour(topo_idw, "var1.pred", add=TRUE)

Dave Unwin

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list