Learn R Programming

terra (version 1.8-70)

Spatial Data Analysis

Description

Methods for spatial data analysis with vector (points, lines, polygons) and raster (grid) data. Methods for vector data include geometric operations such as intersect and buffer. Raster methods include local, focal, global, zonal and geometric operations. The predict and interpolate methods facilitate the use of regression type (interpolation, machine learning) models for spatial prediction, including with satellite remote sensing data. Processing of very large files is supported. See the manual and tutorials on to get started. 'terra' replaces the 'raster' package ('terra' can do more, and it is faster and easier to use).

Copy Link

Version

Install

install.packages('terra')

Monthly Downloads

152,419

Version

1.8-70

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

September 27th, 2025

Functions in terra (1.8-70)

as.data.frame

SpatRaster or SpatVector to data.frame
all.equal

Compare two SpatRaster, SpatVector, or SpatExtent objects for equality
as.character

Create a text representation of (the skeleton of) an object
ar_info

ar_info
align

Align a SpatExtent
aggregate

Aggregate raster or vector data
Arith-methods

Arithmetic
app

Apply a function to the cells of a SpatRaster
animate

Animate a SpatRaster
barplot

Bar plot of a SpatRaster
bestMatch

bestMatch
autocorrelation

Spatial autocorrelation
as.lines

Conversion to a SpatVector of lines
as.points

Conversion to a SpatVector of points
as.polygons

Conversion to a SpatVector of polygons
boundaries

Detect boundaries (edges)
as.list

Coerce a Spat* object to a list
approximate

Estimate values for cell values that are NA by interpolating between layers
as.raster

Coerce to a "raster" object
atan2

Two argument arc-tangent
cellSize

Area covered by each raster cell
clamp

Clamp values
centroids

Centroids
boxplot

Box plot of SpatRaster data
add_box

draw a box
buffer

Create a buffer around vector geometries or raster patches
c

Combine SpatRaster or SpatVector objects
clamp_ts

clamp time series data
click

Query by clicking on a map
tighten

tighten SpatRaster or SpatRasterDataset objects
compareGeom

Compare geometries
concats

Concatenate categorical rasters
cells

Get cell numbers
classify

Classify (or reclassify) cell values
coerce

Coercion to vector, matrix or array
cartogram

Cartogram
combineGeoms

Combine geometries
crs

Get or set a coordinate reference system
crosstab

Cross-tabulate
catalyze

Factors to numeric
colors

Color table
datatype

Data type of a SpatRaster or SpatVector
costDist

Cost-distance
cover

Replace values with values from another object
hull

Convex, concave, rectangular and circular hulls
contour

Contour plot
crop

Cut out a geographic subset
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
direction

Direction
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
diff

Lagged differences
Compare-methods

Compare and logical methods
describe

describe
density

Density plot
distance

Geographic distance
disagg

Disaggregate raster cells or vector geometries
deepcopy

Deep copy
densify

Add additional nodes to lines or polygons
draw

Draw a polygon, line, extent, or points
erase

Erase parts of a SpatVector object
expanse

Get the expanse (area) of individual polygons or for all (summed) raster cells
depth

depth of SpatRaster layers
deprecated

deprecated methods
elongate

elongate lines
divide

Subdivide a raster or polygons
flowAccumulation

Flow accumulation
flip

Flip or reverse a raster
extractAlong

extract values along lines
extractRange

Extract values for a range of layers from a SpatRaster
extract

Extract values from a SpatRaster
dots

Make a dot-density map
focalPairs

Focal function across two layers
focal

Focal values
focal3D

Three-dimensional focal values
forceCCW

force counter-clockwise polygons
ext

Create, get or set a SpatExtent
focalCpp

Compute focal values with an iterating C++ function
extend

Extend
focalValues

Get focal values
focalMat

Focal weights matrix
global

global statistics
focalReg

Focal regression
image

SpatRaster image method
headtail

head and tail of a SpatRaster or SpatVector
geomtype

Geometry type of a SpatVector
factors

Categorical rasters
impose

Impose the geometry of a SpatRaster to those in a SpatRasterCollection.
gdal

GDAL version, supported file formats, and cache size
geom

Get the geometry (coordinates) of a SpatVector
is.empty

Check if a SpatExtent or SpatVector is empty
is.flipped

Is a SpatRaster is flipped
interpolation

Spatial interpolation
hist

Histogram
fillTime

Fill time gaps in a SpatRaster
graticule

Create a graticule
add_grid

add a grid to a map made with terra
identical

Compare two SpatRaster, SpatVector or SpatExtent objects for equality
interpNear

Nearest neighbor interpolation
ifel

ifelse for SpatRasters
fillHoles

Remove holes from polygons
is.lonlat

Check for longitude/latitude crs
interpIDW

Interpolate points using a moving window
layerCor

Correlation and (weighted) covariance
is.rotated

Check for rotation
lapp

Apply a function to layers of a SpatRaster, or sub-datasets of a SpatRasterDataset
inset

Make an inset map
mem

Memory available and needed
merge

Merge SpatRasters, or merge a SpatVector with a data.frame
halo

Add halo-ed text to a plot
north

North arrow
map.pal

color palettes for mapping
inplace

Change values in-place
gridDist

Distance on a grid
initialize

Initialize a SpatRaster with values
gaps

Find gaps between polygons
freq

Frequency table
makeVRT

Make a VRT header file
mosaic

mosaic SpatRasters
lines

Add points, lines, or polygons to a map
mask

Mask values in a SpatRaster or SpatVector
modal

modal value
metags

Set or get metadata
add_legend

add a custom legend
extremes

Get or compute the minimum and maximum cell values
not.na

is not NA
map_extent

Get the coordinates of the extent of a map
is.valid

Check or fix polygon or extent validity
names

Names of Spat* objects
match

Value matching for SpatRasters
Math-methods

General mathematical methods
is.bool

Raster value types
makeTiles

Make tiles or get their extents
intersect

Intersection
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
k_means

k_means
linearUnits

Linear units of the coordinate reference system
persp

Perspective plot
mergeTime

merge SpatRasters by timelines to create a single timeseries
meta

meta
origin

Origin
nseg

Number of segments
perim

Perimeter or length
patches

Detect patches (clumps) of cells
query

Query a SpatVectorProxy object
nearest

nearby geometries
normalize.longitude

normalize vector data that crosses the dateline
rangeFill

Fill layers with a range
plet

Plot with leaflet
rasterizeWin

Rasterize points with a moving window
prcomp

SpatRaster PCA with prcomp
regress

Cell level regression
relate

Spatial relationships between geometries
plot

Make a map
na.omit

Find and remove geometries that are NA
pairs

Pairs plot (matrix of scatterplots)
panel

Map panel
project

Change the coordinate reference system
rasterize

Rasterize vector data
rasterizeGeom

Rasterize geometric properties of vector data
predict

Spatial model predictions
plotRGB

Red-Green-Blue plot of a multi-layered SpatRaster
plot_extent

Plot a SpatExtent
quantile

Quantiles of spatial data
rcl

Combine row, column, and layer numbers
roll

Rolling (moving) functions
rotate

Rotate data along longitude
scoff

Scale (gain) and offset
replace_layers

Replace layers or variables
spatSample

Take a regular sample
resample

Transfer values of a SpatRaster to another one with a different geometry
princomp

SpatRaster PCA with princomp
scale

Scale values
replace_values

Replace values of a SpatRaster
plot_graticule

Plot a graticule
rast

Create a SpatRaster
sds

Create a SpatRasterDataset
shift

Shift
sbar

scale bar
rectify

Rectify a SpatRaster
sort

Sort a SpatRaster or SpatVector
sieve

Sieve filter
readwrite

Read from, or write to, file
rapp

Range-apply
simplifyGeom

simplifyGeom geometries
rowSums

row/col sums and means for SpatRaster
spin

spin a SpatVector
scale_linear

Scale values linearly
subset_double

Subset a SpatRaster or a SpatVector
same.crs

Compare coordinate reference systems
subset_dollar

Subset a SpatRaster or a SpatVector
sources

Data sources of a SpatRaster
sapp

Apply a terra function that takes only a single layer and returns a SpatRaster to all layers of a SpatRaster
split

Split a SpatRaster or SpatVector
rescale

rescale
segregate

segregate
sprc

Create a SpatRasterCollection
scatterplot

Scatterplot of two SpatRaster layers
serialize

saveRDS and serialize for SpatVector and SpatRaster*
sharedPaths

Shared paths
sel

Spatial selection
surfArea

Compute surface area from elevation data
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
rep

Replicate layers
shade

Hill shading
terra-package

Description of the methods in the terra package
symdif

Symmetrical difference
subset

Subset a SpatRaster or a SpatVector
stretch

Stretch
replace_dollar

Replace with $<-
summarize

Summarize
options

Options
terrain

terrain characteristics
unique

Unique values
summary

summary
selectRange

Select the values of a range of layers, as specified by cell values in another SpatRaster
setValues

Set the values of raster cells or of geometry attributes
transpose

Transpose
text

Add labels to a map
selectHighest

select cells with high or low values
watershed

Catchment delineation
vrt_tiles

filenames of VRT tiles
topology

Vector topology methods
units

units of SpatRaster or SpatRasterDataSet
varnames

variable and long variable names
voronoi

Voronoi diagram and Delaunay triangles
trim

Trim a SpatRaster
subst

replace cell values
vrt

Virtual Raster Dataset
which.lyr

Which cells are TRUE?
vect

Create SpatVector objects
tapp

Apply a function to subsets of layers of a SpatRaster
weighted.mean

Weighted mean of layers
thresh

Thresholding
writeRaster

Write raster data to a file
viewshed

Compute a viewshed
time

time of SpatRaster layers
window

Set a window
xapp

Apply a function to the cells of two SpatRasters
union

Union SpatVector or SpatExtent objects
svc

Create a SpatVectorCollection
wrap

wrap and unwrap
tmpFiles

Temporary files
where

Where are the cells with the min or max values?
zoom

Zoom in on a map
xmin

Get or set single values of an extent
vector_layers

List or remove layers from a vector file
toMemory

Read all cell values into memory
xyRowColCell

Coordinates from a row, column or cell number and vice versa
update

Change values in a file
writeVector

Write SpatVector data to a file
values

Cell values and geometry attributes
wrapCache

SpatRaster wrap with caching options
zonal

Zonal statistics
width

SpatVector geometric properties
writeCDF

Write raster data to a NetCDF file
activeCat

Active category
adjacent

Adjacent cells or polygons
NAflag

Set the NA flag
SpatVector-class

Class "SpatVector"
add_mtext

draw a box
SpatRaster-class

SpatRaster class
RGB

Layers representing colors
SpatExtent-class

Class "SpatExtent"
add

Add (in place) a SpatRaster to another SpatRaster or to a SpatRasterDataset or SpatRasterCollection
NIDP

Number of immediate adjacent cells flowing into each cell