Skip to content
Prev 4967 / 29559 Next

Clip a raster

Etienne,

I added a function "clickBbox" to the raster package for increased interactivity

#install.packages("raster", repos="http://R-Forge.R-project.org")
require(raster)

# read a raster file from disk
filename <- system.file("pictures/Rlogo.jpg", package="rgdal")
r <- rasterFromFile(filename, TRUE)
plot(r)

# If you want, for example, the mean of the values of the clipped area,
# use the below click on the image (map) twice to create a rectangle

mean( crop(r, clickBbox())[] )


Best, Robert
On Wed, Feb 4, 2009 at 7:38 PM, Roger Bivand <Roger.Bivand at nhh.no> wrote: