Learn R Programming

terra (version 1.9-46)

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

254,102

Version

1.9-46

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

August 22nd, 2026

Functions in terra (1.9-46)

atan2

Two argument arc-tangent
as.arrows

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

Conversion to a SpatVector of points
as.lines

Conversion to a SpatVector of lines
autocorrelation

Spatial autocorrelation
as.character

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

Conversion to a SpatVector of polygons
as.raster

Coerce to a "raster" object
as.data.frame

SpatRaster or SpatVector to data.frame
as.list

Coerce a Spat* object to a list
buffer

Create a buffer around vector geometries or raster patches
bestMatch

bestMatch
c

Combine SpatRaster or SpatVector objects
cartogram

Cartogram
cellSize

Area covered by each raster cell
add_box

draw a box
catalyze

Factors to numeric
barplot

Bar plot of a SpatRaster
coerce

Coercion to vector, matrix or array
boxplot

Box plot of SpatRaster data
tighten

tighten SpatRaster or SpatRasterDataset objects
classify

Classify (or reclassify) cell values
boundaries

Detect boundaries (edges)
cells

Get cell numbers
crop

Cut out a geographic subset
compareGeom

Compare geometries
clamp

Clamp values
concats

Concatenate categorical rasters
colors

Color table
cover

Replace values with values from another object
hull

Convex, concave, rectangular and circular hulls
Compare-methods

Compare and logical methods
centroids

Centroids
clamp_ts

clamp time series data
click

Query by clicking on a map
costDist

Cost-distance
chunk

Make a SpatRaster method memory-safe
combineGeoms

Combine geometries
deprecated

deprecated methods
contour

Contour plot
densify

Add additional nodes to lines or polygons
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
describe

describe
datatype

Data type of a SpatRaster or SpatVector
crosstab

Cross-tabulate
deepcopy

Deep copy
density

Density plot
crs

Get or set a coordinate reference system
depth

depth of SpatRaster layers
diff

Lagged differences
direction

Direction
divide

Subdivide a raster or polygons
elongate

elongate lines
disagg

Disaggregate raster cells or vector geometries
expanse

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

Make a dot-density map
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
distance

Geographic distance
draw

Draw a polygon, line, extent, or points
erase

Erase parts of a SpatVector object
flowAccumulation

Flow accumulation
fillHoles

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

Flip or reverse a raster
fillTime

Fill time gaps in a SpatRaster
factors

Categorical rasters
extractAlong

extract values along lines
extract

Extract values from a SpatRaster or polygon SpatVector
ext

Create, get or set a SpatExtent
extend

Extend
extractRange

Extract values for a range of layers from a SpatRaster
focalPairs

Focal function across two layers
forceCCW

force counter-clockwise polygons
flowdir

Path-Based Nondisperive Flow Direction
focalMat

Focal weights matrix
focal

Focal values
freq

Frequency table
focal3D

Three-dimensional focal values
focalReg

Focal regression
focalValues

Get focal values
focalCpp

Compute focal values with an iterating C++ function
geom

Get the geometry (coordinates) of a SpatVector
halo

Add halo-ed text to a plot
gdal

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

Distance on a grid
furdist

Distance to the furthest location on a geometry
graticule

Create a graticule
gaps

Find gaps between polygons
add_grid

add a grid to a map made with terra
geomtype

Geometry type of a SpatVector
global

global statistics
ifel

ifelse for SpatRasters
has.geoloc

Geolocation arrays and GCPs
impose

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

Histogram
has.z

Does a SpatVector have Z coordinates?
headtail

head and tail of a SpatRaster or SpatVector
identical

Compare two SpatRaster, SpatVector or SpatExtent objects for equality
inplace

Change values in-place
initialize

Initialize a SpatRaster with values
image

SpatRaster image method
is.lonlat

Check for longitude/latitude crs
interpNear

Nearest neighbor interpolation
inset

Make an inset map
intersect

Intersection
is.rotated

Check for rotation
is.bool

Raster value types
is.empty

Check if a SpatExtent or SpatVector is empty
is.flipped

Is a SpatRaster flipped?
interpIDW

Interpolate points using a moving window
interpolation

Spatial interpolation
linearUnits

Linear units of the coordinate reference system
lapp

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

Correlation and (weighted) covariance
makeTiles

Make tiles or get their extents
is.valid

Check or fix polygon or extent validity
make.RGB

Create a RGB SpatRaster
k_means

k_means
add_legend

add a custom legend
lines

Add points, lines, or polygons to a map
legend_cont

Add a continuous legend
mergeTime

merge SpatRasters by timelines to create a single timeseries
map.pal

color palettes for mapping
merge

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

Value matching for SpatRasters
mask

Mask values in a SpatRaster or SpatVector
makeVRT

Make a VRT header file
Math-methods

General mathematical methods
mem

Memory available and needed
meta

meta
map_extent

Get the coordinates of the extent of a map
nearest

nearby geometries
names

Names of Spat* objects
na.omit

Find and remove geometries that are NA
north

North arrow
netw

Build a SpatNetwork
extremes

Get or compute the minimum and maximum cell values
metags

Set or get metadata
modal

modal value
mosaic

mosaic SpatRasters
normalize.longitude

normalize vector data that crosses the dateline
origin

Origin
pitfiller

Pit Filler
pairs

Pairs plot (matrix of scatterplots)
nseg

Number of segments
perim

Perimeter or length
persp

Perspective plot
pitfinder

Find pits (depressions with no outlet)
not.na

is not NA
panel

Map panel
patches

Detect patches (clumps) of cells
predict

Spatial model predictions
prcomp

SpatRaster PCA with prcomp
princomp

SpatRaster PCA with princomp
plotRGB

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

Plot with leaflet
plot_graticule

Plot a graticule
plot

Make a map
project

Change the coordinate reference system
proj_pipelines

Find CRS transformation pipelines
plot_extent

Plot a SpatExtent
quantile

Quantiles of spatial data
rasterize

Rasterize vector data
rcl

Combine row, column, and layer numbers
query

Query a SpatVectorProxy object
readwrite

Read from, or write to, file
rapp

Range-apply
rangeFill

Fill layers with a range
rasterizeWin

Rasterize points with a moving window
rasterizeGeom

Rasterize geometric properties of vector data
rast

Create a SpatRaster
rectify

Rectify a SpatRaster
rep

Replicate layers
relate

Spatial relationships between geometries
regress

Cell level regression
rotate

Rotate data along longitude
rescale

rescale
roll

Rolling (moving) functions
sbar

scale bar
scoff

Scale (gain) and offset
replace_layers

Replace layers or variables
resample

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

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

row/col sums and means for SpatRaster
replace_dollar

Replace with $<-
scatterplot

Scatterplot of two SpatRaster layers
replace_values

Replace values of a SpatRaster
segregate

segregate
sel

Spatial selection
scale

Scale values
scale_linear

Scale values linearly
same.crs

Compare coordinate reference systems
selectRange

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

Hill shading
selectHighest

select cells with high or low values
serialize

saveRDS and serialize for SpatVector and SpatRaster*
setValues

Set the values of raster cells or of geometry attributes
shift

Shift
spatSample

Take a regular sample
sds

Create a SpatRasterDataset
sharedPaths

Shared paths
spin

spin a SpatVector
stretch

Stretch
snapTo

Snap points to the edge of lines or polygons
sort

Sort a SpatRaster or SpatVector
sieve

Sieve filter
split

Split a SpatRaster or SpatVector
simplifyGeom

simplifyGeom geometries
shortestPath

Shortest paths on a SpatNetwork
sources

Data sources of a SpatRaster
sprc

Create a SpatRasterCollection
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
subset_dollar

Subset a SpatRaster or a SpatVector
surfArea

Compute surface area from elevation data
subset_double

Subset a SpatRaster or a SpatVector
subst

replace cell values
svc

Create a SpatVectorCollection
summarize

Summarize
symdif

Symmetrical difference
summary

summary
subset

Subset a SpatRaster or a SpatVector
options

Options
thresh

Thresholding
terrain

terrain characteristics
time

time of SpatRaster layers
tapp

Apply a function to subsets of layers of a SpatRaster
tile_apply

Parallelize a SpatRaster function
text

Add labels to a map
thin

Subset geometries by minimum distance
tessellate

Create a tessellation
terra-package

Description of the methods in the terra package
unique

Unique values
trim

Trim a SpatRaster
units

units of SpatRaster or SpatRasterDataset
toMemory

Read all cell values into memory
union

Union SpatVector or SpatExtent objects
weighted.mean

Weighted mean of layers
warp_scale

Compute warp resampling scale
viewshed

Compute a viewshed
topology

Vector topology methods
transpose

Transpose
update

Update a raster file
tmpFiles

Temporary files
vector_layers

List or remove layers from a vector file
values

Cell values and geometry attributes
vrt_tiles

filenames of VRT tiles
watershed

Catchment delineation
voronoi

Voronoi diagram and Delaunay triangles
varnames

variable and long variable names
vrt

Virtual Raster Dataset
vect

Create SpatVector objects
writeRaster

Write raster data to a file
which.lyr

Which cells are TRUE?
wrapCache

SpatRaster wrap with caching options
writeNetwork

Write a SpatNetwork to disk
width

SpatVector geometric properties
where

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

Get or set single values of an extent
zoom

Zoom in on a map
writeVector

Write SpatVector data to a file
writeCDF

Write raster data to a NetCDF file
window

Set a window
wrap

wrap and unwrap
xapp

Apply a function to the cells of two SpatRasters
zonal

Zonal statistics
xyRowColCell

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

Layers representing colors
NIDP

Number of immediate adjacent cells flowing into each cell
add_mtext

add a margin text
SpatVector-class

Class "SpatVector"
NAflag

Set the NA flag
add_abline

add vertical and/or horizontal lines to a map made with terra
SpatExtent-class

Class "SpatExtent"
add

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

Active category
SpatRaster-class

SpatRaster class
align

Align a SpatExtent
all.equal

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

Aggregate raster or vector data
agitate

Add noise to (jitter) a SpatVector of points
animate

Animate a map
app

Apply a function to the cells of a SpatRaster
adjacent

Adjacent cells or polygons
approximate

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

Describe a multi-dimensional array file
Arith-methods

Arithmetic