Learn R Programming

terra (version 1.9-50)

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

231,708

Version

1.9-50

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

September 8th, 2026

Functions in terra (1.9-50)

NAflag

Set the NA flag
add

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

Layers representing colors
NIDP

Number of immediate adjacent cells flowing into each cell
add_mtext

add a margin text
activeCat

Active category
SpatRaster-class

SpatRaster class
add_abline

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

Aggregate raster or vector data
all.equal

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

Describe a multi-dimensional array file
adjacent

Adjacent cells or polygons
approximate

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

Align a SpatExtent
animate

Animate a map
Arith-methods

Arithmetic
app

Apply a function to the cells of a SpatRaster
agitate

Add noise to (jitter) a SpatVector of points
as.lines

Conversion to a SpatVector of lines
as.arrows

Add directional arrows from a SpatRaster to a plot
as.polygons

Conversion to a SpatVector of polygons
autocorrelation

Spatial autocorrelation
as.character

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

Two argument arc-tangent
as.list

Coerce a Spat* object to a list
as.data.frame

SpatRaster or SpatVector to data.frame
as.raster

Coerce to a "raster" object
as.points

Conversion to a SpatVector of points
cellSize

Area covered by each raster cell
add_box

draw a box
boundaries

Detect boundaries (edges)
bestMatch

bestMatch
c

Combine SpatRaster or SpatVector objects
buffer

Create a buffer around vector geometries or raster patches
boxplot

Box plot of SpatRaster data
cartogram

Cartogram
catalyze

Factors to numeric
clamp

Clamp values
barplot

Bar plot of a SpatRaster
click

Query by clicking on a map
clamp_ts

clamp time series data
coerce

Coercion to vector, matrix or array
tighten

tighten SpatRaster or SpatRasterDataset objects
chunk

Make a SpatRaster method memory-safe
cells

Get cell numbers
classify

Classify (or reclassify) cell values
colors

Color table
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
compareGeom

Compare geometries
hull

Convex, concave, rectangular and circular hulls
crop

Cut out a geographic subset
centroids

Centroids
costDist

Cost-distance
contour

Contour plot
concats

Concatenate categorical rasters
cover

Replace values with values from another object
combineGeoms

Combine geometries
Compare-methods

Compare and logical methods
density

Density plot
deprecated

deprecated methods
densify

Add additional nodes to lines or polygons
crs

Get or set a coordinate reference system
describe

describe
deepcopy

Deep copy
depth

depth of SpatRaster layers
diff

Lagged differences
datatype

Data type of a SpatRaster or SpatVector
crosstab

Cross-tabulate
distance

Geographic distance
divide

Subdivide a raster or polygons
direction

Direction
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
disagg

Disaggregate raster cells or vector geometries
dots

Make a dot-density map
expanse

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

Erase parts of a SpatVector object
elongate

elongate lines
draw

Draw a polygon, line, extent, or points
extractRange

Extract values for a range of layers from a SpatRaster
ext

Create, get or set a SpatExtent
flowAccumulation

Flow accumulation
extend

Extend
flip

Flip or reverse a raster
extractAlong

extract values along lines
factors

Categorical rasters
extract

Extract values from a SpatRaster or polygon SpatVector
fillTime

Fill time gaps in a SpatRaster
fillHoles

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

Path-Based Nondisperive Flow Direction
focalPairs

Focal function across two layers
forceCCW

force counter-clockwise polygons
focalCpp

Compute focal values with an iterating C++ function
focalReg

Focal regression
focal3D

Three-dimensional focal values
focalMat

Focal weights matrix
focal

Focal values
halo

Add halo-ed text to a plot
focalValues

Get focal values
freq

Frequency table
gridDist

Distance on a grid
gaps

Find gaps between polygons
graticule

Create a graticule
gdal

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

Get the geometry (coordinates) of a SpatVector
global

global statistics
furdist

Distance to the furthest location on a geometry
add_grid

add a grid to a map made with terra
geomtype

Geometry type of a SpatVector
identical

Compare two SpatRaster, SpatVector or SpatExtent objects for equality
has.geoloc

Geolocation arrays and GCPs
ifel

ifelse for SpatRasters
has.z

Does a SpatVector have Z coordinates?
hist

Histogram
headtail

head and tail of a SpatRaster or SpatVector
image

SpatRaster image method
impose

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

Initialize a SpatRaster with values
inplace

Change values in-place
interpIDW

Interpolate points using a moving window
interpNear

Nearest neighbor interpolation
is.empty

Check if a SpatExtent or SpatVector is empty
is.lonlat

Check for longitude/latitude crs
intersect

Intersection
interpolation

Spatial interpolation
is.flipped

Is a SpatRaster flipped?
is.bool

Raster value types
is.rotated

Check for rotation
inset

Make an inset map
lines

Add points, lines, or polygons to a map
layerCor

Correlation and (weighted) covariance
make.RGB

Create a RGB SpatRaster
linearUnits

Linear units of the coordinate reference system
k_means

k_means
is.valid

Check or fix polygon or extent validity
add_legend

add a custom legend
lapp

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

Make tiles or get their extents
legend_cont

Add a continuous legend
map.pal

color palettes for mapping
mem

Memory available and needed
makeVRT

Make a VRT header file
map_extent

Get the coordinates of the extent of a map
match

Value matching for SpatRasters
meta

meta
mergeTime

merge SpatRasters by timelines to create a single timeseries
merge

Merge SpatRasters, or merge a SpatVector with a data.frame
Math-methods

General mathematical methods
mask

Mask values in a SpatRaster or SpatVector
names

Names of Spat* objects
nearest

nearby geometries
metags

Set or get metadata
na.omit

Find and remove geometries that are NA
normalize.longitude

normalize vector data that crosses the dateline
mosaic

mosaic SpatRasters
extremes

Get or compute the minimum and maximum cell values
north

North arrow
modal

modal value
netw

Build a SpatNetwork
nseg

Number of segments
pitfiller

Pit Filler
origin

Origin
persp

Perspective plot
pairs

Pairs plot (matrix of scatterplots)
pitfinder

Find pits (depressions with no outlet)
panel

Map panel
patches

Detect patches (clumps) of cells
perim

Perimeter or length
not.na

is not NA
plot

Make a map
plotRGB

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

Find CRS transformation pipelines
project

Change the coordinate reference system
prcomp

SpatRaster PCA with prcomp
princomp

SpatRaster PCA with princomp
plet

Plot with leaflet
predict

Spatial model predictions
plot_graticule

Plot a graticule
plot_extent

Plot a SpatExtent
rast

Create a SpatRaster
rasterizeGeom

Rasterize geometric properties of vector data
rasterizeWin

Rasterize points with a moving window
rangeFill

Fill layers with a range
quantile

Quantiles of spatial data
rasterize

Rasterize vector data
rcl

Combine row, column, and layer numbers
query

Query a SpatVectorProxy object
rapp

Range-apply
readwrite

Read from, or write to, file
rep

Replicate layers
resample

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

Rectify a SpatRaster
rescale

rescale
replace_dollar

Replace with $<-
roll

Rolling (moving) functions
replace_values

Replace values of a SpatRaster
replace_layers

Replace layers or variables
relate

Spatial relationships between geometries
regress

Cell level regression
scale

Scale values
sbar

scale bar
same.crs

Compare coordinate reference systems
rotate

Rotate data along longitude
rowSums

row/col sums and means for SpatRaster
scatterplot

Scatterplot of two SpatRaster layers
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
scale_linear

Scale values linearly
spatSample

Take a regular sample
sds

Create a SpatRasterDataset
serialize

saveRDS and serialize for SpatVector and SpatRaster*
segregate

segregate
shift

Shift
sel

Spatial selection
selectHighest

select cells with high or low values
shade

Hill shading
selectRange

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

Shared paths
setValues

Set the values of raster cells or of geometry attributes
sprc

Create a SpatRasterCollection
sort

Sort a SpatRaster or SpatVector
simplifyGeom

simplifyGeom geometries
shortestPath

Shortest paths on a SpatNetwork
snapTo

Snap points to the edge of lines or polygons
stretch

Stretch
sieve

Sieve filter
spin

spin a SpatVector
sources

Data sources of a SpatRaster
split

Split a SpatRaster or SpatVector
subst

replace cell values
surfArea

Compute surface area from elevation data
summarize

Summarize
svc

Create a SpatVectorCollection
summary

summary
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
subset_double

Subset a SpatRaster or a SpatVector
subset_dollar

Subset a SpatRaster or a SpatVector
subset

Subset a SpatRaster or a SpatVector
symdif

Symmetrical difference
thresh

Thresholding
terrain

terrain characteristics
text

Add labels to a map
thin

Subset geometries by minimum distance
tessellate

Create a tessellation
tapp

Apply a function to subsets of layers of a SpatRaster
time

time of SpatRaster layers
tile_apply

Parallelize a SpatRaster function
terra-package

Description of the methods in the terra package
options

Options
tmpFiles

Temporary files
unique

Unique values
transpose

Transpose
trim

Trim a SpatRaster
units

units of SpatRaster or SpatRasterDataset
union

Geometric union SpatVector or SpatExtent objects
topology

Vector topology methods
toMemory

Read all cell values into memory
update

Update a raster file
values

Cell values and geometry attributes
vector_layers

List or remove layers from a vector file
weighted.mean

Weighted mean of layers
varnames

variable and long variable names
viewshed

Compute a viewshed
watershed

Catchment delineation
vrt_tiles

filenames of VRT tiles
vrt

Virtual Raster Dataset
voronoi

Voronoi diagram and Delaunay triangles
warp_scale

Compute warp resampling scale
vect

Create SpatVector objects
which.lyr

Which cells are TRUE?
wrap

wrap and unwrap
zoom

Zoom in on a map
width

SpatVector geometric properties
writeVector

Write SpatVector data to a file
xapp

Apply a function to the cells of two SpatRasters
writeCDF

Write raster data to a NetCDF file
writeRaster

Write raster data to a file
window

Set a window
wrapCache

SpatRaster wrap with caching options
writeNetwork

Write a SpatNetwork to disk
xmin

Get or set single values of an extent
zonal

Zonal statistics
xyRowColCell

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

Where are the cells with the min or max values?
SpatVector-class

Class "SpatVector"
SpatExtent-class

Class "SpatExtent"