Learn R Programming

terra (version 1.9-11)

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

193,759

Version

1.9-11

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

March 26th, 2026

Functions in terra (1.9-11)

autocorrelation

Spatial autocorrelation
as.character

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

draw a box
as.polygons

Conversion to a SpatVector of polygons
as.points

Conversion to a SpatVector of points
boxplot

Box plot of SpatRaster data
as.data.frame

SpatRaster or SpatVector to data.frame
bestMatch

bestMatch
boundaries

Detect boundaries (edges)
centroids

Centroids
clamp_ts

clamp time series data
clamp

Clamp values
chunk

Make a SpatRaster method memory-safe
as.lines

Conversion to a SpatVector of lines
classify

Classify (or reclassify) cell values
as.list

Coerce a Spat* object to a list
cartogram

Cartogram
Arith-methods

Arithmetic
catalyze

Factors to numeric
buffer

Create a buffer around vector geometries or raster patches
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
click

Query by clicking on a map
costDist

Cost-distance
c

Combine SpatRaster or SpatVector objects
as.raster

Coerce to a "raster" object
hull

Convex, concave, rectangular and circular hulls
atan2

Two argument arc-tangent
cover

Replace values with values from another object
crs

Get or set a coordinate reference system
colors

Color table
coerce

Coercion to vector, matrix or array
cells

Get cell numbers
cellSize

Area covered by each raster cell
combineGeoms

Combine geometries
barplot

Bar plot of a SpatRaster
Compare-methods

Compare and logical methods
crop

Cut out a geographic subset
compareGeom

Compare geometries
densify

Add additional nodes to lines or polygons
crosstab

Cross-tabulate
expanse

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

Deep copy
tighten

tighten SpatRaster or SpatRasterDataset objects
ext

Create, get or set a SpatExtent
density

Density plot
draw

Draw a polygon, line, extent, or points
flowAccumulation

Flow accumulation
deprecated

deprecated methods
extend

Extend
fillHoles

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

Make a dot-density map
contour

Contour plot
datatype

Data type of a SpatRaster or SpatVector
factors

Categorical rasters
direction

Direction
divide

Subdivide a raster or polygons
describe

describe
depth

depth of SpatRaster layers
disagg

Disaggregate raster cells or vector geometries
distance

Geographic distance
concats

Concatenate categorical rasters
fillTime

Fill time gaps in a SpatRaster
focal

Focal values
extract

Extract values from a SpatRaster
extractAlong

extract values along lines
gdal

GDAL version, supported file formats, cache size, and PROJ coordinate transformation control
diff

Lagged differences
extractRange

Extract values for a range of layers from a SpatRaster
gaps

Find gaps between polygons
flip

Flip or reverse a raster
focalCpp

Compute focal values with an iterating C++ function
focal3D

Three-dimensional focal values
focalPairs

Focal function across two layers
focalMat

Focal weights matrix
geom

Get the geometry (coordinates) of a SpatVector
forceCCW

force counter-clockwise polygons
hist

Histogram
geomtype

Geometry type of a SpatVector
freq

Frequency table
focalReg

Focal regression
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
halo

Add halo-ed text to a plot
erase

Erase parts of a SpatVector object
elongate

elongate lines
focalValues

Get focal values
ifel

ifelse for SpatRasters
global

global statistics
identical

Compare two SpatRaster, SpatVector or SpatExtent objects for equality
graticule

Create a graticule
add_grid

add a grid to a map made with terra
image

SpatRaster image method
inset

Make an inset map
inplace

Change values in-place
interpNear

Nearest neighbor interpolation
interpIDW

Interpolate points using a moving window
k_means

k_means
impose

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

head and tail of a SpatRaster or SpatVector
layerCor

Correlation and (weighted) covariance
initialize

Initialize a SpatRaster with values
is.empty

Check if a SpatExtent or SpatVector is empty
lapp

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

Check for rotation
add_legend

add a custom legend
is.bool

Raster value types
gridDist

Distance on a grid
is.lonlat

Check for longitude/latitude crs
mem

Memory available and needed
is.flipped

Is a SpatRaster is flipped
linearUnits

Linear units of the coordinate reference system
interpolation

Spatial interpolation
intersect

Intersection
Math-methods

General mathematical methods
map.pal

color palettes for mapping
is.valid

Check or fix polygon or extent validity
lines

Add points, lines, or polygons to a map
extremes

Get or compute the minimum and maximum cell values
match

Value matching for SpatRasters
map_extent

Get the coordinates of the extent of a map
mask

Mask values in a SpatRaster or SpatVector
modal

modal value
nearest

nearby geometries
names

Names of Spat* objects
makeVRT

Make a VRT header file
makeTiles

Make tiles or get their extents
metags

Set or get metadata
patches

Detect patches (clumps) of cells
panel

Map panel
meta

meta
persp

Perspective plot
perim

Perimeter or length
pairs

Pairs plot (matrix of scatterplots)
origin

Origin
merge

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

merge SpatRasters by timelines to create a single timeseries
na.omit

Find and remove geometries that are NA
nseg

Number of segments
mosaic

mosaic SpatRasters
not.na

is not NA
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
plot_extent

Plot a SpatExtent
plet

Plot with leaflet
prcomp

SpatRaster PCA with prcomp
predict

Spatial model predictions
north

North arrow
project

Change the coordinate reference system
princomp

SpatRaster PCA with princomp
plotRGB

Red-Green-Blue plot of a multi-layered SpatRaster
normalize.longitude

normalize vector data that crosses the dateline
plot

Make a map
rcl

Combine row, column, and layer numbers
rangeFill

Fill layers with a range
quantile

Quantiles of spatial data
rescale

rescale
plot_graticule

Plot a graticule
rasterize

Rasterize vector data
readwrite

Read from, or write to, file
rapp

Range-apply
query

Query a SpatVectorProxy object
rast

Create a SpatRaster
rep

Replicate layers
relate

Spatial relationships between geometries
replace_values

Replace values of a SpatRaster
roll

Rolling (moving) functions
rasterizeGeom

Rasterize geometric properties of vector data
spatSample

Take a regular sample
scale_linear

Scale values linearly
scale

Scale values
same.crs

Compare coordinate reference systems
rowSums

row/col sums and means for SpatRaster
rasterizeWin

Rasterize points with a moving window
rectify

Rectify a SpatRaster
regress

Cell level regression
rotate

Rotate data along longitude
sharedPaths

Shared paths
shift

Shift
sort

Sort a SpatRaster or SpatVector
sel

Spatial selection
scatterplot

Scatterplot of two SpatRaster layers
subset

Subset a SpatRaster or a SpatVector
selectHighest

select cells with high or low values
shade

Hill shading
subset_dollar

Subset a SpatRaster or a SpatVector
resample

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

Replace with $<-
setValues

Set the values of raster cells or of geometry attributes
sources

Data sources of a SpatRaster
stretch

Stretch
sbar

scale bar
sapp

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

Scale (gain) and offset
replace_layers

Replace layers or variables
sds

Create a SpatRasterDataset
sprc

Create a SpatRasterCollection
segregate

segregate
spin

spin a SpatVector
selectRange

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

saveRDS and serialize for SpatVector and SpatRaster*
surfArea

Compute surface area from elevation data
sieve

Sieve filter
subset_double

Subset a SpatRaster or a SpatVector
summary

summary
split

Split a SpatRaster or SpatVector
subst

replace cell values
summarize

Summarize
tmpFiles

Temporary files
time

time of SpatRaster layers
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
terrain

terrain characteristics
symdif

Symmetrical difference
svc

Create a SpatVectorCollection
options

Options
thresh

Thresholding
trim

Trim a SpatRaster
transpose

Transpose
union

Union SpatVector or SpatExtent objects
text

Add labels to a map
varnames

variable and long variable names
unique

Unique values
values

Cell values and geometry attributes
simplifyGeom

simplifyGeom geometries
wrap

wrap and unwrap
wrapCache

SpatRaster wrap with caching options
vrt_tiles

filenames of VRT tiles
vector_layers

List or remove layers from a vector file
vrt

Virtual Raster Dataset
vect

Create SpatVector objects
tapp

Apply a function to subsets of layers of a SpatRaster
where

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

Change values in a file
viewshed

Compute a viewshed
voronoi

Voronoi diagram and Delaunay triangles
units

units of SpatRaster or SpatRasterDataSet
width

SpatVector geometric properties
toMemory

Read all cell values into memory
terra-package

Description of the methods in the terra package
topology

Vector topology methods
writeCDF

Write raster data to a NetCDF file
which.lyr

Which cells are TRUE?
zonal

Zonal statistics
window

Set a window
writeRaster

Write raster data to a file
watershed

Catchment delineation
writeVector

Write SpatVector data to a file
xapp

Apply a function to the cells of two SpatRasters
weighted.mean

Weighted mean of layers
xyRowColCell

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

Zoom in on a map
xmin

Get or set single values of an extent