fasterRaster {fasterRaster} | R Documentation |
"fasterRaster": Faster raster and spatial vector processing using "GRASS"
Description
fasterRaster: Processing of large-in-memory/-on disk rasters and spatial vectors in using GRASS. Most functions in the terra and sf packages are recreated. Processing of medium-sized and smaller spatial objects will nearly always be faster using terra or sf. To use most of the functions you must have the stand-alone version of GRASS version 8.3 or higher (not the OSGeoW4 installer version). Note that due to differences in how GRASS, terra, and sf were implemented, results will not always be strictly comparable between functions for the same operation.
Most useful tutorials and functions:
The quick-start guide to getting started with fasterRaster:
vignette("fasterRaster", package = "fasterRaster")
:Types of
GRaster
s:vignette("GRasters", package = "fasterRaster")
How to speed up fasterRaster:
vignette("faster_fasterRaster", package = "fasterRaster")
-
faster()
: Set the directory where GRASS is installed on your system, and set or get other package-wide options. This function must be run once before using most fasterRaster functions. -
fast()
: Convert aSpatRaster
,SpatVector
, orsf
vector to fasterRaster's raster format (GRaster
s) or vector format (GVector
s), or load one from a file -
rast()
,vect()
, andst_as_sf()
: ConvertGRaster
s andGVector
s toSpatRaster
s,SpatVector
s, orsf
vectors -
writeRaster()
andwriteVector()
: SaveGRaster
s orGVector
s to disk
Properties of GRasters
-
crs()
: Coordinate reference system -
coordRef()
: Coordinate reference system -
datatype()
: Data type -
ext()
,N()
,S()
,E()
,W()
,top()
, andbottom()
: Spatial extent -
freq()
: Frequencies of cell values in a raster -
is.int()
,is.cell()
,is.float()
,is.doub()
:GRaster
data type (integer/float/double) -
is.factor()
: Does a raster represent categorical data? -
is.lonlat()
: Is an object projected (e.g., in WGS84)? -
levels()
: Names of levels in a categoricalGRaster
-
minmax()
: Minimum and maximum values across all non-NA
cells -
names()
:GRaster
names -
ncol()
: Number of columns -
nacell()
: Number ofNA
cells -
ncell()
: Number of cells -
ncell3d()
: Number of cells of a 3DGRaster
-
ndepth()
: Number of depths of a 3DGRaster
-
nlyr()
: Number of layers -
nonnacell()
: Number of non-NA
cells -
nrow()
: Number of rows -
nlevels()
: Number of categories -
res()
,res3d()
,xres()
,yres()
, andzres()
: Spatial resolution -
sources()
: Name of the raster file in the GRASS cache -
topology()
: Dimensionally (2D or 3D) -
zext()
: Vertical extent -
zres()
: Vertical resolution
Functions that operate on or create GRasters
-
Arithmetic: Mathematical operations on
GRaster
s:+
,-
,*
,/
,^
,%%
(modulus),%/%
(integer division) -
Logical comparisons:
<
,<=
,==
,!=
,>=
, and>
, plus%in%
and%notin%
(for categorical rasters only) -
Logical operators:
|
and&
Mathematical functions that are applied to each layer of a GRaster
:
Trigonometry:
sin()
,cos()
,tan()
,asin()
,acos()
,atan()
,atan2()
Logarithms and powers:
exp()
,log()
,ln()
,log1p()
,log2()
,log10()
,sqrt()
Signs:
abs()
Mathematical functions that are applied across layers of multi-layered GRaster
s:
Dispersion:
stdev()
,var()
,varpop()
,nunique()
,range()
,quantile()
,skewness()
,kurtosis()
Extremes:
min()
,max()
,which.min()
,which.max()
Subsetting, assigning, and replacing GRaster
layers
-
$,
[[
, orsubset()
: Subset or remove specific layers of aGRaster
-
[<-
: Replace values of cells of aGRaster
-
[[<-
: Replace specific layers of aGRaster
-
add<-
: Replace specific layers of aGRaster
Operations on GRaster
s
-
as.int()
,as.float()
,as.doub()
: Change data type (integer/float/double) -
as.lines()
: Convert aGRaster
to a "lines" vector -
as.points()
: Convert aGRaster
to a "points" vector -
as.polygons()
: Convert aGRaster
to a "polygons" vector -
aggregate()
: Aggregate values ofGRaster
cells into larger cells -
bioclims()
: BIOCLIM rasters (classic set and extended set) -
buffer()
: Create a buffer around non-NA
cells -
app()
: Apply a user-defined function to multiple layers of aGRaster
(with helper functionsappFuns()
andappCheck()
) -
c()
: "Stack" two or more rasters -
cellSize()
: Cell area -
classify()
: Partition cell values into strata -
clump()
: Group adjacent cells with similar values -
combineLevels()
: Combine the "levels" tables of two or more categoricalGRaster
s -
concats()
: Combine values from two or more categorical and/or integer rasters by concatenating them -
crop()
: Remove parts of aGRaster
-
denoise()
: Remove "noise" from aGRaster
using a principal components analysis (PCA) -
distance()
: Distance to non-NA
cells, or vice versa -
extend()
: Add rows and columns to aGRaster
-
extract()
: Extract values from aGRaster
at locations of aGVector
-
fillNAs()
: FillNA
cells -
focal()
: Calculate cell values based on values of nearby cells -
fragmentation()
: Landscape fragmentation class from Riitters et al. (2020) -
global()
: Summary statistics across cells of eachGRaster
layer -
hist()
: Histogram ofGRaster
values -
interpIDW()
: Interpolate values at points to aGRaster
-
kernel()
: Kernel density estimator of points -
layerCor()
: Correlation or covariance between two or moreGRaster
layers -
mask()
: Remove values in aGRaster
based on values in anotherGRaster
or vector -
maskNA()
: Mask all non-NA cells or all NA cells -
match()
,%in%
, and%notin%
: Find which cells of aGRaster
match or do not match certain values -
merge()
: Combine two or more rasters with different extents and fill inNA
s -
multivarEnvSim()
: Multivariate environmental similarity surface (MESS) -
names<-
: Assign names to aGRaster
-
noise()
: Remove coarse-scale trends from aGRaster
, leaving just fine-scale "noise" -
pairs()
: Plot correlations betweenGRaster
layers -
pcs()
: Retrieve a principal components model from a PCAGRaster
generated usingprincomp()
-
plot()
: Display aGRaster
-
project()
: Change coordinate reference system and cell size -
predict()
: Make predictions to aGRaster
from a linear model or generalized linear model -
princomp()
: Apply a principal components analysis (PCA) to aGRaster
-
regress()
: Regression intercept, slope, r2, and t-value across each set of cells -
resample()
: Change cell size -
reorient()
: Convert degrees between 'north-orientation' and 'east orientation' -
sampleRast()
: Randomly sample cells from aGRaster
-
scale()
,scalepop()
, andunscale()
: Subtract means and divide by standard deviations, or inverse of that -
selectRange()
: Select values from rasters in a stack based on values in anotherGRaster
-
spatSample()
: Randomly points from aGRaster
-
stretch()
: Rescale values in a GRaster -
subst()
: Re-assign cell values -
thinLines()
: Reduce linear features on aGRaster
so linear features are 1 cell wide -
tiles()
: Divide aGRaster
into spatially exclusive subsets (though with possible overlap) -
trim()
: Remove rows and columns from aGRaster
that are allNA
-
zonal()
: Statistics (mean, sum, etc.) on areas of aGRaster
defined by sets of cells with the same values in anotherGRaster
, or by geometries in aGVector
-
zonalGeog()
: Geographic statistics (area, perimeter, fractal dimension, etc.) for sets of cells with the same values
Creating GRaster
s de novo
-
fractalRast()
: Create a fractalGRaster
-
init()
: GRaster with values equal to row, column, coordinate, regular, or "chess" -
longlat()
: Create longitude/latitude rasters -
rNormRast()
: A randomGRaster
with values drawn from a normal distribution -
rSpatialDepRast()
: Create a randomGRaster
with or without spatial dependence -
rUnifRast()
: A randomGRaster
with values drawn from a uniform distribution -
rWalkRast()
: Paths of random walkers -
sineRast()
: Sine wave rasters
Analysis of terrain and hydrology
-
as.contour()
: Contour lines from aGRaster
-
flow()
: Identify watershed basins and direction and accumulation of flow -
flowPath()
: Path of water flow across a landscape -
geomorphons()
: Identify terrain feature types -
hillshade()
: Create a hillshadeGRaster
-
horizonHeight()
: Horizon height -
sun()
: Solar radiance and irradiance -
ruggedness()
: Terrain Ruggedness Index -
streams()
: Create stream network -
terrain()
: Slope, aspect, curvature, and partial slopes -
wetness()
: Topographic wetness index
Operations on categorical (factor) GRaster
s
-
%in%
, and%notin%
: Mask cells that match or do not match a given category -
activeCat()
andactiveCats()
: Column(s) that defines category labelsactiveCat<-
: Set column that defines category labels -
addCats()
: Add new columns to a "levels" tableaddCats<-
: Add new rows (levels) to a "levels" table -
categories()
: Set "levels" table for specific layers of a categorical raster -
catNames()
: Column names of each "levels" table -
cats()
: "Levels" table of a categorical raster -
combineLevels()
: Combine the "levels" tables of two or more categoricalGRaster
s -
complete.cases()
: Find rows of a categoricalGRaster
's "levels" table that have noNA
s in them -
concats()
: Combine categories from two or more categorical rasters by concatenating them -
droplevels()
: Remove one or more levels -
freq()
: Frequency of each category across cells of a raster -
is.factor()
: Is a raster categorical? -
levels()
: "Levels" table of a categorical raster -
levels<-
: Set "levels" table of a categorical raster -
match()
,%in%
, and%notin%
: Find which cells of aGRaster
match or do not match certain category labels -
minmax()
: "Lowest" and "highest" category values of categorical rasters (when argumentlevels = TRUE
) -
missing.cases()
: Find rows of a categoricalGRaster
's "levels" table that have at least oneNA
in them -
missingCats()
: Values that have no category assigned to them -
nlevels()
: Number of levels -
segregate()
: Create one GRaster layer per unique value in a GRaster -
subst()
: Re-assign category levels -
zonalGeog()
: Geographic statistics (area, perimeter, fractal dimension, etc.) for sets of cells with the same values
Analysis of remote sensing rasters
-
compositeRGB()
: Combine red, green, and blue color bands to make a compositeGRaster
-
plotRGB()
: Display a multispectralGRaster
using red, blue, green, and alpha channels -
vegIndex()
: Vegetation indices from surface reflectance
Functions that operate on terra SpatRaster
s
-
bioclims()
: BIOCLIM rasters (classic set and extended set) -
fragmentation()
: Landscape fragmentation class from Riitters et al. (2020)
Properties of GVector
s
-
crs()
: Coordinate reference system -
coordRef()
: Coordinate reference system -
datatype()
: Data type of fields -
dim()
: Number of geometries and columns -
expanse()
: Area of polygons or length of lines -
ext()
,N()
,S()
,E()
,W()
,top()
, andbottom()
: Spatial extent -
geomtype()
: Type of vector (points, lines, polygons) -
is.lonlat()
: Is an object projected (e.g., in WGS84)? -
is.points()
,is.lines()
,is.polygons()
: Does aGVector
represent points, lines, or polygons? -
names()
: Names ofGVector
fields -
ncol()
: Number of fields -
ngeom()
: Number of geometries (points, lines, polygons) -
nrow()
: Number of rows in a vector data table -
nsubgeom()
: Number of sub-geometries (points, lines, polygons that make up single- and multipart geometries) -
sources()
: Name of the vector file in the GRASS cache -
topology()
: Dimensionally (2D or 3D) -
zext()
: Vertical extent
Subsetting and assigning geometries or rows and columns of GVector
s
-
$<-
: Replace specific columns of aGVector
's data table or add columns -
addTable<-
: Add a data table to aGVector
-
dropTable()
: Remove aGVector
s data table
Operations on GVector
s
-
aggregate()
: CombineGVector
geometries -
as.data.frame()
: Convert aGVector
's attribute table to adata.frame
-
as.data.table()
: Convert aGVector
's attribute table to adata.table
-
as.points()
: Extract vertex coordinates from a "lines" or "polygons"GVector
-
buffer()
: Create a polygon around/inside aGVector
-
clusterPoints()
: Identify clusters of points -
centroids()
: Centroid(s) of aGVector
-
colbind()
: Add columns to the data table of aGVector
-
complete.cases()
: Find rows of aGVector
's data table that have noNA
s in them -
connectors()
: Create lines connecting nearest features of twoGVector
s -
convHull()
: Minimum convex hull -
crds()
: Extract coordinates of aGVector
-
crop()
: Remove parts of aGVector
-
delaunay()
: Delaunay triangulation -
disagg()
: Separate multipart geometries into singlepart geometries -
distance()
: Distance between geometries in twoGVector
, or from aGVector
to cells of aGRaster
-
erase()
or-
: Remove part of aGVector
that overlaps with another -
expanse()
: Area of polygons or length of lines -
extract()
: Extract values from aGVector
at specific points -
grid()
: Create a gridGVector
-
head()
: First rows of aGVector
's data table -
hexagons()
: Create a hexagonal grid -
interpIDW()
: Interpolate values at points to aGRaster
using inverse-distance weighting -
interpSplines()
: Interpolate values at points to aGRaster
using splines -
intersect()
or*
: Intersection of twoGVectors
-
kernel()
: Kernel density estimator of points -
missing.cases()
: Find rows of aGVector
's data table that have at leastNA
in them -
names<-
: Assign names to columns of aGVector
s data table -
neighborhoodMatrix()
andneighbourhoodMatrix()
: Neighborhood matrix of a polygonsGVector
-
project()
: Change coordinate reference system -
rasterize()
: Convert aGVector
to aGRaster
-
rbind()
: CombineGVectors
-
simplifyGeom()
: Remove vertices -
smoothGeom()
: Remove "angular" aspects of features -
st_as_sf()
: Convert aGVector
to asf
vector -
st_buffer()
: Create a polygon around/inside aGVector
-
tail()
: Last rows of aGVector
's data table -
thinPoints()
: Reduce number of points in same raster cell -
union()
or+
: Combine twoGVector
s -
voronoi()
: Voronoi tessellation -
xor()
or/
: Select parts of polygons not shared by twoGVector
s
Creating GVector
s de novo
-
rvoronoi()
: Random Voronoi tesselation
Fixing issues with GVector
s
(See also Details fast()
.)
-
breakPolys()
: Break topologically clean areas -
fillHoles()
: Fill "holes" of aGVector
-
fixBridges()
: Change "bridges" to "islands" -
fixDangles()
: Change "dangles" hanging off boundaries to lines -
fixLines()
: Break lines at intersections and lines that form closed loops -
remove0()
: Remove all boundaries and lines with a length of 0 -
removeAngles()
: Collapse lines that diverge at an angle that is computationally equivalent to 0 -
removeBridges()
: Remove "bridges" to "islands" -
removeDangles()
: Remove "dangling" lines -
removeDupCentroids()
: Remove duplicated area centroids -
removeDups()
: Remove duplicated features and area centroids -
removeSmallPolys()
: Remove small polygons -
snap()
: Snap lines/boundaries to each other
Converting between data types
-
as.contour()
: Convert aGRaster
to aGVector
representing contour lines -
as.doub()
: Convert aGRaster
to a double-floating point raster (GRASS data typeDCELL
) -
as.data.frame()
: ConvertGVector
to adata.frame
-
as.data.table()
: ConvertGVector
to adata.table
-
as.float()
: Convert aGRaster
to a floating-point raster (GRASS data typeFCELL
) -
as.int()
: Convert aGRaster
to an integer raster (GRASS data typeCELL
) -
as.points()
,as.lines()
, andas.polygons()
: Convert aGRaster
to aGVector
-
categories()
andlevels<-
: Convert an integer raster to a categorical ("factor") raster. -
fast()
: Convert aSpatRaster
to aGRaster
; aSpatVector
,sf
vector, numeric vector,matrix
,data.frame
, ordata.table
to aGVector
; or load a vector or raster from a file -
rast()
: Convert aGRaster
to aSpatRaster
-
rasterize()
: Convert aGVector
to aGRaster
-
st_as_sf()
: Convert aGVector
to asf
vector -
vect()
: Convert aGVector
to aSpatVector
General purpose functions
-
addons()
: Show installed GRASS addons -
compareGeom()
: Determine if geographic metadata is same betweenGRaster
s and/orGVector
s -
dropRows()
: Remove rows from adata.frame
ordata.table
-
grassGUI()
: Start the GRASS GUI (not recommended for most users!!!) -
grassHelp()
: Open the help page for a GRASS tool. -
grassInfo()
: GRASS version and citation -
grassStarted()
: Has a connection GRASS been made within the current R session? -
installAddon()
: Install a GRASS addon -
mow()
: Remove unused rasters and vectors from the GRASS cache -
reorient()
: Convert degrees between 'north-orientation' and 'east orientation' -
replaceNAs()
: ReplaceNA
s in columns of adata.table
ordata.frame
, or in a vector -
removeAddon()
: Delete GRASS addon from your system -
seqToSQL()
: Format a numeric series into an SQL value call -
update()
: Refresh metadata in aGRaster
orGVector
object
Data objects
-
fastData()
: Helper function to quickly obtain example rasters and vectors -
appFunsTable (see also
appFuns()
): Functions usable by theapp()
function -
madChelsa: Climate rasters for of a portion of eastern Madagascar
-
madCoast0, madCoast4, and madCoast: Borders of an eastern portion of Madagascar
-
madCover: Land cover raster
-
madCoverCats: Table of land cover classes
-
madDypsis: Specimens records of species in the genus Dypsis
-
madElev: Elevation raster
-
madForest2000 and madForest2014: Forest cover in 2000 and 2014
-
madLANDSAT: Surface reflectance in 2023
-
madPpt, madTmin, madTmax: Rasters of mean monthly precipitation, and minimum and maximum temperature
-
madRivers: Rivers vector
-
vegIndices: Vegetation indices that can be calculated using
vegIndex()
Esoteric tutorials and arcane notes
Comparisons between
GRegion
s can be performed using the==
and!=
operators.Vignette on GRASS "projects/locations" and "mapsets":
vignette("projects_mapsets", package = "fasterRaster")
Vignette on GRASS "regions":
vignette("regions", package = "fasterRaster")
Vignette on GRASS 3-dimensional
GRaster
s andGVector
s:vignette("three_d_objects", package = "fasterRaster")
Vignette on fasterRaster hidden functions:
vignette("hidden_functions", package = "fasterRaster")
Classes
-
GLocation
: Fundamental class; points to a "location/project" in GRASS -
GSpatial
: Basic class of any spatial object -
GRegion
: Points to a "region" of a "location/project" in GRASS -
GRaster
: Raster class -
GVector
: Spatial vector class
Author(s)
Adam B. Smith
See Also
Useful links:
Report bugs at https://github.com/adamlilith/fasterRaster/issues