Learn R Programming

terra (version 1.8-5)

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

190,738

Version

1.8-5

License

GPL (>= 3)

Maintainer

Last Published

December 12th, 2024

Functions in terra (1.8-5)

SpatRaster-class

SpatRaster class
NAflag

Set the NA flag
add_mtext

draw a box
activeCat

Active category
SpatVector-class

Class "SpatVector"
NIDP

Number of immediate adjacent cells flowing into each cell
all.equal

Compare two SpatRasters for equality
animate

Animate a SpatRaster
app

Apply a function to the cells of a SpatRaster
aggregate

Aggregate raster or vector data
add

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

Layers representing colors
approximate

Estimate values for cell values that are NA by interpolating between layers
SpatExtent-class

Class "SpatExtent"
adjacent

Adjacent cells
boundaries

Detect boundaries (edges)
as.list

Coerce a Spat* object to a list
add_box

draw a box
align

Align a SpatExtent
Arith-methods

Arithmetic
as.character

Create a text representation of (the skeleton of) an object
as.points

Conversion to a SpatVector of points
cells

Get cell numbers
atan2

Two argument arc-tangent
autocorrelation

Spatial autocorrelation
clamp

Clamp values
colors

Color table
clamp_ts

clamp time series data
combineGeoms

Combine geometries
classify

Classify (or reclassify) cell values
click

Query by clicking on a map
centroids

Centroids
as.lines

Conversion to a SpatVector of lines
as.data.frame

SpatRaster or SpatVector to data.frame
boxplot

Box plot of SpatRaster data
buffer

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

Conversion to a SpatVector of polygons
deepcopy

Deep copy
as.raster

Coerce to a "raster" object
coerce

Coercion to vector, matrix or array
catalyze

Factors to numeric
crs

Get or set a coordinate reference system
densify

Add additional nodes to lines or polygons
datatype

Data type of a SpatRaster or SpatVector
tighten

tighten SpatRaster or SpatRasterDataset objects
erase

Erase parts of a SpatVector object
density

Density plot
crop

Cut out a geographic subset
expanse

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

Lagged differences
crosstab

Cross-tabulate
dimensions

Dimensions of a SpatRaster or SpatVector and related objects
distance

Geographic distance
deprecated

deprecated methods
focal

Focal values
focal3D

Three-dimensional focal values
barplot

Bar plot of a SpatRaster
focalPairs

Focal function across two layers
draw

Draw a polygon, line, extent, or points
elongate

elongate lines
dots

Make a dot-density map
focalReg

Focal regression
graticule

Create a graticule
add_grid

add a grid to a map made with terra
freq

Frequency table
extract

Extract values from a SpatRaster
bestMatch

bestMatch
cellSize

Area covered by each raster cell
c

Combine SpatRaster or SpatVector objects
gaps

Find gaps between polygons
initialize

Initialize a SpatRaster with values
extractAlong

extract values along lines
Compare-methods

Compare and logical methods
cartogram

Cartogram
compareGeom

Compare geometries
focalValues

Get focal values
headtail

head and tail of a SpatRaster or SpatVector
flip

Flip or reverse a raster
hist

Histogram
interpNear

Nearest neighbor interpolation
flowAccumulation

Flow accumulation
cover

Replace values with values from another object
contour

Contour plot
concats

Concatenate categorical rasters
crds

Get the coordinates of SpatVector geometries or SpatRaster cells
geomtype

Geometry type of a SpatVector
inplace

Change values in-place
interpolation

Spatial interpolation
global

global statistics
forceCCW

force counter-clockwise polygons
gridDist

Distance on a grid
convHull

Convex hull, minimal bounding rotated rectangle, and minimal bounding circle
halo

Add halo-ed text to a plot
direction

Direction
is.rotated

Check for rotation
is.valid

Check or fix polygon or extent validity
linearUnits

Linear units of the coordinate reference system
lines

Add points, lines, or polygons to a map
disagg

Disaggregate raster cells or vector geometries
extractRange

Extract values for a range of layers from a SpatRaster
makeTiles

Make tiles or get their extents
identical

Compare two SpatRasters for equality
is.empty

Check if a SpatExtent or SpatVector is empty
costDist

Cost-distance
plot_graticule

Plot a graticule
depth

depth of SpatRaster layers
prcomp

SpatRaster PCA with prcomp
describe

describe
makeVRT

Make a VRT header file
is.lonlat

Check for longitude/latitude crs
Math-methods

General mathematical methods
ext

Create, get or set a SpatExtent
ifel

ifelse for SpatRasters
meta

meta
metags

Set or get metadata
extend

Extend
not.na

is not NA
factors

Categorical rasters
inset

Make an inset map
fillHoles

Remove holes from polygons
fillTime

Fill time gaps in a SpatRaster
gdal

GDAL version, supported file formats, and cache size
mem

Memory available and needed
query

Query a SpatVectorProxy object
names

Names of Spat* objects
origin

Origin
geom

Get the geometry (coordinates) of a SpatVector
interpIDW

Interpolate points using a moving window
focalCpp

Compute focal values with an iterating C++ function
nearest

nearby geometries
layerCor

Correlation and (weighted) covariance
image

SpatRaster image method
impose

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

add a custom legend
patches

Detect patches (clumps) of cells
plotRGB

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

Focal weights matrix
rangeFill

Fill layers with a range
extremes

Get or compute the minimum and maximum cell values
intersect

Intersection
modal

modal value
is.bool

Raster value types
plot_extent

Plot a SpatExtent
predict

Spatial model predictions
perim

Perimeter or length
map_extent

Get the coordinates of the extent of a map
rasterizeWin

Rasterize points with a moving window
map.pal

color palettes for mapping
merge

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

k_means
princomp

SpatRaster PCA with princomp
rcl

Combine row, column, and layer numbers
replace_layers

Replace layers or variables
rasterize

Rasterize vector data
lapp

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

Mask values in a SpatRaster or SpatVector
rasterizeGeom

Rasterize geometric properties of vector data
replace_values

Replace values of a SpatRaster
roll

Rolling (moving) functions
mergeTime

merge SpatRasters by timelines to create a single timeseries
pairs

Pairs plot (matrix of scatterplots)
rotate

Rotate data along longitude
normalize.longitude

normalize vector data that crosses the dateline
scatterplot

Scatterplot of two SpatRaster layers
scoff

Scale (gain) and offset
resample

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

Shared paths
panel

Map panel
plet

Plot with leaflet
plot

Make a map
match

Value matching for SpatRasters
mosaic

mosaic SpatRasters
sds

Create a SpatRasterDataset
na.omit

Find and remove geometries that are NA
north

North arrow
rapp

Range-apply
persp

Perspective plot
pitfinder

Pit Finder in a Flow Dir SpatRaster for Watershed Extraction
rast

Create a SpatRaster
project

Change the coordinate reference system
quantile

Quantiles of spatial data
segregate

segregate
rescale

rescale
rep

Replicate layers
readwrite

Read from, or write to, file
shift

Shift
replace_dollar

Replace with $<-
regress

Cell level regression
spatSample

Take a regular sample
setValues

Set the values of raster cells or of geometry attributes
subst

replace cell values
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
shade

Hill shading
summarize

Summarize
spin

spin a SpatVector
sbar

scale bar
scale

Scale values
rectify

Rectify a SpatRaster
split

Split a SpatRaster or SpatVector
svc

Create a SpatVectorCollection
subset

Subset a SpatRaster or a SpatVector
sel

Spatial selection
rowSums

row/col sums and means for SpatRaster
selectHighest

select cells with high or low values
sprc

Create a SpatRasterCollection
symdif

Symmetrical difference
sort

Sort a SpatRaster or SpatVector
same.crs

Compare coordinate reference systems
text

Add labels to a map
time

time of SpatRaster layers
subset_dollar

Subset a SpatRaster or a SpatVector
options

Options
topology

Vector topology methods
update

Change values in a file
transpose

Transpose
values

Cell values and geometry attributes
which.lyr

Which cells are TRUE?
width

SpatVector geometric properties
writeRaster

Write raster data to a file
writeVector

Write SpatVector data to a file
unique

Unique values
units

units of SpatRaster or SpatRasterDataSet
sources

Data sources of a SpatRaster
selectRange

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

terrain characteristics
vrt_tiles

filenames of VRT tiles
serialize

saveRDS and serialize for SpatVector and SpatRaster*
summary

summary
watershed

Catchment delineation
surfArea

Compute surface area from elevation data
tapp

Apply a function to subsets of layers of a SpatRaster
vector_layers

List or remove layers from a vector file
xyRowColCell

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

Stretch
subset_double

Subset a SpatRaster or a SpatVector
zonal

Zonal statistics
terra-package

Description of the methods in the terra package
viewshed

Compute a viewshed
sieve

Sieve filter
subset_single

Extract values from a SpatRaster, SpatVector or SpatExtent
window

Set a window
simplifyGeom

simplifyGeom geometries
xapp

Apply a function to the cells of a two SpatRasters
trim

Trim a SpatRaster
wrap

wrap and unwrap
union

Union SpatVector or SpatExtent objects
xmin

Get or set single values of an extent
voronoi

Voronoi diagram and Delaunay triangles
tmpFiles

Temporary files
vrt

Virtual Raster Dataset
toMemory

Read all cell values into memory
wrapCache

SpatRaster wrap with caching options
varnames

variable and long variable names
vect

Create SpatVector objects
writeCDF

Write raster data to a NetCDF file
weighted.mean

Weighted mean of layers
where

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

Zoom in on a map