Learn R Programming

raster (version 1.9-44)

crop: Crop

Description

crop returns a geographic subset of an object as specified by an Extent object (or object from which an extent object can be extracted/created). If x is a Raster* object, the Extent is aligned to x. Areas included in y but outside the extent of x are ignored (see expand if you want a larger area)

Usage

## S3 method for class 'Raster':
crop(x, y, filename="", ...)

## S3 method for class 'Spatial':
crop(x, y, ...)

Arguments

x
Raster* object or SpatialPolygons* or SpatialLines* object
y
Extent object, or any object from which an Extent object can be extracted (see Details)
filename
Character, output filename. Optional
...
Additional arguments as for writeRaster

Value

  • RasterLayer or RasterBrick object; or SpatialLines or SpatialPolygons object.

Details

Objects from which an Extent can be extracted/created include RasterLayer, RasterStack, RasterBrick and objects of the Spatial* classes from the sp package. You can check this with the extent function. New Extent objects can be also be created with function extent and drawExtent by clicking twice on a plot.

See Also

expand, merge

Examples

Run this code
r <- raster(nrow=45, ncol=90)
r[] <- 1:ncell(r)
e <- extent(-160, 10, 30, 60)
rc <- crop(r, e)

Run the code above in your browser using DataLab