Learn R Programming

terra (version 1.8-21)

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-21

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

February 10th, 2025

Functions in terra (1.8-21)

Arith-methods

Arithmetic
all.equal

Compare two SpatRasters for equality
app

Apply a function to the cells of a SpatRaster
animate

Animate a SpatRaster
as.lines

Conversion to a SpatVector of lines
align

Align a SpatExtent
as.character

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

Estimate values for cell values that are NA by interpolating between layers
as.data.frame

SpatRaster or SpatVector to data.frame
as.polygons

Conversion to a SpatVector of polygons
aggregate

Aggregate raster or vector data
barplot

Bar plot of a SpatRaster
autocorrelation

Spatial autocorrelation
bestMatch

bestMatch
as.list

Coerce a Spat* object to a list
atan2

Two argument arc-tangent
boundaries

Detect boundaries (edges)
centroids

Centroids
clamp

Clamp values
as.raster

Coerce to a "raster" object
clamp_ts

clamp time series data
add_box

draw a box
boxplot

Box plot of SpatRaster data
buffer

Create a buffer around vector geometries or raster patches
as.points

Conversion to a SpatVector of points
cells

Get cell numbers
c

Combine SpatRaster or SpatVector objects
compareGeom

Compare geometries
Compare-methods

Compare and logical methods
cartogram

Cartogram
concats

Concatenate categorical rasters
catalyze

Factors to numeric
contour

Contour plot
tighten

tighten SpatRaster or SpatRasterDataset objects
coerce

Coercion to vector, matrix or array
classify

Classify (or reclassify) cell values
hull

Convex, concave, rectangular and circular hulls
crop

Cut out a geographic subset
click

Query by clicking on a map
cover

Replace values with values from another object
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
crosstab

Cross-tabulate
colors

Color table
cellSize

Area covered by each raster cell
describe

describe
depth

depth of SpatRaster layers
diff

Lagged differences
divide

Subdivide a raster or polygons
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
crs

Get or set a coordinate reference system
distance

Geographic distance
densify

Add additional nodes to lines or polygons
datatype

Data type of a SpatRaster or SpatVector
deepcopy

Deep copy
elongate

elongate lines
costDist

Cost-distance
combineGeoms

Combine geometries
erase

Erase parts of a SpatVector object
expanse

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

Density plot
focal

Focal values
flowAccumulation

Flow accumulation
extractAlong

extract values along lines
extractRange

Extract values for a range of layers from a SpatRaster
focalValues

Get focal values
direction

Direction
focalReg

Focal regression
extend

Extend
disagg

Disaggregate raster cells or vector geometries
extract

Extract values from a SpatRaster
draw

Draw a polygon, line, extent, or points
dots

Make a dot-density map
focal3D

Three-dimensional focal values
gaps

Find gaps between polygons
ifel

ifelse for SpatRasters
gdal

GDAL version, supported file formats, and cache size
focalCpp

Compute focal values with an iterating C++ function
ext

Create, get or set a SpatExtent
interpolation

Spatial interpolation
fillTime

Fill time gaps in a SpatRaster
intersect

Intersection
deprecated

deprecated methods
factors

Categorical rasters
add_grid

add a grid to a map made with terra
gridDist

Distance on a grid
flip

Flip or reverse a raster
image

SpatRaster image method
k_means

k_means
global

global statistics
lapp

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

Focal weights matrix
graticule

Create a graticule
is.rotated

Check for rotation
interpIDW

Interpolate points using a moving window
interpNear

Nearest neighbor interpolation
is.valid

Check or fix polygon or extent validity
fillHoles

Remove holes from polygons
impose

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

Focal function across two layers
makeTiles

Make tiles or get their extents
geom

Get the geometry (coordinates) of a SpatVector
mask

Mask values in a SpatRaster or SpatVector
initialize

Initialize a SpatRaster with values
geomtype

Geometry type of a SpatVector
match

Value matching for SpatRasters
halo

Add halo-ed text to a plot
origin

Origin
pairs

Pairs plot (matrix of scatterplots)
prcomp

SpatRaster PCA with prcomp
forceCCW

force counter-clockwise polygons
inset

Make an inset map
inplace

Change values in-place
headtail

head and tail of a SpatRaster or SpatVector
extremes

Get or compute the minimum and maximum cell values
modal

modal value
predict

Spatial model predictions
makeVRT

Make a VRT header file
mergeTime

merge SpatRasters by timelines to create a single timeseries
merge

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

Create a SpatRaster
mosaic

mosaic SpatRasters
na.omit

Find and remove geometries that are NA
meta

meta
freq

Frequency table
is.bool

Raster value types
rasterize

Rasterize vector data
hist

Histogram
plot_extent

Plot a SpatExtent
plot_graticule

Plot a graticule
metags

Set or get metadata
is.empty

Check if a SpatExtent or SpatVector is empty
layerCor

Correlation and (weighted) covariance
identical

Compare two SpatRasters for equality
rcl

Combine row, column, and layer numbers
is.flipped

Check for rotation
is.lonlat

Check for longitude/latitude crs
panel

Map panel
patches

Detect patches (clumps) of cells
add_legend

add a custom legend
names

Names of Spat* objects
nearest

nearby geometries
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
map_extent

Get the coordinates of the extent of a map
plet

Plot with leaflet
rangeFill

Fill layers with a range
readwrite

Read from, or write to, file
sds

Create a SpatRasterDataset
linearUnits

Linear units of the coordinate reference system
map.pal

color palettes for mapping
princomp

SpatRaster PCA with princomp
lines

Add points, lines, or polygons to a map
project

Change the coordinate reference system
Math-methods

General mathematical methods
rasterizeGeom

Rasterize geometric properties of vector data
segregate

segregate
rasterizeWin

Rasterize points with a moving window
sort

Sort a SpatRaster or SpatVector
not.na

is not NA
nseg

Number of segments
rapp

Range-apply
relate

Spatial relationships between geometries
replace_values

Replace values of a SpatRaster
rotate

Rotate data along longitude
sources

Data sources of a SpatRaster
spin

spin a SpatVector
rowSums

row/col sums and means for SpatRaster
mem

Memory available and needed
setValues

Set the values of raster cells or of geometry attributes
perim

Perimeter or length
rep

Replicate layers
shade

Hill shading
resample

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

Spatial selection
selectHighest

select cells with high or low values
split

Split a SpatRaster or SpatVector
sharedPaths

Shared paths
sprc

Create a SpatRasterCollection
rescale

rescale
normalize.longitude

normalize vector data that crosses the dateline
svc

Create a SpatVectorCollection
roll

Rolling (moving) functions
north

North arrow
shift

Shift
options

Options
stretch

Stretch
symdif

Symmetrical difference
scale

Scale values
scale_linear

Scale values linearly
persp

Perspective plot
selectRange

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

Subset a SpatRaster or a SpatVector
quantile

Quantiles of spatial data
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
serialize

saveRDS and serialize for SpatVector and SpatRaster*
plot

Make a map
transpose

Transpose
plotRGB

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

terrain characteristics
query

Query a SpatVectorProxy object
replace_dollar

Replace with $<-
trim

Trim a SpatRaster
tapp

Apply a function to subsets of layers of a SpatRaster
replace_layers

Replace layers or variables
rectify

Rectify a SpatRaster
text

Add labels to a map
thresh

Thresholding
scatterplot

Scatterplot of two SpatRaster layers
watershed

Catchment delineation
units

units of SpatRaster or SpatRasterDataSet
terra-package

Description of the methods in the terra package
viewshed

Compute a viewshed
update

Change values in a file
regress

Cell level regression
values

Cell values and geometry attributes
varnames

variable and long variable names
zonal

Zonal statistics
zoom

Zoom in on a map
same.crs

Compare coordinate reference systems
voronoi

Voronoi diagram and Delaunay triangles
weighted.mean

Weighted mean of layers
window

Set a window
width

SpatVector geometric properties
writeVector

Write SpatVector data to a file
xapp

Apply a function to the cells of a two SpatRasters
spatSample

Take a regular sample
sapp

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

scale bar
union

Union SpatVector or SpatExtent objects
unique

Unique values
xmin

Get or set single values of an extent
scoff

Scale (gain) and offset
vect

Create SpatVector objects
xyRowColCell

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

Sieve filter
vector_layers

List or remove layers from a vector file
where

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

Subset a SpatRaster or a SpatVector
subset_dollar

Subset a SpatRaster or a SpatVector
simplifyGeom

simplifyGeom geometries
which.lyr

Which cells are TRUE?
time

time of SpatRaster layers
subst

replace cell values
tmpFiles

Temporary files
wrap

wrap and unwrap
wrapCache

SpatRaster wrap with caching options
summarize

Summarize
surfArea

Compute surface area from elevation data
summary

summary
toMemory

Read all cell values into memory
topology

Vector topology methods
vrt

Virtual Raster Dataset
vrt_tiles

filenames of VRT tiles
writeCDF

Write raster data to a NetCDF file
writeRaster

Write raster data to a file
NAflag

Set the NA flag
adjacent

Adjacent cells or polygons
add

Add (in place) a SpatRaster to another SpatRaster or to a SpatRasterDataset or SpatRasterCollection
SpatExtent-class

Class "SpatExtent"
NIDP

Number of immediate adjacent cells flowing into each cell
RGB

Layers representing colors
add_mtext

draw a box
activeCat

Active category
SpatRaster-class

SpatRaster class
SpatVector-class

Class "SpatVector"