library(raster)
r <- raster(nrows=500, ncols=500, xmn=571823, xmx=616763,
ymn=4423540, ymx=4453690)
proj4string(r) <- crs("+proj=utm +zone=12 +datum=NAD83 +units=m +no_defs")
r[] <- runif(ncell(r), 1000, 2500)
r <- focal(r, focalWeight(r, 150, "Gauss") )
# calculate tpi and plot
tpi9 <- tpi(r, scale=9)
par(mfrow=c(1,2))
plot(r, main="original raster")
plot(tpi9, main="tpi 9x9")
Run the code above in your browser using DataLab