Learn R Programming

terra (version 1.8-29)

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

172,117

Version

1.8-29

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

February 26th, 2025

Functions in terra (1.8-29)

NAflag

Set the NA flag
NIDP

Number of immediate adjacent cells flowing into each cell
adjacent

Adjacent cells or polygons
SpatVector-class

Class "SpatVector"
add

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

Active category
add_mtext

draw a box
SpatExtent-class

Class "SpatExtent"
RGB

Layers representing colors
SpatRaster-class

SpatRaster class
app

Apply a function to the cells of a SpatRaster
as.lines

Conversion to a SpatVector of lines
align

Align a SpatExtent
as.data.frame

SpatRaster or SpatVector to data.frame
approximate

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

Compare two SpatRasters for equality
as.character

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

Animate a SpatRaster
Arith-methods

Arithmetic
as.points

Conversion to a SpatVector of points
aggregate

Aggregate raster or vector data
atan2

Two argument arc-tangent
add_box

draw a box
as.list

Coerce a Spat* object to a list
boundaries

Detect boundaries (edges)
bestMatch

bestMatch
barplot

Bar plot of a SpatRaster
clamp

Clamp values
boxplot

Box plot of SpatRaster data
as.polygons

Conversion to a SpatVector of polygons
catalyze

Factors to numeric
contour

Contour plot
cellSize

Area covered by each raster cell
concats

Concatenate categorical rasters
clamp_ts

clamp time series data
combineGeoms

Combine geometries
colors

Color table
crop

Cut out a geographic subset
buffer

Create a buffer around vector geometries or raster patches
classify

Classify (or reclassify) cell values
crosstab

Cross-tabulate
click

Query by clicking on a map
autocorrelation

Spatial autocorrelation
as.raster

Coerce to a "raster" object
c

Combine SpatRaster or SpatVector objects
cover

Replace values with values from another object
deepcopy

Deep copy
centroids

Centroids
cells

Get cell numbers
direction

Direction
densify

Add additional nodes to lines or polygons
disagg

Disaggregate raster cells or vector geometries
coerce

Coercion to vector, matrix or array
cartogram

Cartogram
tighten

tighten SpatRaster or SpatRasterDataset objects
distance

Geographic distance
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
divide

Subdivide a raster or polygons
hull

Convex, concave, rectangular and circular hulls
diff

Lagged differences
elongate

elongate lines
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
dots

Make a dot-density map
erase

Erase parts of a SpatVector object
ext

Create, get or set a SpatExtent
expanse

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

Categorical rasters
costDist

Cost-distance
fillHoles

Remove holes from polygons
focalReg

Focal regression
focalValues

Get focal values
geom

Get the geometry (coordinates) of a SpatVector
focalMat

Focal weights matrix
Compare-methods

Compare and logical methods
focalPairs

Focal function across two layers
compareGeom

Compare geometries
geomtype

Geometry type of a SpatVector
draw

Draw a polygon, line, extent, or points
fillTime

Fill time gaps in a SpatRaster
deprecated

deprecated methods
density

Density plot
inplace

Change values in-place
crs

Get or set a coordinate reference system
gaps

Find gaps between polygons
hist

Histogram
gdal

GDAL version, supported file formats, and cache size
inset

Make an inset map
extend

Extend
identical

Compare two SpatRasters for equality
initialize

Initialize a SpatRaster with values
impose

Impose the geometry of a SpatRaster to those in a SpatRasterCollection.
is.bool

Raster value types
is.empty

Check if a SpatExtent or SpatVector is empty
layerCor

Correlation and (weighted) covariance
interpIDW

Interpolate points using a moving window
add_legend

add a custom legend
flip

Flip or reverse a raster
extract

Extract values from a SpatRaster
focal3D

Three-dimensional focal values
Math-methods

General mathematical methods
focalCpp

Compute focal values with an iterating C++ function
is.rotated

Check for rotation
mem

Memory available and needed
interpNear

Nearest neighbor interpolation
forceCCW

force counter-clockwise polygons
is.valid

Check or fix polygon or extent validity
merge

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

meta
normalize.longitude

normalize vector data that crosses the dateline
datatype

Data type of a SpatRaster or SpatVector
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
north

North arrow
mergeTime

merge SpatRasters by timelines to create a single timeseries
plet

Plot with leaflet
princomp

SpatRaster PCA with princomp
depth

depth of SpatRaster layers
halo

Add halo-ed text to a plot
headtail

head and tail of a SpatRaster or SpatVector
metags

Set or get metadata
mosaic

mosaic SpatRasters
describe

describe
extremes

Get or compute the minimum and maximum cell values
extractAlong

extract values along lines
is.flipped

Check for rotation
is.lonlat

Check for longitude/latitude crs
k_means

k_means
freq

Frequency table
lapp

Apply a function to layers of a SpatRaster, or sub-datasets of a SpatRasterDataset
na.omit

Find and remove geometries that are NA
ifel

ifelse for SpatRasters
image

SpatRaster image method
interpolation

Spatial interpolation
intersect

Intersection
mask

Mask values in a SpatRaster or SpatVector
makeTiles

Make tiles or get their extents
makeVRT

Make a VRT header file
extractRange

Extract values for a range of layers from a SpatRaster
modal

modal value
flowAccumulation

Flow accumulation
panel

Map panel
names

Names of Spat* objects
patches

Detect patches (clumps) of cells
plot_extent

Plot a SpatExtent
focal

Focal values
plot_graticule

Plot a graticule
match

Value matching for SpatRasters
prcomp

SpatRaster PCA with prcomp
rectify

Rectify a SpatRaster
regress

Cell level regression
not.na

is not NA
rescale

rescale
nseg

Number of segments
nearest

nearby geometries
roll

Rolling (moving) functions
predict

Spatial model predictions
global

global statistics
project

Change the coordinate reference system
time

time of SpatRaster layers
watershed

Catchment delineation
tmpFiles

Temporary files
relate

Spatial relationships between geometries
plot

Make a map
graticule

Create a graticule
add_grid

add a grid to a map made with terra
gridDist

Distance on a grid
linearUnits

Linear units of the coordinate reference system
lines

Add points, lines, or polygons to a map
rep

Replicate layers
sds

Create a SpatRasterDataset
plotRGB

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

segregate
sieve

Sieve filter
map_extent

Get the coordinates of the extent of a map
quantile

Quantiles of spatial data
origin

Origin
pairs

Pairs plot (matrix of scatterplots)
map.pal

color palettes for mapping
perim

Perimeter or length
weighted.mean

Weighted mean of layers
same.crs

Compare coordinate reference systems
writeVector

Write SpatVector data to a file
query

Query a SpatVectorProxy object
xapp

Apply a function to the cells of a two SpatRasters
persp

Perspective plot
simplifyGeom

simplifyGeom geometries
subset_dollar

Subset a SpatRaster or a SpatVector
subset

Subset a SpatRaster or a SpatVector
rast

Create a SpatRaster
summary

summary
rangeFill

Fill layers with a range
rapp

Range-apply
rasterize

Rasterize vector data
surfArea

Compute surface area from elevation data
replace_dollar

Replace with $<-
rasterizeGeom

Rasterize geometric properties of vector data
units

units of SpatRaster or SpatRasterDataSet
rcl

Combine row, column, and layer numbers
spatSample

Take a regular sample
rasterizeWin

Rasterize points with a moving window
scatterplot

Scatterplot of two SpatRaster layers
replace_layers

Replace layers or variables
rotate

Rotate data along longitude
update

Change values in a file
scale

Scale values
scale_linear

Scale values linearly
scoff

Scale (gain) and offset
rowSums

row/col sums and means for SpatRaster
vrt

Virtual Raster Dataset
readwrite

Read from, or write to, file
sharedPaths

Shared paths
replace_values

Replace values of a SpatRaster
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
selectRange

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

scale bar
shift

Shift
serialize

saveRDS and serialize for SpatVector and SpatRaster*
sel

Spatial selection
selectHighest

select cells with high or low values
vrt_tiles

filenames of VRT tiles
subset_double

Subset a SpatRaster or a SpatVector
sort

Sort a SpatRaster or SpatVector
sources

Data sources of a SpatRaster
setValues

Set the values of raster cells or of geometry attributes
subst

replace cell values
where

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

Extract values from a SpatRaster, SpatVector or SpatExtent
which.lyr

Which cells are TRUE?
shade

Hill shading
summarize

Summarize
tapp

Apply a function to subsets of layers of a SpatRaster
sprc

Create a SpatRasterCollection
svc

Create a SpatVectorCollection
symdif

Symmetrical difference
spin

spin a SpatVector
split

Split a SpatRaster or SpatVector
stretch

Stretch
toMemory

Read all cell values into memory
options

Options
topology

Vector topology methods
terra-package

Description of the methods in the terra package
terrain

terrain characteristics
text

Add labels to a map
vect

Create SpatVector objects
union

Union SpatVector or SpatExtent objects
unique

Unique values
thresh

Thresholding
vector_layers

List or remove layers from a vector file
values

Cell values and geometry attributes
width

SpatVector geometric properties
varnames

variable and long variable names
window

Set a window
wrap

wrap and unwrap
wrapCache

SpatRaster wrap with caching options
transpose

Transpose
xmin

Get or set single values of an extent
trim

Trim a SpatRaster
viewshed

Compute a viewshed
voronoi

Voronoi diagram and Delaunay triangles
writeCDF

Write raster data to a NetCDF file
writeRaster

Write raster data to a file
zonal

Zonal statistics
zoom

Zoom in on a map
xyRowColCell

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