Learn R Programming

terra (version 1.9-25)

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

222,230

Version

1.9-25

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

May 6th, 2026

Functions in terra (1.9-25)

RGB

Layers representing colors
ar_info

ar_info
agitate

Add noise to (jitter) a SpatVector of points
adjacent

Adjacent cells or polygons
approximate

Estimate values for cell values that are NA by interpolating between layers
all.equal

Compare two SpatRaster, SpatVector, or SpatExtent objects for equality
Arith-methods

Arithmetic
app

Apply a function to the cells of a SpatRaster
aggregate

Aggregate raster or vector data
animate

Animate a map
as.lines

Conversion to a SpatVector of lines
autocorrelation

Spatial autocorrelation
as.raster

Coerce to a "raster" object
atan2

Two argument arc-tangent
barplot

Bar plot of a SpatRaster
as.list

Coerce a Spat* object to a list
as.character

Create a text representation of (the skeleton of) an object
as.data.frame

SpatRaster or SpatVector to data.frame
align

Align a SpatExtent
as.polygons

Conversion to a SpatVector of polygons
as.points

Conversion to a SpatVector of points
c

Combine SpatRaster or SpatVector objects
buffer

Create a buffer around vector geometries or raster patches
add_box

draw a box
bestMatch

bestMatch
boxplot

Box plot of SpatRaster data
boundaries

Detect boundaries (edges)
catalyze

Factors to numeric
cellSize

Area covered by each raster cell
cartogram

Cartogram
cells

Get cell numbers
click

Query by clicking on a map
classify

Classify (or reclassify) cell values
colors

Color table
combineGeoms

Combine geometries
crop

Cut out a geographic subset
crosstab

Cross-tabulate
cover

Replace values with values from another object
concats

Concatenate categorical rasters
depth

depth of SpatRaster layers
chunk

Make a SpatRaster method memory-safe
centroids

Centroids
tighten

tighten SpatRaster or SpatRasterDataset objects
coerce

Coercion to vector, matrix or array
hull

Convex, concave, rectangular and circular hulls
costDist

Cost-distance
densify

Add additional nodes to lines or polygons
deepcopy

Deep copy
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
elongate

elongate lines
diff

Lagged differences
expanse

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

Create, get or set a SpatExtent
contour

Contour plot
dots

Make a dot-density map
direction

Direction
flowAccumulation

Flow accumulation
crs

Get or set a coordinate reference system
draw

Draw a polygon, line, extent, or points
focal

Focal values
datatype

Data type of a SpatRaster or SpatVector
describe

describe
disagg

Disaggregate raster cells or vector geometries
fillHoles

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

Geographic distance
factors

Categorical rasters
clamp

Clamp values
forceCCW

force counter-clockwise polygons
freq

Frequency table
global

global statistics
divide

Subdivide a raster or polygons
extend

Extend
erase

Erase parts of a SpatVector object
extract

Extract values from a SpatRaster
graticule

Create a graticule
focalCpp

Compute focal values with an iterating C++ function
focal3D

Three-dimensional focal values
focalMat

Focal weights matrix
focalPairs

Focal function across two layers
flip

Flip or reverse a raster
hist

Histogram
fillTime

Fill time gaps in a SpatRaster
interpNear

Nearest neighbor interpolation
interpIDW

Interpolate points using a moving window
add_grid

add a grid to a map made with terra
halo

Add halo-ed text to a plot
gaps

Find gaps between polygons
gdal

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

Distance on a grid
interpolation

Spatial interpolation
identical

Compare two SpatRaster, SpatVector or SpatExtent objects for equality
intersect

Intersection
layerCor

Correlation and (weighted) covariance
headtail

head and tail of a SpatRaster or SpatVector
add_legend

add a custom legend
is.flipped

Is a SpatRaster is flipped
is.lonlat

Check for longitude/latitude crs
ifel

ifelse for SpatRasters
k_means

k_means
initialize

Initialize a SpatRaster with values
clamp_ts

clamp time series data
Compare-methods

Compare and logical methods
impose

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

Density plot
focalReg

Focal regression
compareGeom

Compare geometries
deprecated

deprecated methods
lapp

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

extract values along lines
image

SpatRaster image method
is.bool

Raster value types
focalValues

Get focal values
extractRange

Extract values for a range of layers from a SpatRaster
is.empty

Check if a SpatExtent or SpatVector is empty
linearUnits

Linear units of the coordinate reference system
legend_cont

Add a continuous legend
geom

Get the geometry (coordinates) of a SpatVector
map.pal

color palettes for mapping
metags

Set or get metadata
mask

Mask values in a SpatRaster or SpatVector
extremes

Get or compute the minimum and maximum cell values
geomtype

Geometry type of a SpatVector
mergeTime

merge SpatRasters by timelines to create a single timeseries
meta

meta
plet

Plot with leaflet
plot

Make a map
inplace

Change values in-place
inset

Make an inset map
rasterizeGeom

Rasterize geometric properties of vector data
replace_dollar

Replace with $<-
patches

Detect patches (clumps) of cells
perim

Perimeter or length
rasterizeWin

Rasterize points with a moving window
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
persp

Perspective plot
is.valid

Check or fix polygon or extent validity
rcl

Combine row, column, and layer numbers
is.rotated

Check for rotation
makeVRT

Make a VRT header file
rotate

Rotate data along longitude
makeTiles

Make tiles or get their extents
lines

Add points, lines, or polygons to a map
readwrite

Read from, or write to, file
mem

Memory available and needed
rowSums

row/col sums and means for SpatRaster
sel

Spatial selection
replace_layers

Replace layers or variables
map_extent

Get the coordinates of the extent of a map
pairs

Pairs plot (matrix of scatterplots)
panel

Map panel
merge

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

Names of Spat* objects
na.omit

Find and remove geometries that are NA
match

Value matching for SpatRasters
Math-methods

General mathematical methods
same.crs

Compare coordinate reference systems
north

North arrow
origin

Origin
nearest

nearby geometries
mosaic

mosaic SpatRasters
modal

modal value
nseg

Number of segments
scoff

Scale (gain) and offset
spatSample

Take a regular sample
plot_graticule

Plot a graticule
not.na

is not NA
scatterplot

Scatterplot of two SpatRaster layers
plotRGB

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

Spatial model predictions
rectify

Rectify a SpatRaster
selectHighest

select cells with high or low values
regress

Cell level regression
shift

Shift
quantile

Quantiles of spatial data
query

Query a SpatVectorProxy object
normalize.longitude

normalize vector data that crosses the dateline
sharedPaths

Shared paths
prcomp

SpatRaster PCA with prcomp
surfArea

Compute surface area from elevation data
summary

summary
sbar

scale bar
segregate

segregate
spin

spin a SpatVector
plot_extent

Plot a SpatExtent
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
sds

Create a SpatRasterDataset
princomp

SpatRaster PCA with princomp
rangeFill

Fill layers with a range
proj_pipelines

Find CRS transformation pipelines
subset

Subset a SpatRaster or a SpatVector
subset_dollar

Subset a SpatRaster or a SpatVector
rasterize

Rasterize vector data
rast

Create a SpatRaster
sort

Sort a SpatRaster or SpatVector
rapp

Range-apply
sources

Data sources of a SpatRaster
subset_double

Subset a SpatRaster or a SpatVector
setValues

Set the values of raster cells or of geometry attributes
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
thin

Subset geometries by minimum distance
project

Change the coordinate reference system
shade

Hill shading
replace_values

Replace values of a SpatRaster
resample

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

Thresholding
scale_linear

Scale values linearly
scale

Scale values
tapp

Apply a function to subsets of layers of a SpatRaster
symdif

Symmetrical difference
terrain

terrain characteristics
options

Options
terra-package

Description of the methods in the terra package
relate

Spatial relationships between geometries
svc

Create a SpatVectorCollection
voronoi

Voronoi diagram and Delaunay triangles
update

Update a raster file
unique

Unique values
units

units of SpatRaster or SpatRasterDataSet
stretch

Stretch
vrt_tiles

filenames of VRT tiles
sprc

Create a SpatRasterCollection
values

Cell values and geometry attributes
rep

Replicate layers
tmpFiles

Temporary files
subst

replace cell values
warp_scale

Compute warp resampling scale
toMemory

Read all cell values into memory
where

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

Zoom in on a map
which.lyr

Which cells are TRUE?
zonal

Zonal statistics
vrt

Virtual Raster Dataset
varnames

variable and long variable names
summarize

Summarize
window

Set a window
width

SpatVector geometric properties
rescale

rescale
roll

Rolling (moving) functions
vect

Create SpatVector objects
tile_apply

Parallelize a SpatRaster function
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*
wrap

wrap and unwrap
wrapCache

SpatRaster wrap with caching options
sieve

Sieve filter
time

time of SpatRaster layers
watershed

Catchment delineation
trim

Trim a SpatRaster
union

Union SpatVector or SpatExtent objects
simplifyGeom

simplifyGeom geometries
text

Add labels to a map
topology

Vector topology methods
tessellate

Create a tesselation
weighted.mean

Weighted mean of layers
transpose

Transpose
xyRowColCell

Coordinates from a row, column or cell number and vice versa
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
writeVector

Write SpatVector data to a file
writeRaster

Write raster data to a file
vector_layers

List or remove layers from a vector file
viewshed

Compute a viewshed
activeCat

Active category
add

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

add a margin text
NIDP

Number of immediate adjacent cells flowing into each cell
add_abline

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

Set the NA flag
SpatRaster-class

SpatRaster class
SpatExtent-class

Class "SpatExtent"
SpatVector-class

Class "SpatVector"