[R-sig-Geo] working with Z values in spatial data frames

Michael Sumner mdsumner at utas.edu.au
Mon Nov 5 10:14:25 CET 2007


Here's one simple way, using package akima:


library(sp)

data(meuse)

## assume your data is Spatial*

coordinates(meuse) <- ~x+y



## use "elev" column in akima
library(akima)

## define a grid
xx <- coordinates(meuse)[,1]
yy <- coordinates(meuse)[,2]
## modify offset of 100 to match your data, or use a proportion
grd <- expand.grid(x = seq(min(xx) - 200,  max(xx) + 200, length = 100),
          y = seq(min(yy) - 200, max(yy) + 200, length = 100))


res <- interpp(xx, yy, meuse$elev, grd$x, grd$y)
res <- as.data.frame(res) ## akima output is a list of 3 equal-length 
vectors like grd passed in


## if you want to interpolate on another "Z", repeat as desired, adding 
to output
res$cadmium <- interpp(xx, yy, meuse$cadmium, grd$x, grd$y)$z


coordinates(res) <- ~x+y
gridded(res) <- TRUE

## if you don't have a lot of empty cells
fullgrid(res) <- TRUE

image(res, "z")

## confirm where the high values were
points(meuse$x, meuse$y, cex = meuse$elev/5)

image(res, "cadmium")  ## etc

spplot(res)




Steve Friedman wrote:
> Hi,
>
> I have a spatial data set consisting of several z values and UTM
> coordinates.  Can someone direct me to documentation describing how I can
> plot specific z values using the coordinates to develop a continuous surface
> map?
>
> Thanks
> Steve
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>




More information about the R-sig-Geo mailing list