Learn R Programming

terra (version 1.8-15)

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

160,039

Version

1.8-15

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

January 24th, 2025

Functions in terra (1.8-15)

all.equal

Compare two SpatRasters for equality
RGB

Layers representing colors
direction

Direction
lines

Add points, lines, or polygons to a map
as.list

Coerce a Spat* object to a list
cells

Get cell numbers
meta

meta
boxplot

Box plot of SpatRaster data
focalMat

Focal weights matrix
NAflag

Set the NA flag
barplot

Bar plot of a SpatRaster
cover

Replace values with values from another object
lapp

Apply a function to layers of a SpatRaster, or sub-datasets of a SpatRasterDataset
as.points

Conversion to a SpatVector of points
erase

Erase parts of a SpatVector object
as.polygons

Conversion to a SpatVector of polygons
interpolation

Spatial interpolation
scale

Scale values
density

Density plot
app

Apply a function to the cells of a SpatRaster
classify

Classify (or reclassify) cell values
add_mtext

draw a box
distance

Geographic distance
SpatExtent-class

Class "SpatExtent"
shift

Shift
clamp_ts

clamp time series data
extend

Extend
adjacent

Adjacent cells or polygons
persp

Perspective plot
aggregate

Aggregate raster or vector data
ifel

ifelse for SpatRasters
makeVRT

Make a VRT header file
Compare-methods

Compare and logical methods
expanse

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

Detect boundaries (edges)
Arith-methods

Arithmetic
datatype

Data type of a SpatRaster or SpatVector
as.character

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

Clamp values
contour

Contour plot
add_box

draw a box
centroids

Centroids
click

Query by clicking on a map
align

Align a SpatExtent
hull

Convex, concave, rectangular and circular hulls
approximate

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

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

Compare geometries
image

SpatRaster image method
freq

Frequency table
modal

modal value
costDist

Cost-distance
colors

Color table
SpatRaster-class

SpatRaster class
SpatVector-class

Class "SpatVector"
ext

Create, get or set a SpatExtent
depth

depth of SpatRaster layers
crosstab

Cross-tabulate
describe

describe
tighten

tighten SpatRaster or SpatRasterDataset objects
focal3D

Three-dimensional focal values
geom

Get the geometry (coordinates) of a SpatVector
update

Change values in a file
deepcopy

Deep copy
flip

Flip or reverse a raster
nearest

nearby geometries
animate

Animate a SpatRaster
interpIDW

Interpolate points using a moving window
buffer

Create a buffer around vector geometries or raster patches
activeCat

Active category
concats

Concatenate categorical rasters
catalyze

Factors to numeric
origin

Origin
focalPairs

Focal function across two layers
geomtype

Geometry type of a SpatVector
mem

Memory available and needed
combineGeoms

Combine geometries
add_legend

add a custom legend
inset

Make an inset map
impose

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

Names of Spat* objects
NIDP

Number of immediate adjacent cells flowing into each cell
factors

Categorical rasters
bestMatch

bestMatch
as.raster

Coerce to a "raster" object
inplace

Change values in-place
crs

Get or set a coordinate reference system
stretch

Stretch
sharedPaths

Shared paths
atan2

Two argument arc-tangent
rowSums

row/col sums and means for SpatRaster
densify

Add additional nodes to lines or polygons
dots

Make a dot-density map
merge

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

Data sources of a SpatRaster
is.bool

Raster value types
cellSize

Area covered by each raster cell
plot_extent

Plot a SpatExtent
c

Combine SpatRaster or SpatVector objects
vrt

Virtual Raster Dataset
as.data.frame

SpatRaster or SpatVector to data.frame
as.lines

Conversion to a SpatVector of lines
map.pal

color palettes for mapping
is.lonlat

Check for longitude/latitude crs
split

Split a SpatRaster or SpatVector
fillTime

Fill time gaps in a SpatRaster
deprecated

deprecated methods
coerce

Coercion to vector, matrix or array
cartogram

Cartogram
unique

Unique values
mosaic

mosaic SpatRasters
autocorrelation

Spatial autocorrelation
elongate

elongate lines
summary

summary
global

global statistics
hist

Histogram
fillHoles

Remove holes from polygons
identical

Compare two SpatRasters for equality
divide

Subdivide a raster or polygons
north

North arrow
rotate

Rotate data along longitude
extractAlong

extract values along lines
rapp

Range-apply
svc

Create a SpatVectorCollection
graticule

Create a graticule
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
roll

Rolling (moving) functions
plot_graticule

Plot a graticule
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
focalCpp

Compute focal values with an iterating C++ function
match

Value matching for SpatRasters
setValues

Set the values of raster cells or of geometry attributes
mergeTime

merge SpatRasters by timelines to create a single timeseries
normalize.longitude

normalize vector data that crosses the dateline
disagg

Disaggregate raster cells or vector geometries
flowAccumulation

Flow accumulation
prcomp

SpatRaster PCA with prcomp
makeTiles

Make tiles or get their extents
pairs

Pairs plot (matrix of scatterplots)
is.empty

Check if a SpatExtent or SpatVector is empty
crop

Cut out a geographic subset
diff

Lagged differences
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
sbar

scale bar
is.valid

Check or fix polygon or extent validity
draw

Draw a polygon, line, extent, or points
map_extent

Get the coordinates of the extent of a map
sieve

Sieve filter
headtail

head and tail of a SpatRaster or SpatVector
rep

Replicate layers
mask

Mask values in a SpatRaster or SpatVector
nseg

Number of segments
intersect

Intersection
halo

Add halo-ed text to a plot
resample

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

Map panel
metags

Set or get metadata
gaps

Find gaps between polygons
subst

replace cell values
interpNear

Nearest neighbor interpolation
patches

Detect patches (clumps) of cells
extractRange

Extract values for a range of layers from a SpatRaster
time

time of SpatRaster layers
initialize

Initialize a SpatRaster with values
focalReg

Focal regression
scoff

Scale (gain) and offset
predict

Spatial model predictions
replace_dollar

Replace with $<-
width

SpatVector geometric properties
summarize

Summarize
layerCor

Correlation and (weighted) covariance
not.na

is not NA
extremes

Get or compute the minimum and maximum cell values
gdal

GDAL version, supported file formats, and cache size
spatSample

Take a regular sample
vector_layers

List or remove layers from a vector file
plotRGB

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

wrap and unwrap
rast

Create a SpatRaster
rasterizeWin

Rasterize points with a moving window
zoom

Zoom in on a map
rasterize

Rasterize vector data
scale_linear

Scale values linearly
terrain

terrain characteristics
surfArea

Compute surface area from elevation data
trim

Trim a SpatRaster
transpose

Transpose
rcl

Combine row, column, and layer numbers
wrapCache

SpatRaster wrap with caching options
extract

Extract values from a SpatRaster
vect

Create SpatVector objects
sapp

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

rescale
rasterizeGeom

Rasterize geometric properties of vector data
princomp

SpatRaster PCA with princomp
zonal

Zonal statistics
same.crs

Compare coordinate reference systems
focal

Focal values
rectify

Rectify a SpatRaster
forceCCW

force counter-clockwise polygons
serialize

saveRDS and serialize for SpatVector and SpatRaster*
perim

Perimeter or length
readwrite

Read from, or write to, file
project

Change the coordinate reference system
focalValues

Get focal values
is.rotated

Check for rotation
gridDist

Distance on a grid
subset_dollar

Subset a SpatRaster or a SpatVector
options

Options
add_grid

add a grid to a map made with terra
watershed

Catchment delineation
k_means

k_means
union

Union SpatVector or SpatExtent objects
Math-methods

General mathematical methods
text

Add labels to a map
sds

Create a SpatRasterDataset
quantile

Quantiles of spatial data
units

units of SpatRaster or SpatRasterDataSet
toMemory

Read all cell values into memory
topology

Vector topology methods
weighted.mean

Weighted mean of layers
selectHighest

select cells with high or low values
selectRange

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

Fill layers with a range
na.omit

Find and remove geometries that are NA
linearUnits

Linear units of the coordinate reference system
query

Query a SpatVectorProxy object
replace_layers

Replace layers or variables
plet

Plot with leaflet
regress

Cell level regression
subset_double

Subset a SpatRaster or a SpatVector
plot

Make a map
segregate

segregate
sort

Sort a SpatRaster or SpatVector
simplifyGeom

simplifyGeom geometries
viewshed

Compute a viewshed
sprc

Create a SpatRasterCollection
xmin

Get or set single values of an extent
scatterplot

Scatterplot of two SpatRaster layers
tapp

Apply a function to subsets of layers of a SpatRaster
xapp

Apply a function to the cells of a two SpatRasters
relate

Spatial relationships between geometries
terra-package

Description of the methods in the terra package
voronoi

Voronoi diagram and Delaunay triangles
subset

Subset a SpatRaster or a SpatVector
shade

Hill shading
symdif

Symmetrical difference
xyRowColCell

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

Cell values and geometry attributes
window

Set a window
writeVector

Write SpatVector data to a file
vrt_tiles

filenames of VRT tiles
where

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

Spatial selection
replace_values

Replace values of a SpatRaster
writeCDF

Write raster data to a NetCDF file
spin

spin a SpatVector
tmpFiles

Temporary files
varnames

variable and long variable names
which.lyr

Which cells are TRUE?
writeRaster

Write raster data to a file