Learn R Programming

terra (version 1.8-54)

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

229,584

Version

1.8-54

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

June 1st, 2025

Functions in terra (1.8-54)

NAflag

Set the NA flag
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
adjacent

Adjacent cells or polygons
activeCat

Active category
add_mtext

draw a box
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
all.equal

Compare two SpatRasters for equality
ar_info

ar_info
SpatVector-class

Class "SpatVector"
Arith-methods

Arithmetic
SpatRaster-class

SpatRaster class
align

Align a SpatExtent
autocorrelation

Spatial autocorrelation
bestMatch

bestMatch
as.data.frame

SpatRaster or SpatVector to data.frame
aggregate

Aggregate raster or vector data
atan2

Two argument arc-tangent
app

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

Coerce to a "raster" object
boundaries

Detect boundaries (edges)
as.points

Conversion to a SpatVector of points
as.polygons

Conversion to a SpatVector of polygons
animate

Animate a SpatRaster
barplot

Bar plot of a SpatRaster
cellSize

Area covered by each raster cell
add_box

draw a box
c

Combine SpatRaster or SpatVector objects
as.lines

Conversion to a SpatVector of lines
buffer

Create a buffer around vector geometries or raster patches
cells

Get cell numbers
boxplot

Box plot of SpatRaster data
as.list

Coerce a Spat* object to a list
centroids

Centroids
clamp

Clamp values
cartogram

Cartogram
click

Query by clicking on a map
catalyze

Factors to numeric
combineGeoms

Combine geometries
Compare-methods

Compare and logical methods
compareGeom

Compare geometries
tighten

tighten SpatRaster or SpatRasterDataset objects
concats

Concatenate categorical rasters
colors

Color table
clamp_ts

clamp time series data
crs

Get or set a coordinate reference system
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
classify

Classify (or reclassify) cell values
crosstab

Cross-tabulate
coerce

Coercion to vector, matrix or array
crop

Cut out a geographic subset
costDist

Cost-distance
cover

Replace values with values from another object
contour

Contour plot
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
direction

Direction
datatype

Data type of a SpatRaster or SpatVector
describe

describe
diff

Lagged differences
hull

Convex, concave, rectangular and circular hulls
deepcopy

Deep copy
densify

Add additional nodes to lines or polygons
disagg

Disaggregate raster cells or vector geometries
density

Density plot
draw

Draw a polygon, line, extent, or points
deprecated

deprecated methods
erase

Erase parts of a SpatVector object
depth

depth of SpatRaster layers
extract

Extract values from a SpatRaster
elongate

elongate lines
extractAlong

extract values along lines
extractRange

Extract values for a range of layers from a SpatRaster
factors

Categorical rasters
distance

Geographic distance
ext

Create, get or set a SpatExtent
extend

Extend
focal

Focal values
focal3D

Three-dimensional focal values
expanse

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

force counter-clockwise polygons
focalCpp

Compute focal values with an iterating C++ function
focalMat

Focal weights matrix
focalPairs

Focal function across two layers
focalReg

Focal regression
halo

Add halo-ed text to a plot
freq

Frequency table
focalValues

Get focal values
gridDist

Distance on a grid
divide

Subdivide a raster or polygons
global

global statistics
flowAccumulation

Flow accumulation
fillHoles

Remove holes from polygons
hist

Histogram
headtail

head and tail of a SpatRaster or SpatVector
dots

Make a dot-density map
gdal

GDAL version, supported file formats, and cache size
geomtype

Geometry type of a SpatVector
flip

Flip or reverse a raster
gaps

Find gaps between polygons
fillTime

Fill time gaps in a SpatRaster
is.empty

Check if a SpatExtent or SpatVector is empty
identical

Compare two SpatRasters for equality
graticule

Create a graticule
add_grid

add a grid to a map made with terra
intersect

Intersection
is.lonlat

Check for longitude/latitude crs
geom

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

Is a SpatRaster is flipped
interpNear

Nearest neighbor interpolation
impose

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

Interpolate points using a moving window
image

SpatRaster image method
inset

Make an inset map
is.rotated

Check for rotation
interpolation

Spatial interpolation
linearUnits

Linear units of the coordinate reference system
add_legend

add a custom legend
makeVRT

Make a VRT header file
lines

Add points, lines, or polygons to a map
makeTiles

Make tiles or get their extents
is.bool

Raster value types
ifel

ifelse for SpatRasters
initialize

Initialize a SpatRaster with values
inplace

Change values in-place
meta

meta
mergeTime

merge SpatRasters by timelines to create a single timeseries
map_extent

Get the coordinates of the extent of a map
north

North arrow
mem

Memory available and needed
nearest

nearby geometries
is.valid

Check or fix polygon or extent validity
merge

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

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

Mask values in a SpatRaster or SpatVector
layerCor

Correlation and (weighted) covariance
metags

Set or get metadata
k_means

k_means
pairs

Pairs plot (matrix of scatterplots)
panel

Map panel
mosaic

mosaic SpatRasters
normalize.longitude

normalize vector data that crosses the dateline
not.na

is not NA
nseg

Number of segments
modal

modal value
map.pal

color palettes for mapping
origin

Origin
extremes

Get or compute the minimum and maximum cell values
patches

Detect patches (clumps) of cells
perim

Perimeter or length
na.omit

Find and remove geometries that are NA
Math-methods

General mathematical methods
match

Value matching for SpatRasters
plot

Make a map
plet

Plot with leaflet
prcomp

SpatRaster PCA with prcomp
plot_graticule

Plot a graticule
plotRGB

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

Plot a SpatExtent
princomp

SpatRaster PCA with princomp
predict

Spatial model predictions
rasterize

Rasterize vector data
project

Change the coordinate reference system
rasterizeWin

Rasterize points with a moving window
readwrite

Read from, or write to, file
quantile

Quantiles of spatial data
rasterizeGeom

Rasterize geometric properties of vector data
names

Names of Spat* objects
rcl

Combine row, column, and layer numbers
rectify

Rectify a SpatRaster
replace_layers

Replace layers or variables
rapp

Range-apply
persp

Perspective plot
rast

Create a SpatRaster
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
rowSums

row/col sums and means for SpatRaster
scale_linear

Scale values linearly
replace_values

Replace values of a SpatRaster
rotate

Rotate data along longitude
rangeFill

Fill layers with a range
same.crs

Compare coordinate reference systems
roll

Rolling (moving) functions
scoff

Scale (gain) and offset
sbar

scale bar
regress

Cell level regression
shift

Shift
scale

Scale values
sieve

Sieve filter
rep

Replicate layers
selectHighest

select cells with high or low values
selectRange

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

Query a SpatVectorProxy object
sds

Create a SpatRasterDataset
scatterplot

Scatterplot of two SpatRaster layers
sel

Spatial selection
simplifyGeom

simplifyGeom geometries
sources

Data sources of a SpatRaster
spin

spin a SpatVector
replace_dollar

Replace with $<-
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
segregate

segregate
shade

Hill shading
spatSample

Take a regular sample
resample

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

Set the values of raster cells or of geometry attributes
split

Split a SpatRaster or SpatVector
relate

Spatial relationships between geometries
sapp

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

Subset a SpatRaster or a SpatVector
sort

Sort a SpatRaster or SpatVector
serialize

saveRDS and serialize for SpatVector and SpatRaster*
subset_dollar

Subset a SpatRaster or a SpatVector
rescale

rescale
subst

replace cell values
sharedPaths

Shared paths
stretch

Stretch
terrain

terrain characteristics
subset

Subset a SpatRaster or a SpatVector
text

Add labels to a map
sprc

Create a SpatRasterCollection
symdif

Symmetrical difference
options

Options
toMemory

Read all cell values into memory
terra-package

Description of the methods in the terra package
tapp

Apply a function to subsets of layers of a SpatRaster
summary

summary
tmpFiles

Temporary files
svc

Create a SpatVectorCollection
thresh

Thresholding
unique

Unique values
summarize

Summarize
surfArea

Compute surface area from elevation data
transpose

Transpose
time

time of SpatRaster layers
trim

Trim a SpatRaster
voronoi

Voronoi diagram and Delaunay triangles
union

Union SpatVector or SpatExtent objects
topology

Vector topology methods
vrt

Virtual Raster Dataset
wrapCache

SpatRaster wrap with caching options
vrt_tiles

filenames of VRT tiles
update

Change values in a file
varnames

variable and long variable names
which.lyr

Which cells are TRUE?
vect

Create SpatVector objects
units

units of SpatRaster or SpatRasterDataSet
watershed

Catchment delineation
width

SpatVector geometric properties
writeRaster

Write raster data to a file
zoom

Zoom in on a map
zonal

Zonal statistics
xyRowColCell

Coordinates from a row, column or cell number and vice versa
weighted.mean

Weighted mean of layers
writeVector

Write SpatVector data to a file
vector_layers

List or remove layers from a vector file
viewshed

Compute a viewshed
writeCDF

Write raster data to a NetCDF file
window

Set a window
values

Cell values and geometry attributes
where

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

Apply a function to the cells of two SpatRasters
wrap

wrap and unwrap
xmin

Get or set single values of an extent
SpatExtent-class

Class "SpatExtent"
RGB

Layers representing colors