Skip to content
Prev 2873 / 29559 Next

Method for: Creating contour maps of geocoded point shapefile attributes

On Thu, 29 Nov 2007, Rick Reeves wrote:

            
Not in the spatial classes, and the issue of Great Circle distances is 
there too. You could look at inverse distance weighting (in a small 
neighbourhood in gstat I think using GC distances (?idw, ?gstat and its 
predict method), or at kriging on GC distances in fields (?Krig, 
Distance="rdist.earth" - Tps does not seem to support GC distances).

This is just a sketch:

library(gstat)
library(fields)
data(ozone2)
o <- cbind(ozone2$lon.lat, ozone2$y[16,])
colnames(o) <- c("lon", "lat", "day16")
o <- as.data.frame(o)
o <- o[complete.cases(o),]
coordinates(o) <- c(1, 2)
proj4string(o) <- CRS("+proj=longlat")
grd <- GridTopology(c(-94,36), c(0.25,0.25), c(48,40))
SG <- SpatialGrid(grd, proj4string=CRS("+proj=longlat"))
p <- idw(day16 ~ 1, o, newdata=SG, nmax=16)
image(p[1], axes=TRUE)
points(o, pch=3)
pim <- as.image.SpatialGridDataFrame(p[1])
cl <- contourLines(pim)
library(maptools)
cL <- ContourLines2SLDF(cl)
proj4string(cL) <- CRS("+proj=longlat")
lines(cL)

Roger