Learn R Programming

⚠️There's a newer version (1.8-42) of this package.Take me there.

terra

This R package is a replacement of the raster package. It has a very similar, but simpler, interface, and it is much faster.

All native computations are done in C++. Classes, methods and properties are exposed via a Rcpp module. The R side has two main S4 classes (SpatRaster and SpatVector) that represent spatial data. These classes have only slot, a reference to a C++ object. They are used to provide a "normal" "S4" R user-interface as in the raster package.

The first (alpha) release is expected by July 2019.

Installation

You need to have the current version of raster from CRAN (>= 2.9-22) or install the development version of "raster".

Windows

If you are on Windows, you need to first install Rtools to get a C++ compiler that R can use. After that, you need the first install development version of "raster" for "terra" to work.

Then, in R, install the packages.

library(devtools)
install.packages("raster")
#devtools::install_github("rspatial/raster")
devtools::install_github("rspatial/terra")

Mac - OSX

The libraries GDAL (>= 2.0.0), GEOS (>= 3.3.0) and Proj.4 (>= 4.8.0) are required (as for sf)

With Homebrew you can do:

brew install gdal

And now, in R, install the packages.

library(devtools)
install.packages("raster")
#devtools::install_github("rspatial/raster")
devtools::install_github("rspatial/terra")

Linux

The libraries GDAL (>= 2.0.0), GEOS (>= 3.3.0) and Proj.4 (>= 4.8.0) are required (as for sf)

To install these on Ubuntu you can do:

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable
sudo apt-get update
sudo apt-get install libgdal-dev libgeos-dev libproj-dev 

And now, in R, install the packages.

library(devtools)
install.packages("raster")
#devtools::install_github("rspatial/raster")
devtools::install_github("rspatial/terra")

See the sf instructions for installation on other linux systems.

Copy Link

Version

Install

install.packages('terra')

Monthly Downloads

202,413

Version

0.2-9

License

GPL (>=3)

Issues

Pull Requests

Stars

Forks

Maintainer

Robert Hijmans

Last Published

April 2nd, 2025

Functions in terra (0.2-9)

crop

Crop
cover

Cover (replace) NA values with values of another raster
contour

Contour plot
compareGeom

Compare geometries of SpatRaster objects
buffer

buffer
crs

Get or set a coordinate reference system (projection)
density

Density plot
disaggregate

Disaggregate raster cells
dimensions

Dimensions of a SpatRaster or SpatVector
initialize

Initialize a SpatRaster with values
c

Combine
aggregate

Aggregate raster cells
area

Area and length
clamp

Clamp values
distance

Geographic distance
draw

Draw a polygon, line, extent, or points
hist

Histogram
ifel

ifelse for SpatRaster objects
extend

Extend
SpatRaster-class

SpatRaster class
atan2

Two argument arc-tangent
names

Names of Spat objects
overlay

Overlay SpatRaster objects
flip

Flip a raster
warp

warp a SpatRaster
writeRaster

Write raster data to a file
SpatDataFrame-class

C++ classes
click

Query by clicking on a map
focal

Focal values
classify

classify
extent

ext
global

global statistics
interpolate

Interpolate
range

get or compute min and max values
merge

Merge SpatRaster or SpatExtent objects
rotate

rotate
sampleRegular

Take a regular sample
persp

Perspective plot
pairs

Pairs plot (matrix of scatterplots)
shift

Shift
predict

Spatial model predictions
project

Change the coordinate reference system
text

Add labels to a map
head and tail

Show the head or tail of a Spat* object
plot

Plot a SpatRaster or SpatVector
plotRGB

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

Extract values from a SpatRaster
sources

Data sources of a SpatRaster
subset-vector

Subset of a SpatVector
transpose

Transpose
factors

Factors
mask

Mask values in a SpatRaster
coerce

Coercion to other object types
zonal

Zonal statistics
xyRowColCell

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

geom
geomtype

Geometry type of a SpatVector
isLonLat

Check for longitude/latitude crs
subset

Subset of a SpatRaster
values

Get cell values
terra-package

terra
read and write

read from or write to file
local

Local statistics
reduce

reduce
SpatOptions-class

options
vect

Create SpatVector objects
rast

Create a SpatRaster
trim

Trim a SpatRaster
rasterize

rasterize
math

Mathematical operations with SpatRaster objects
unique

Unique values
zoom

Zoom in on a map
adjacent

Adjacent cells
as.data.frame

Get the attributes of a SpatVector
boundaries

boundaries (edges) detection
SpatVector-class

Class "SpatVector"
SpatExtent-class

Class "SpatExtent"
rastApply

Apply a function to subsets of layers of a SpatRaster