Learn R Programming

terra (version 0.4-3)

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. You can only extract rectangular areas, but see mask for setting cell values within SpatRaster to NA.

Usage

# S4 method for SpatRaster,ANY
crop(x, y, snap="near", filename="", overwrite=FALSE, wopt=list(), ...)
# S4 method for SpatVector,SpatVector
crop(x, y, ...)

Arguments

x

SpatRaster or SpatVector

y

SpatExtent or other object that has a SpatExtent; or SpatVector if x is a SpatVector

snap

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

filename

character. Output filename. Optional

overwrite

logical. If TRUE, filename is overwritten

wopt

list. Options for writing files as in writeRaster

...

additional arguments. None implemented

Value

SpatRaster

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab