Learn R Programming

terra (version 1.8-10)

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

License

GPL (>= 3)

Maintainer

Robert Hijmans

Last Published

January 14th, 2025

Functions in terra (1.8-10)

RGB

Layers representing colors
NAflag

Set the NA flag
SpatExtent-class

Class "SpatExtent"
SpatRaster-class

SpatRaster class
NIDP

Number of immediate adjacent cells flowing into each cell
SpatVector-class

Class "SpatVector"
activeCat

Active category
app

Apply a function to the cells of a SpatRaster
add

Add (in place) a SpatRaster to another SpatRaster or to a SpatRasterDataset or SpatRasterCollection
as.data.frame

SpatRaster or SpatVector to data.frame
Arith-methods

Arithmetic
approximate

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

Bar plot of a SpatRaster
bestMatch

bestMatch
as.lines

Conversion to a SpatVector of lines
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
all.equal

Compare two SpatRasters for equality
animate

Animate a SpatRaster
aggregate

Aggregate raster or vector data
align

Align a SpatExtent
boundaries

Detect boundaries (edges)
boxplot

Box plot of SpatRaster data
buffer

Create a buffer around vector geometries or raster patches
add_box

draw a box
add_mtext

draw a box
as.list

Coerce a Spat* object to a list
clamp

Clamp values
clamp_ts

clamp time series data
as.points

Conversion to a SpatVector of points
cells

Get cell numbers
adjacent

Adjacent cells
catalyze

Factors to numeric
cellSize

Area covered by each raster cell
concats

Concatenate categorical rasters
coerce

Coercion to vector, matrix or array
tighten

tighten SpatRaster or SpatRasterDataset objects
cover

Replace values with values from another object
centroids

Centroids
atan2

Two argument arc-tangent
autocorrelation

Spatial autocorrelation
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
colors

Color table
combineGeoms

Combine geometries
c

Combine SpatRaster or SpatVector objects
deepcopy

Deep copy
hull

Convex, concave, rectangular and circular hulls
contour

Contour plot
cartogram

Cartogram
densify

Add additional nodes to lines or polygons
density

Density plot
deprecated

deprecated methods
classify

Classify (or reclassify) cell values
Compare-methods

Compare and logical methods
click

Query by clicking on a map
elongate

elongate lines
costDist

Cost-distance
compareGeom

Compare geometries
extractAlong

extract values along lines
extractRange

Extract values for a range of layers from a SpatRaster
focal3D

Three-dimensional focal values
direction

Direction
erase

Erase parts of a SpatVector object
disagg

Disaggregate raster cells or vector geometries
factors

Categorical rasters
distance

Geographic distance
crs

Get or set a coordinate reference system
fillHoles

Remove holes from polygons
crop

Cut out a geographic subset
focalCpp

Compute focal values with an iterating C++ function
divide

Subdivide a raster or polygons
focalReg

Focal regression
crosstab

Cross-tabulate
datatype

Data type of a SpatRaster or SpatVector
diff

Lagged differences
focalValues

Get focal values
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
expanse

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

Make a dot-density map
add_grid

add a grid to a map made with terra
depth

depth of SpatRaster layers
draw

Draw a polygon, line, extent, or points
describe

describe
gridDist

Distance on a grid
flowAccumulation

Flow accumulation
ext

Create, get or set a SpatExtent
focal

Focal values
is.lonlat

Check for longitude/latitude crs
fillTime

Fill time gaps in a SpatRaster
flip

Flip or reverse a raster
geom

Get the geometry (coordinates) of a SpatVector
extend

Extend
is.rotated

Check for rotation
lapp

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

Geometry type of a SpatVector
layerCor

Correlation and (weighted) covariance
extract

Extract values from a SpatRaster
gaps

Find gaps between polygons
gdal

GDAL version, supported file formats, and cache size
halo

Add halo-ed text to a plot
focalMat

Focal weights matrix
focalPairs

Focal function across two layers
map.pal

color palettes for mapping
mask

Mask values in a SpatRaster or SpatVector
nseg

Number of segments
hist

Histogram
lines

Add points, lines, or polygons to a map
origin

Origin
makeTiles

Make tiles or get their extents
identical

Compare two SpatRasters for equality
interpolation

Spatial interpolation
intersect

Intersection
headtail

head and tail of a SpatRaster or SpatVector
mergeTime

merge SpatRasters by timelines to create a single timeseries
forceCCW

force counter-clockwise polygons
is.bool

Raster value types
freq

Frequency table
plet

Plot with leaflet
global

global statistics
meta

meta
ifel

ifelse for SpatRasters
is.empty

Check if a SpatExtent or SpatVector is empty
plot

Make a map
na.omit

Find and remove geometries that are NA
graticule

Create a graticule
names

Names of Spat* objects
image

SpatRaster image method
persp

Perspective plot
inplace

Change values in-place
makeVRT

Make a VRT header file
inset

Make an inset map
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
impose

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

Check or fix polygon or extent validity
map_extent

Get the coordinates of the extent of a map
initialize

Initialize a SpatRaster with values
k_means

k_means
rapp

Range-apply
metags

Set or get metadata
rast

Create a SpatRaster
readwrite

Read from, or write to, file
rasterizeWin

Rasterize points with a moving window
interpIDW

Interpolate points using a moving window
interpNear

Nearest neighbor interpolation
rcl

Combine row, column, and layer numbers
rowSums

row/col sums and means for SpatRaster
pairs

Pairs plot (matrix of scatterplots)
match

Value matching for SpatRasters
add_legend

add a custom legend
extremes

Get or compute the minimum and maximum cell values
panel

Map panel
same.crs

Compare coordinate reference systems
rectify

Rectify a SpatRaster
Math-methods

General mathematical methods
linearUnits

Linear units of the coordinate reference system
modal

modal value
replace_layers

Replace layers or variables
mosaic

mosaic SpatRasters
mem

Memory available and needed
replace_values

Replace values of a SpatRaster
merge

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

North arrow
not.na

is not NA
sources

Data sources of a SpatRaster
segregate

segregate
plot_graticule

Plot a graticule
nearest

nearby geometries
normalize.longitude

normalize vector data that crosses the dateline
sel

Spatial selection
spin

spin a SpatVector
prcomp

SpatRaster PCA with prcomp
rep

Replicate layers
replace_dollar

Replace with $<-
patches

Detect patches (clumps) of cells
stretch

Stretch
perim

Perimeter or length
sbar

scale bar
subset

Subset a SpatRaster or a SpatVector
scale

Scale values
terrain

terrain characteristics
plotRGB

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

Get or set single values of an extent
plot_extent

Plot a SpatExtent
shade

Hill shading
sharedPaths

Shared paths
text

Add labels to a map
terra-package

Description of the methods in the terra package
subset_dollar

Subset a SpatRaster or a SpatVector
project

Change the coordinate reference system
options

Options
toMemory

Read all cell values into memory
transpose

Transpose
query

Query a SpatVectorProxy object
predict

Spatial model predictions
wrapCache

SpatRaster wrap with caching options
princomp

SpatRaster PCA with princomp
topology

Vector topology methods
trim

Trim a SpatRaster
quantile

Quantiles of spatial data
weighted.mean

Weighted mean of layers
rangeFill

Fill layers with a range
where

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

Cell level regression
spatSample

Take a regular sample
rasterize

Rasterize vector data
sapp

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

Spatial relationships between geometries
subset_double

Subset a SpatRaster or a SpatVector
resample

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

summary
vect

Create SpatVector objects
which.lyr

Which cells are TRUE?
rescale

rescale
rotate

Rotate data along longitude
rasterizeGeom

Rasterize geometric properties of vector data
vector_layers

List or remove layers from a vector file
union

Union SpatVector or SpatExtent objects
wrap

wrap and unwrap
unique

Unique values
roll

Rolling (moving) functions
scale_linear

Scale values linearly
scatterplot

Scatterplot of two SpatRaster layers
xyRowColCell

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

Symmetrical difference
scoff

Scale (gain) and offset
setValues

Set the values of raster cells or of geometry attributes
shift

Shift
sieve

Sieve filter
svc

Create a SpatVectorCollection
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
sds

Create a SpatRasterDataset
selectHighest

select cells with high or low values
summarize

Summarize
subst

replace cell values
watershed

Catchment delineation
surfArea

Compute surface area from elevation data
viewshed

Compute a viewshed
vrt

Virtual Raster Dataset
serialize

saveRDS and serialize for SpatVector and SpatRaster*
varnames

variable and long variable names
values

Cell values and geometry attributes
selectRange

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

Set a window
sprc

Create a SpatRasterCollection
tapp

Apply a function to subsets of layers of a SpatRaster
update

Change values in a file
simplifyGeom

simplifyGeom geometries
width

SpatVector geometric properties
time

time of SpatRaster layers
voronoi

Voronoi diagram and Delaunay triangles
writeRaster

Write raster data to a file
sort

Sort a SpatRaster or SpatVector
units

units of SpatRaster or SpatRasterDataSet
writeCDF

Write raster data to a NetCDF file
split

Split a SpatRaster or SpatVector
zoom

Zoom in on a map
tmpFiles

Temporary files
vrt_tiles

filenames of VRT tiles
writeVector

Write SpatVector data to a file
xapp

Apply a function to the cells of a two SpatRasters
zonal

Zonal statistics