Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

crop

Cut out a geographic subset


Description

Cut out a part of a SpatRaster with a SpatExtent, or another object from which an extent can be obtained. With a SpatRaster you can only extract rectangular areas, but see mask for setting cell values within SpatRaster to NA.

You can crop a SpatVector with a rectangle, or with another vector (if these are not polygons, the minimum convex hull is used). Unlike with intersect the geometries and attributes of y are not trasferred to the output.

Usage

## S4 method for signature 'SpatRaster'
crop(x, y, snap="near", filename="", ...)

## S4 method for signature 'SpatVector,ANY'
crop(x, y)

## S4 method for signature 'SpatVector,SpatVector'
crop(x, y)

Arguments

x

SpatRaster or SpatVector

y

SpatExtent or other object that has a SpatExtent (ext returns a SpatExtent), or a SpatVector to crop another SpatVector

snap

character. One of "near", "in", or "out"

filename

character. Output filename

...

additional arguments for writing files as in writeRaster

Value

SpatRaster

See Also

intersect

Examples

r <- rast(xmin=0, xmax=10, ymin=0, ymax=10, nrows=25, ncols=25)
values(r) <- 1:ncell(r)
e <- ext(-5, 5, -5, 5)
rc <- crop(r, e)

# vector
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
e <- ext(6.15, 6.3, 49.7, 49.8)
x <- crop(v, e)
#plot(x, "NAME_1")

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.