Learn R Programming

terra (version 1.8-80)

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

228,887

Version

1.8-80

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

November 5th, 2025

Functions in terra (1.8-80)

animate

Animate a SpatRaster
adjacent

Adjacent cells or polygons
approximate

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

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

Align a SpatExtent
ar_info

ar_info
Arith-methods

Arithmetic
all.equal

Compare two SpatRaster, SpatVector, or SpatExtent objects for equality
app

Apply a function to the cells of a SpatRaster
aggregate

Aggregate raster or vector data
atan2

Two argument arc-tangent
as.points

Conversion to a SpatVector of points
bestMatch

bestMatch
as.polygons

Conversion to a SpatVector of polygons
as.lines

Conversion to a SpatVector of lines
autocorrelation

Spatial autocorrelation
as.list

Coerce a Spat* object to a list
barplot

Bar plot of a SpatRaster
cells

Get cell numbers
boundaries

Detect boundaries (edges)
as.data.frame

SpatRaster or SpatVector to data.frame
as.raster

Coerce to a "raster" object
cellSize

Area covered by each raster cell
c

Combine SpatRaster or SpatVector objects
boxplot

Box plot of SpatRaster data
buffer

Create a buffer around vector geometries or raster patches
catalyze

Factors to numeric
cartogram

Cartogram
add_box

draw a box
centroids

Centroids
compareGeom

Compare geometries
click

Query by clicking on a map
clamp_ts

clamp time series data
classify

Classify (or reclassify) cell values
tighten

tighten SpatRaster or SpatRasterDataset objects
coerce

Coercion to vector, matrix or array
combineGeoms

Combine geometries
Compare-methods

Compare and logical methods
colors

Color table
costDist

Cost-distance
crs

Get or set a coordinate reference system
clamp

Clamp values
cover

Replace values with values from another object
crosstab

Cross-tabulate
contour

Contour plot
datatype

Data type of a SpatRaster or SpatVector
deprecated

deprecated methods
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
direction

Direction
densify

Add additional nodes to lines or polygons
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
crop

Cut out a geographic subset
deepcopy

Deep copy
disagg

Disaggregate raster cells or vector geometries
concats

Concatenate categorical rasters
describe

describe
depth

depth of SpatRaster layers
density

Density plot
hull

Convex, concave, rectangular and circular hulls
diff

Lagged differences
elongate

elongate lines
dots

Make a dot-density map
ext

Create, get or set a SpatExtent
draw

Draw a polygon, line, extent, or points
extend

Extend
distance

Geographic distance
expanse

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

Subdivide a raster or polygons
erase

Erase parts of a SpatVector object
extract

Extract values from a SpatRaster
flowAccumulation

Flow accumulation
focal

Focal values
flip

Flip or reverse a raster
fillHoles

Remove holes from polygons
fillTime

Fill time gaps in a SpatRaster
factors

Categorical rasters
extractRange

Extract values for a range of layers from a SpatRaster
focal3D

Three-dimensional focal values
focalCpp

Compute focal values with an iterating C++ function
extractAlong

extract values along lines
focalReg

Focal regression
focalMat

Focal weights matrix
geom

Get the geometry (coordinates) of a SpatVector
gdal

GDAL version, supported file formats, and cache size
halo

Add halo-ed text to a plot
gaps

Find gaps between polygons
geomtype

Geometry type of a SpatVector
freq

Frequency table
gridDist

Distance on a grid
focalPairs

Focal function across two layers
ifel

ifelse for SpatRasters
forceCCW

force counter-clockwise polygons
add_grid

add a grid to a map made with terra
focalValues

Get focal values
initialize

Initialize a SpatRaster with values
inplace

Change values in-place
identical

Compare two SpatRaster, SpatVector or SpatExtent objects for equality
global

global statistics
image

SpatRaster image method
impose

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

Intersection
headtail

head and tail of a SpatRaster or SpatVector
graticule

Create a graticule
is.empty

Check if a SpatExtent or SpatVector is empty
interpIDW

Interpolate points using a moving window
interpNear

Nearest neighbor interpolation
hist

Histogram
is.bool

Raster value types
inset

Make an inset map
interpolation

Spatial interpolation
layerCor

Correlation and (weighted) covariance
linearUnits

Linear units of the coordinate reference system
k_means

k_means
add_legend

add a custom legend
lapp

Apply a function to layers of a SpatRaster, or sub-datasets of a SpatRasterDataset
is.rotated

Check for rotation
lines

Add points, lines, or polygons to a map
is.lonlat

Check for longitude/latitude crs
is.valid

Check or fix polygon or extent validity
is.flipped

Is a SpatRaster is flipped
map_extent

Get the coordinates of the extent of a map
makeTiles

Make tiles or get their extents
mergeTime

merge SpatRasters by timelines to create a single timeseries
mask

Mask values in a SpatRaster or SpatVector
makeVRT

Make a VRT header file
merge

Merge SpatRasters, or merge a SpatVector with a data.frame
map.pal

color palettes for mapping
mem

Memory available and needed
match

Value matching for SpatRasters
Math-methods

General mathematical methods
na.omit

Find and remove geometries that are NA
north

North arrow
metags

Set or get metadata
mosaic

mosaic SpatRasters
meta

meta
extremes

Get or compute the minimum and maximum cell values
modal

modal value
normalize.longitude

normalize vector data that crosses the dateline
names

Names of Spat* objects
nearest

nearby geometries
not.na

is not NA
origin

Origin
pairs

Pairs plot (matrix of scatterplots)
nseg

Number of segments
persp

Perspective plot
patches

Detect patches (clumps) of cells
perim

Perimeter or length
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
panel

Map panel
plet

Plot with leaflet
plot_extent

Plot a SpatExtent
quantile

Quantiles of spatial data
project

Change the coordinate reference system
prcomp

SpatRaster PCA with prcomp
query

Query a SpatVectorProxy object
princomp

SpatRaster PCA with princomp
predict

Spatial model predictions
plot

Make a map
plotRGB

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

Plot a graticule
rectify

Rectify a SpatRaster
rangeFill

Fill layers with a range
rcl

Combine row, column, and layer numbers
rasterizeGeom

Rasterize geometric properties of vector data
rasterize

Rasterize vector data
rasterizeWin

Rasterize points with a moving window
readwrite

Read from, or write to, file
regress

Cell level regression
rast

Create a SpatRaster
rapp

Range-apply
rowSums

row/col sums and means for SpatRaster
roll

Rolling (moving) functions
replace_dollar

Replace with $<-
rescale

rescale
replace_values

Replace values of a SpatRaster
resample

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

Spatial relationships between geometries
replace_layers

Replace layers or variables
rotate

Rotate data along longitude
rep

Replicate layers
scale

Scale values
same.crs

Compare coordinate reference systems
scale_linear

Scale values linearly
segregate

segregate
spatSample

Take a regular sample
sapp

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

Create a SpatRasterDataset
scoff

Scale (gain) and offset
sbar

scale bar
scatterplot

Scatterplot of two SpatRaster layers
sel

Spatial selection
selectHighest

select cells with high or low values
sieve

Sieve filter
simplifyGeom

simplifyGeom geometries
sharedPaths

Shared paths
setValues

Set the values of raster cells or of geometry attributes
selectRange

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

Shift
shade

Hill shading
serialize

saveRDS and serialize for SpatVector and SpatRaster*
spin

spin a SpatVector
subset

Subset a SpatRaster or a SpatVector
sort

Sort a SpatRaster or SpatVector
stretch

Stretch
subset_double

Subset a SpatRaster or a SpatVector
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
subset_dollar

Subset a SpatRaster or a SpatVector
split

Split a SpatRaster or SpatVector
sources

Data sources of a SpatRaster
sprc

Create a SpatRasterCollection
svc

Create a SpatVectorCollection
subst

replace cell values
terrain

terrain characteristics
surfArea

Compute surface area from elevation data
terra-package

Description of the methods in the terra package
options

Options
tapp

Apply a function to subsets of layers of a SpatRaster
summary

summary
summarize

Summarize
unique

Unique values
transpose

Transpose
time

time of SpatRaster layers
text

Add labels to a map
topology

Vector topology methods
toMemory

Read all cell values into memory
symdif

Symmetrical difference
voronoi

Voronoi diagram and Delaunay triangles
trim

Trim a SpatRaster
tmpFiles

Temporary files
thresh

Thresholding
vector_layers

List or remove layers from a vector file
union

Union SpatVector or SpatExtent objects
varnames

variable and long variable names
vect

Create SpatVector objects
units

units of SpatRaster or SpatRasterDataSet
update

Change values in a file
viewshed

Compute a viewshed
weighted.mean

Weighted mean of layers
values

Cell values and geometry attributes
vrt

Virtual Raster Dataset
watershed

Catchment delineation
vrt_tiles

filenames of VRT tiles
which.lyr

Which cells are TRUE?
where

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

Set a window
width

SpatVector geometric properties
wrap

wrap and unwrap
wrapCache

SpatRaster wrap with caching options
writeRaster

Write raster data to a file
writeCDF

Write raster data to a NetCDF file
xyRowColCell

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

Zoom in on a map
zonal

Zonal statistics
xmin

Get or set single values of an extent
writeVector

Write SpatVector data to a file
xapp

Apply a function to the cells of two SpatRasters
activeCat

Active category
NIDP

Number of immediate adjacent cells flowing into each cell
NAflag

Set the NA flag
RGB

Layers representing colors
add_mtext

draw a box
SpatExtent-class

Class "SpatExtent"
SpatVector-class

Class "SpatVector"
add_abline

add vertical and/or horizontal lines to a map made with terra
SpatRaster-class

SpatRaster class
add

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