Learn R Programming

terra (version 1.8-60)

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

185,852

Version

1.8-60

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

July 21st, 2025

Functions in terra (1.8-60)

as.list

Coerce a Spat* object to a list
all.equal

Compare two SpatRasters for equality
align

Align a SpatExtent
app

Apply a function to the cells of a SpatRaster
as.lines

Conversion to a SpatVector of lines
aggregate

Aggregate raster or vector data
cellSize

Area covered by each raster cell
as.raster

Coerce to a "raster" object
buffer

Create a buffer around vector geometries or raster patches
barplot

Bar plot of a SpatRaster
boxplot

Box plot of SpatRaster data
bestMatch

bestMatch
compareGeom

Compare geometries
as.data.frame

SpatRaster or SpatVector to data.frame
Arith-methods

Arithmetic
cells

Get cell numbers
as.character

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

Classify (or reclassify) cell values
add_box

draw a box
atan2

Two argument arc-tangent
concats

Concatenate categorical rasters
clamp_ts

clamp time series data
crs

Get or set a coordinate reference system
coerce

Coercion to vector, matrix or array
c

Combine SpatRaster or SpatVector objects
autocorrelation

Spatial autocorrelation
catalyze

Factors to numeric
cartogram

Cartogram
combineGeoms

Combine geometries
boundaries

Detect boundaries (edges)
Compare-methods

Compare and logical methods
focal

Focal values
disagg

Disaggregate raster cells or vector geometries
distance

Geographic distance
crosstab

Cross-tabulate
as.polygons

Conversion to a SpatVector of polygons
centroids

Centroids
costDist

Cost-distance
click

Query by clicking on a map
as.points

Conversion to a SpatVector of points
cover

Replace values with values from another object
deepcopy

Deep copy
crop

Cut out a geographic subset
approximate

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

Dimensions of a SpatRaster or SpatVector and related objects
direction

Direction
densify

Add additional nodes to lines or polygons
gaps

Find gaps between polygons
datatype

Data type of a SpatRaster or SpatVector
freq

Frequency table
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
describe

describe
focal3D

Three-dimensional focal values
clamp

Clamp values
headtail

head and tail of a SpatRaster or SpatVector
extract

Extract values from a SpatRaster
diff

Lagged differences
focalCpp

Compute focal values with an iterating C++ function
is.empty

Check if a SpatExtent or SpatVector is empty
extractAlong

extract values along lines
hist

Histogram
fillHoles

Remove holes from polygons
elongate

elongate lines
extend

Extend
density

Density plot
draw

Draw a polygon, line, extent, or points
ext

Create, get or set a SpatExtent
extractRange

Extract values for a range of layers from a SpatRaster
colors

Color table
focalValues

Get focal values
is.valid

Check or fix polygon or extent validity
factors

Categorical rasters
forceCCW

force counter-clockwise polygons
gdal

GDAL version, supported file formats, and cache size
tighten

tighten SpatRaster or SpatRasterDataset objects
deprecated

deprecated methods
fillTime

Fill time gaps in a SpatRaster
contour

Contour plot
focalPairs

Focal function across two layers
geom

Get the geometry (coordinates) of a SpatVector
depth

depth of SpatRaster layers
divide

Subdivide a raster or polygons
focalMat

Focal weights matrix
hull

Convex, concave, rectangular and circular hulls
graticule

Create a graticule
dots

Make a dot-density map
k_means

k_means
identical

Compare two SpatRasters for equality
gridDist

Distance on a grid
ifel

ifelse for SpatRasters
focalReg

Focal regression
erase

Erase parts of a SpatVector object
match

Value matching for SpatRasters
layerCor

Correlation and (weighted) covariance
Math-methods

General mathematical methods
names

Names of Spat* objects
is.flipped

Is a SpatRaster is flipped
expanse

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

add a grid to a map made with terra
inset

Make an inset map
lapp

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

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

Rasterize vector data
initialize

Initialize a SpatRaster with values
interpIDW

Interpolate points using a moving window
princomp

SpatRaster PCA with princomp
flip

Flip or reverse a raster
mem

Memory available and needed
predict

Spatial model predictions
halo

Add halo-ed text to a plot
persp

Perspective plot
plot_graticule

Plot a graticule
global

global statistics
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
flowAccumulation

Flow accumulation
na.omit

Find and remove geometries that are NA
geomtype

Geometry type of a SpatVector
image

SpatRaster image method
north

North arrow
rcl

Combine row, column, and layer numbers
prcomp

SpatRaster PCA with prcomp
rasterizeWin

Rasterize points with a moving window
add_legend

add a custom legend
intersect

Intersection
is.bool

Raster value types
impose

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

Replicate layers
replace_dollar

Replace with $<-
interpNear

Nearest neighbor interpolation
inplace

Change values in-place
is.lonlat

Check for longitude/latitude crs
interpolation

Spatial interpolation
lines

Add points, lines, or polygons to a map
linearUnits

Linear units of the coordinate reference system
roll

Rolling (moving) functions
rotate

Rotate data along longitude
map.pal

color palettes for mapping
rasterizeGeom

Rasterize geometric properties of vector data
makeVRT

Make a VRT header file
sds

Create a SpatRasterDataset
is.rotated

Check for rotation
map_extent

Get the coordinates of the extent of a map
sbar

scale bar
shade

Hill shading
nearest

nearby geometries
scoff

Scale (gain) and offset
not.na

is not NA
serialize

saveRDS and serialize for SpatVector and SpatRaster*
pairs

Pairs plot (matrix of scatterplots)
scale

Scale values
makeTiles

Make tiles or get their extents
normalize.longitude

normalize vector data that crosses the dateline
sharedPaths

Shared paths
time

time of SpatRaster layers
thresh

Thresholding
plet

Plot with leaflet
modal

modal value
mosaic

mosaic SpatRasters
mergeTime

merge SpatRasters by timelines to create a single timeseries
perim

Perimeter or length
meta

meta
setValues

Set the values of raster cells or of geometry attributes
mask

Mask values in a SpatRaster or SpatVector
vrt_tiles

filenames of VRT tiles
panel

Map panel
summarize

Summarize
project

Change the coordinate reference system
rangeFill

Fill layers with a range
patches

Detect patches (clumps) of cells
summary

summary
query

Query a SpatVectorProxy object
plot

Make a map
selectHighest

select cells with high or low values
regress

Cell level regression
metags

Set or get metadata
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
segregate

segregate
relate

Spatial relationships between geometries
selectRange

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

Temporary files
sel

Spatial selection
rectify

Rectify a SpatRaster
watershed

Catchment delineation
options

Options
nseg

Number of segments
toMemory

Read all cell values into memory
subst

replace cell values
terra-package

Description of the methods in the terra package
quantile

Quantiles of spatial data
sprc

Create a SpatRasterCollection
split

Split a SpatRaster or SpatVector
rapp

Range-apply
readwrite

Read from, or write to, file
origin

Origin
rast

Create a SpatRaster
tapp

Apply a function to subsets of layers of a SpatRaster
extremes

Get or compute the minimum and maximum cell values
topology

Vector topology methods
symdif

Symmetrical difference
replace_layers

Replace layers or variables
sieve

Sieve filter
scale_linear

Scale values linearly
same.crs

Compare coordinate reference systems
shift

Shift
transpose

Transpose
rowSums

row/col sums and means for SpatRaster
scatterplot

Scatterplot of two SpatRaster layers
replace_values

Replace values of a SpatRaster
subset_dollar

Subset a SpatRaster or a SpatVector
subset_double

Subset a SpatRaster or a SpatVector
plotRGB

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

Write SpatVector data to a file
vector_layers

List or remove layers from a vector file
trim

Trim a SpatRaster
xyRowColCell

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

Zonal statistics
surfArea

Compute surface area from elevation data
writeRaster

Write raster data to a file
svc

Create a SpatVectorCollection
vect

Create SpatVector objects
rescale

rescale
varnames

variable and long variable names
spatSample

Take a regular sample
resample

Transfer values of a SpatRaster to another one with a different geometry
weighted.mean

Weighted mean of layers
union

Union SpatVector or SpatExtent objects
plot_extent

Plot a SpatExtent
viewshed

Compute a viewshed
subset

Subset a SpatRaster or a SpatVector
stretch

Stretch
where

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

Zoom in on a map
unique

Unique values
sapp

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

terrain characteristics
text

Add labels to a map
window

Set a window
units

units of SpatRaster or SpatRasterDataSet
voronoi

Voronoi diagram and Delaunay triangles
spin

spin a SpatVector
sort

Sort a SpatRaster or SpatVector
wrap

wrap and unwrap
sources

Data sources of a SpatRaster
vrt

Virtual Raster Dataset
simplifyGeom

simplifyGeom geometries
width

SpatVector geometric properties
which.lyr

Which cells are TRUE?
update

Change values in a file
values

Cell values and geometry attributes
wrapCache

SpatRaster wrap with caching options
xmin

Get or set single values of an extent
writeCDF

Write raster data to a NetCDF file
xapp

Apply a function to the cells of two SpatRasters
add_mtext

draw a box
NAflag

Set the NA flag
add

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

Adjacent cells or polygons
SpatRaster-class

SpatRaster class
animate

Animate a SpatRaster
NIDP

Number of immediate adjacent cells flowing into each cell
activeCat

Active category
RGB

Layers representing colors
SpatExtent-class

Class "SpatExtent"
ar_info

ar_info
SpatVector-class

Class "SpatVector"