Learn R Programming

⚠️There's a newer version (1.8-54) of this package.Take me there.

terra (version 1.8-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. '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

207,345

Version

1.8-50

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

May 9th, 2025

Functions in terra (1.8-50)

app

Apply a function to the cells of a SpatRaster
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
tighten

tighten SpatRaster or SpatRasterDataset objects
as.points

Conversion to a SpatVector of points
coerce

Coercion to vector, matrix or array
clamp

Clamp values
clamp_ts

clamp time series data
expanse

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

Two argument arc-tangent
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
describe

describe
depth

depth of SpatRaster layers
focalMat

Focal weights matrix
focalPairs

Focal function across two layers
as.list

Coerce a Spat* object to a list
draw

Draw a polygon, line, extent, or points
diff

Lagged differences
cover

Replace values with values from another object
dots

Make a dot-density map
buffer

Create a buffer around vector geometries or raster patches
autocorrelation

Spatial autocorrelation
interpolation

Spatial interpolation
geom

Get the geometry (coordinates) of a SpatVector
meta

meta
intersect

Intersection
ext

Create, get or set a SpatExtent
approximate

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

Geometry type of a SpatVector
c

Combine SpatRaster or SpatVector objects
fillHoles

Remove holes from polygons
factors

Categorical rasters
as.raster

Coerce to a "raster" object
plot_graticule

Plot a graticule
interpIDW

Interpolate points using a moving window
as.polygons

Conversion to a SpatVector of polygons
impose

Impose the geometry of a SpatRaster to those in a SpatRasterCollection.
Compare-methods

Compare and logical methods
compareGeom

Compare geometries
metags

Set or get metadata
plot_extent

Plot a SpatExtent
initialize

Initialize a SpatRaster with values
interpNear

Nearest neighbor interpolation
classify

Classify (or reclassify) cell values
barplot

Bar plot of a SpatRaster
cartogram

Cartogram
deepcopy

Deep copy
persp

Perspective plot
bestMatch

bestMatch
nseg

Number of segments
click

Query by clicking on a map
cells

Get cell numbers
combineGeoms

Combine geometries
not.na

is not NA
perim

Perimeter or length
densify

Add additional nodes to lines or polygons
density

Density plot
crop

Cut out a geographic subset
direction

Direction
deprecated

deprecated methods
crosstab

Cross-tabulate
colors

Color table
elongate

elongate lines
hull

Convex, concave, rectangular and circular hulls
flowAccumulation

Flow accumulation
centroids

Centroids
rcl

Combine row, column, and layer numbers
readwrite

Read from, or write to, file
disagg

Disaggregate raster cells or vector geometries
erase

Erase parts of a SpatVector object
focal

Focal values
k_means

k_means
gdal

GDAL version, supported file formats, and cache size
focal3D

Three-dimensional focal values
global

global statistics
focalCpp

Compute focal values with an iterating C++ function
gaps

Find gaps between polygons
graticule

Create a graticule
costDist

Cost-distance
gridDist

Distance on a grid
lapp

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

Detect boundaries (edges)
add_grid

add a grid to a map made with terra
catalyze

Factors to numeric
extractAlong

extract values along lines
add_box

draw a box
is.empty

Check if a SpatExtent or SpatVector is empty
ifel

ifelse for SpatRasters
extractRange

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

Raster value types
cellSize

Area covered by each raster cell
concats

Concatenate categorical rasters
rescale

rescale
roll

Rolling (moving) functions
makeTiles

Make tiles or get their extents
image

SpatRaster image method
extend

Extend
crs

Get or set a coordinate reference system
divide

Subdivide a raster or polygons
contour

Contour plot
Math-methods

General mathematical methods
datatype

Data type of a SpatRaster or SpatVector
flip

Flip or reverse a raster
forceCCW

force counter-clockwise polygons
distance

Geographic distance
makeVRT

Make a VRT header file
lines

Add points, lines, or polygons to a map
panel

Map panel
fillTime

Fill time gaps in a SpatRaster
halo

Add halo-ed text to a plot
selectHighest

select cells with high or low values
linearUnits

Linear units of the coordinate reference system
extract

Extract values from a SpatRaster
freq

Frequency table
merge

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

Focal regression
identical

Compare two SpatRasters for equality
sel

Spatial selection
normalize.longitude

normalize vector data that crosses the dateline
focalValues

Get focal values
hist

Histogram
is.flipped

Check for rotation
headtail

head and tail of a SpatRaster or SpatVector
patches

Detect patches (clumps) of cells
prcomp

SpatRaster PCA with prcomp
north

North arrow
sort

Sort a SpatRaster or SpatVector
inplace

Change values in-place
spin

spin a SpatVector
plot

Make a map
sources

Data sources of a SpatRaster
is.lonlat

Check for longitude/latitude crs
mem

Memory available and needed
plotRGB

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

Spatial model predictions
inset

Make an inset map
units

units of SpatRaster or SpatRasterDataSet
rasterizeGeom

Rasterize geometric properties of vector data
terrain

terrain characteristics
extremes

Get or compute the minimum and maximum cell values
mergeTime

merge SpatRasters by timelines to create a single timeseries
layerCor

Correlation and (weighted) covariance
split

Split a SpatRaster or SpatVector
modal

modal value
map.pal

color palettes for mapping
update

Change values in a file
na.omit

Find and remove geometries that are NA
add_legend

add a custom legend
options

Options
vrt

Virtual Raster Dataset
mosaic

mosaic SpatRasters
rowSums

row/col sums and means for SpatRaster
rectify

Rectify a SpatRaster
rasterizeWin

Rasterize points with a moving window
map_extent

Get the coordinates of the extent of a map
where

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

filenames of VRT tiles
rotate

Rotate data along longitude
rangeFill

Fill layers with a range
is.valid

Check or fix polygon or extent validity
sprc

Create a SpatRasterCollection
is.rotated

Check for rotation
names

Names of Spat* objects
nearest

nearby geometries
which.lyr

Which cells are TRUE?
match

Value matching for SpatRasters
mask

Mask values in a SpatRaster or SpatVector
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
stretch

Stretch
pairs

Pairs plot (matrix of scatterplots)
origin

Origin
rep

Replicate layers
plet

Plot with leaflet
quantile

Quantiles of spatial data
tapp

Apply a function to subsets of layers of a SpatRaster
relate

Spatial relationships between geometries
resample

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

Replace values of a SpatRaster
regress

Cell level regression
query

Query a SpatVectorProxy object
terra-package

Description of the methods in the terra package
shade

Hill shading
unique

Unique values
same.crs

Compare coordinate reference systems
spatSample

Take a regular sample
scatterplot

Scatterplot of two SpatRaster layers
scoff

Scale (gain) and offset
rast

Create a SpatRaster
sapp

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

SpatRaster PCA with princomp
sbar

scale bar
union

Union SpatVector or SpatExtent objects
selectRange

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

Cell values and geometry attributes
setValues

Set the values of raster cells or of geometry attributes
rasterize

Rasterize vector data
surfArea

Compute surface area from elevation data
segregate

segregate
project

Change the coordinate reference system
topology

Vector topology methods
rapp

Range-apply
toMemory

Read all cell values into memory
summary

summary
serialize

saveRDS and serialize for SpatVector and SpatRaster*
replace_dollar

Replace with $<-
sharedPaths

Shared paths
varnames

variable and long variable names
writeRaster

Write raster data to a file
scale

Scale values
subset_dollar

Subset a SpatRaster or a SpatVector
subset

Subset a SpatRaster or a SpatVector
sds

Create a SpatRasterDataset
writeCDF

Write raster data to a NetCDF file
replace_layers

Replace layers or variables
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
sieve

Sieve filter
vect

Create SpatVector objects
vector_layers

List or remove layers from a vector file
text

Add labels to a map
simplifyGeom

simplifyGeom geometries
transpose

Transpose
subset_double

Subset a SpatRaster or a SpatVector
shift

Shift
scale_linear

Scale values linearly
trim

Trim a SpatRaster
thresh

Thresholding
subst

replace cell values
writeVector

Write SpatVector data to a file
time

time of SpatRaster layers
svc

Create a SpatVectorCollection
width

SpatVector geometric properties
summarize

Summarize
voronoi

Voronoi diagram and Delaunay triangles
tmpFiles

Temporary files
xapp

Apply a function to the cells of two SpatRasters
wrap

wrap and unwrap
symdif

Symmetrical difference
window

Set a window
viewshed

Compute a viewshed
xmin

Get or set single values of an extent
wrapCache

SpatRaster wrap with caching options
xyRowColCell

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

Catchment delineation
zoom

Zoom in on a map
weighted.mean

Weighted mean of layers
zonal

Zonal statistics
activeCat

Active category
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
as.lines

Conversion to a SpatVector of lines
NAflag

Set the NA flag
all.equal

Compare two SpatRasters for equality
SpatRaster-class

SpatRaster class
as.data.frame

SpatRaster or SpatVector to data.frame
SpatVector-class

Class "SpatVector"
as.character

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

Align a SpatExtent
adjacent

Adjacent cells or polygons
add_mtext

draw a box
animate

Animate a SpatRaster
aggregate

Aggregate raster or vector data
Arith-methods

Arithmetic
RGB

Layers representing colors
SpatExtent-class

Class "SpatExtent"
boxplot

Box plot of SpatRaster data