Learn R Programming

terra (version 1.8-86)

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.

Copy Link

Version

Install

install.packages('terra')

Monthly Downloads

228,887

Version

1.8-86

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

November 28th, 2025

Functions in terra (1.8-86)

RGB

Layers representing colors
add

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

SpatRaster class
add_abline

add vertical and/or horizontal lines to a map made with terra
animate

Animate a SpatRaster
ar_info

ar_info
NIDP

Number of immediate adjacent cells flowing into each cell
Arith-methods

Arithmetic
app

Apply a function to the cells of a SpatRaster
SpatVector-class

Class "SpatVector"
SpatExtent-class

Class "SpatExtent"
add_mtext

draw a box
as.data.frame

SpatRaster or SpatVector to data.frame
as.polygons

Conversion to a SpatVector of polygons
bestMatch

bestMatch
all.equal

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

Align a SpatExtent
as.list

Coerce a Spat* object to a list
aggregate

Aggregate raster or vector data
activeCat

Active category
autocorrelation

Spatial autocorrelation
as.lines

Conversion to a SpatVector of lines
as.points

Conversion to a SpatVector of points
add_box

draw a box
as.raster

Coerce to a "raster" object
barplot

Bar plot of a SpatRaster
atan2

Two argument arc-tangent
boundaries

Detect boundaries (edges)
coerce

Coercion to vector, matrix or array
tighten

tighten SpatRaster or SpatRasterDataset objects
centroids

Centroids
boxplot

Box plot of SpatRaster data
c

Combine SpatRaster or SpatVector objects
adjacent

Adjacent cells or polygons
buffer

Create a buffer around vector geometries or raster patches
as.character

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

Factors to numeric
cellSize

Area covered by each raster cell
cartogram

Cartogram
crop

Cut out a geographic subset
clamp

Clamp values
chunk

Make a SpatRaster method memory-safe
classify

Classify (or reclassify) cell values
clamp_ts

clamp time series data
Compare-methods

Compare and logical methods
deprecated

deprecated methods
cells

Get cell numbers
direction

Direction
density

Density plot
compareGeom

Compare geometries
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
approximate

Estimate values for cell values that are NA by interpolating between layers
contour

Contour plot
click

Query by clicking on a map
concats

Concatenate categorical rasters
colors

Color table
draw

Draw a polygon, line, extent, or points
describe

describe
combineGeoms

Combine geometries
depth

depth of SpatRaster layers
deepcopy

Deep copy
crosstab

Cross-tabulate
cover

Replace values with values from another object
densify

Add additional nodes to lines or polygons
extractRange

Extract values for a range of layers from a SpatRaster
focal

Focal values
ext

Create, get or set a SpatExtent
crs

Get or set a coordinate reference system
diff

Lagged differences
dots

Make a dot-density map
datatype

Data type of a SpatRaster or SpatVector
hull

Convex, concave, rectangular and circular hulls
divide

Subdivide a raster or polygons
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
extend

Extend
distance

Geographic distance
costDist

Cost-distance
elongate

elongate lines
expanse

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

Disaggregate raster cells or vector geometries
gridDist

Distance on a grid
extractAlong

extract values along lines
fillHoles

Remove or extract holes from polygons, or fill holes in raster data
fillTime

Fill time gaps in a SpatRaster
erase

Erase parts of a SpatVector object
extract

Extract values from a SpatRaster
gaps

Find gaps between polygons
focalMat

Focal weights matrix
focalPairs

Focal function across two layers
focalCpp

Compute focal values with an iterating C++ function
flowAccumulation

Flow accumulation
flip

Flip or reverse a raster
focalReg

Focal regression
freq

Frequency table
hist

Histogram
geom

Get the geometry (coordinates) of a SpatVector
identical

Compare two SpatRaster, SpatVector or SpatExtent objects for equality
focalValues

Get focal values
halo

Add halo-ed text to a plot
interpIDW

Interpolate points using a moving window
ifel

ifelse for SpatRasters
forceCCW

force counter-clockwise polygons
graticule

Create a graticule
factors

Categorical rasters
headtail

head and tail of a SpatRaster or SpatVector
initialize

Initialize a SpatRaster with values
intersect

Intersection
is.bool

Raster value types
interpolation

Spatial interpolation
is.rotated

Check for rotation
geomtype

Geometry type of a SpatVector
image

SpatRaster image method
layerCor

Correlation and (weighted) covariance
gdal

GDAL version, supported file formats, and cache size
is.valid

Check or fix polygon or extent validity
is.lonlat

Check for longitude/latitude crs
global

global statistics
focal3D

Three-dimensional focal values
impose

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

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

modal value
inset

Make an inset map
inplace

Change values in-place
mem

Memory available and needed
match

Value matching for SpatRasters
makeVRT

Make a VRT header file
makeTiles

Make tiles or get their extents
k_means

k_means
linearUnits

Linear units of the coordinate reference system
interpNear

Nearest neighbor interpolation
map_extent

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

Is a SpatRaster is flipped
mergeTime

merge SpatRasters by timelines to create a single timeseries
add_grid

add a grid to a map made with terra
origin

Origin
metags

Set or get metadata
is.empty

Check if a SpatExtent or SpatVector is empty
add_legend

add a custom legend
Math-methods

General mathematical methods
mask

Mask values in a SpatRaster or SpatVector
panel

Map panel
map.pal

color palettes for mapping
persp

Perspective plot
names

Names of Spat* objects
nearest

nearby geometries
nseg

Number of segments
meta

meta
na.omit

Find and remove geometries that are NA
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
not.na

is not NA
normalize.longitude

normalize vector data that crosses the dateline
plotRGB

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

Add points, lines, or polygons to a map
prcomp

SpatRaster PCA with prcomp
perim

Perimeter or length
patches

Detect patches (clumps) of cells
plot_extent

Plot a SpatExtent
merge

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

Plot with leaflet
mosaic

mosaic SpatRasters
pairs

Pairs plot (matrix of scatterplots)
project

Change the coordinate reference system
princomp

SpatRaster PCA with princomp
north

North arrow
rasterize

Rasterize vector data
predict

Spatial model predictions
extremes

Get or compute the minimum and maximum cell values
quantile

Quantiles of spatial data
rasterizeGeom

Rasterize geometric properties of vector data
readwrite

Read from, or write to, file
rcl

Combine row, column, and layer numbers
rangeFill

Fill layers with a range
rectify

Rectify a SpatRaster
plot_graticule

Plot a graticule
plot

Make a map
regress

Cell level regression
rapp

Range-apply
rep

Replicate layers
rasterizeWin

Rasterize points with a moving window
rotate

Rotate data along longitude
replace_dollar

Replace with $<-
roll

Rolling (moving) functions
resample

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

Query a SpatVectorProxy object
replace_values

Replace values of a SpatRaster
replace_layers

Replace layers or variables
relate

Spatial relationships between geometries
rast

Create a SpatRaster
same.crs

Compare coordinate reference systems
scale_linear

Scale values linearly
rescale

rescale
rowSums

row/col sums and means for SpatRaster
scale

Scale values
scatterplot

Scatterplot of two SpatRaster layers
shift

Shift
sieve

Sieve filter
selectHighest

select cells with high or low values
segregate

segregate
sbar

scale bar
spatSample

Take a regular sample
serialize

saveRDS and serialize for SpatVector and SpatRaster*
sharedPaths

Shared paths
sds

Create a SpatRasterDataset
spin

spin a SpatVector
subset_double

Subset a SpatRaster or a SpatVector
shade

Hill shading
sort

Sort a SpatRaster or SpatVector
sel

Spatial selection
selectRange

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

Scale (gain) and offset
split

Split a SpatRaster or SpatVector
sapp

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

Stretch
simplifyGeom

simplifyGeom geometries
subset_dollar

Subset a SpatRaster or a SpatVector
sources

Data sources of a SpatRaster
setValues

Set the values of raster cells or of geometry attributes
subset

Subset a SpatRaster or a SpatVector
sprc

Create a SpatRasterCollection
svc

Create a SpatVectorCollection
symdif

Symmetrical difference
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
terra-package

Description of the methods in the terra package
tapp

Apply a function to subsets of layers of a SpatRaster
options

Options
subst

replace cell values
surfArea

Compute surface area from elevation data
summarize

Summarize
summary

summary
text

Add labels to a map
tmpFiles

Temporary files
transpose

Transpose
thresh

Thresholding
toMemory

Read all cell values into memory
union

Union SpatVector or SpatExtent objects
terrain

terrain characteristics
trim

Trim a SpatRaster
time

time of SpatRaster layers
topology

Vector topology methods
varnames

variable and long variable names
voronoi

Voronoi diagram and Delaunay triangles
units

units of SpatRaster or SpatRasterDataSet
vrt

Virtual Raster Dataset
vector_layers

List or remove layers from a vector file
values

Cell values and geometry attributes
weighted.mean

Weighted mean of layers
vect

Create SpatVector objects
unique

Unique values
window

Set a window
vrt_tiles

filenames of VRT tiles
wrap

wrap and unwrap
width

SpatVector geometric properties
writeCDF

Write raster data to a NetCDF file
update

Change values in a file
watershed

Catchment delineation
where

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

Compute a viewshed
which.lyr

Which cells are TRUE?
wrapCache

SpatRaster wrap with caching options
xmin

Get or set single values of an extent
xyRowColCell

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

Zoom in on a map
zonal

Zonal statistics
xapp

Apply a function to the cells of two SpatRasters
writeVector

Write SpatVector data to a file
writeRaster

Write raster data to a file