"fasterRaster": Faster raster and spatial vector processing using "GRASS GIS"
Source:R/fasterRaster.r
fasterRaster.Rd
fasterRaster: Processing of large-in-memory/-on disk rasters and spatial vectors in using GRASS GIS. 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 GIS 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:
A quick-start tutorial
A tutorial on raster data typesfaster()
: Set the directory where GRASS is installed on your system, and set or get other package-wide optionsfast()
: Convert a SpatRaster
, SpatVector
, or sf
vector to fasterRaster's raster format (GRaster
s) or vector format (GVector
s), or load one from a filerast()
, vect()
, and st_as_sf()
: Convert GRaster
s and GVector
s to SpatRaster
s, SpatVector
s, or sf
vectorswriteRaster()
and writeVector()
: Save GRaster
s or GVector
s to disk
Properties of GRasters
crs()
: Coordinate reference systemdatatype()
: Data typedim()
and dim3d()
: Number of rows, columns, and depthsext()
, N()
, S()
, E()
, W()
, top()
, and bottom()
: Spatial extentfreq()
: Frequencies of cell values in a rasteris.2d()
and is.3d()
: Is an object 2- or 3-dimensional?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 categorical GRaster
minmax()
: Minimum and maximum values across all non-NA
cellsnames()
: GRaster
namesncol()
: Number of columnsnacell()
: Number of NA
cellsncell()
: Number of cellsncell3d()
: Number of cells of a 3D GRaster
ndepth()
: Number of depths of a 3D GRaster
nlyr()
: Number of layersnonnacell()
: Number of non-NA
cellsnrow()
: Number of rowsnlevels()
: Number of categoriesres()
, xres()
, yres()
, and zres()
: Spatial resolutionsources()
: Name of the GRaster
in GRASStopology()
: Dimensionality (2D or 3D)zext()
: Vertical extentzres()
: 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 &
Single-layer mathematical functions (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()
Multi-layer functions (applied across layers of a "stack" of GRaster
s):
Dispersion:
stdev()
,var()
,varpop()
,nunique()
,range()
,quantile()
,skewness()
,kurtosis()
Extremes:
min()
,max()
,which.min()
,which.max()
The operators $ and [[
can be used to subset or remove specific layers of a GRaster
.
The [<-
operator can be used to replace values of cells of a GRaster
.
The assign operators, $<-
, [[<-
, and add<-
can be used to replace specific layers of a GRaster
.as.int()
, as.float()
, as.doub()
: Change data type (integer/float/double)as.lines()
: Convert a GRaster
to a "lines" vectoras.points()
: Convert a GRaster
to a "points" vectoras.polygons()
: Convert a GRaster
to a "polygons" vectoraggregate()
: Aggregate values of GRaster
cells into larger cellsbioclims()
: BIOCLIM rasters (classic set and extended set)buffer()
: Create a buffer around non-NA
cellsapp()
: Apply a user-defined function to multiple layers of a GRaster
(with helper functions appFuns()
and appCheck()
)c()
: "Stack" two or more rasterscellSize()
: Cell areaclassify()
: Partition cell values into strataclump()
: Group adjacent cells with similar valuescombineCats()
: Combine values from two or more categorical and/or integer rasterscombineLevels()
: Combine the "levels" tables of two or more categorical GRaster
scrop()
: Remove parts of a GRaster
denoise()
: Remove "noise" from a GRaster
using a principal components analysis (PCA)distance()
: Distance to non-NA
cells, or vice versaextend()
: Add rows and columns to a GRaster
extract()
: Extract values from a GRaster
at locations of a GVector
fillNAs()
: Fill NA
cellsfocal()
: Calculate cell values based on values of nearby cellsfragmentation()
: Landscape fragmentation class from Riitters et al. (2020)global()
: Summary statistics across cells of each GRaster
layerhist()
: Histogram of GRaster
valuesinterpIDW()
: Interpolate values at points to a GRaster
kernel()
: Kernel density estimator of pointslayerCor()
: Correlation or covariance between two or more GRaster
layerslonglat()
: Create longitude/latitude rastersmask()
: Remove values in a GRaster
based on values in another GRaster
or vectormaskNA()
: Mask all non-NA cells or all NA cellsmatch()
, %in%
, and %notin%
: Find which cells of a GRaster
match or do not match certain valuesmerge()
: Combine two or more rasters with different extents and fill in NA
snames<-
: Assign names to a GRaster
noise()
: Remove coarse-scale trends from a GRaster
, leaving just fine-scale "noise"pairs()
: Plot correlations between GRaster
layerspca()
: Apply a principal components analysis (PCA) to a GRaster
pcs()
: Retrieve a principal components model from a PCA GRaster
generated using pca()
plot()
: Display a GRaster
plotRGB()
: Display a multispectral GRaster
using red, blue, green, and alpha channelsproject()
: Change coordinate reference system and cell sizepredict()
: Make predictions to a GRaster
from a linear model or generalized linear modelresample()
: Change cell sizereorient()
: Convert degrees between 'north-orientation' and 'east orientation'scale()
, scalepop()
, and unscale()
: Subtract means and divide by standard deviations, or inverse of thatselectRange()
: Select values from rasters in a stack based on values in another GRaster
spatSample()
: Randomly points from a GRaster
subst()
: Re-assign cell valuesthinLines()
: Reduce linear features on a GRaster
so linear features are 1 cell widetiles()
: Divide a GRaster
into spatially exclusive subsets (though with possible overlap)trim()
: Remove rows and columns from a GRaster
that are all NA
zonal()
: Statistics (mean, sum, etc.) on areas of a GRaster
defined by sets of cells with the same values in another GRaster
, or by geometries in a GVector
zonalGeog()
: Geographic statistics (area, perimeter, fractal dimension, etc.) for sets of cells with the same values
Functions for creating GRaster
s de novo
fractalRast()
: Create a fractal GRaster
rnormRast()
: A random GRaster
with values drawn from a normal distributionrSpatialDepRast()
: Create a random GRaster
with or without spatial dependencerunifRast()
: A random GRaster
with values drawn from a uniform distributionsineRast()
: Sine wave rasters
Functions for analysis of terrain and flow of water across landscapes
as.contour()
: Contour lines from a GRaster
flow()
: Identify watershed basins and direction and accumulation of flowflowPath()
: Path of water flow across a landscapegeomorphons()
: Identify terrain feature typeshillshade()
: Create a hillshade GRaster
horizonHeight()
: Horizon heightsun()
: Solar radiance and irradianceruggedness()
: Terrain Ruggedness Indexstreams()
: Create stream networkterrain()
: Slope, aspect, curvature, and partial slopeswetness()
: Topographic wetness index
Functions operating on categorical (factor) rasters
%in%
, and %notin%
: Mask cells that match or do not match a given categoryactiveCat()
and activeCats()
: Column(s) that defines category labelsactiveCat<-
: Set column that defines category labelsaddCats()
: Add new columns to a "levels" tableaddCats<-
: Add new rows (levels) to a "levels" tablecategories()
: Set "levels" table for specific layers of a categorical rastercatNames()
: Column names of each "levels" tablecats()
: "Levels" table of a categorical rastercombineCats()
: Combine categories from two or more categorical rasterscombineLevels()
: Combine the "levels" tables of two or more categorical GRaster
scomplete.cases()
: Find rows of a categorical GRaster
's "levels" table that have no NA
s in themdroplevels()
: Remove one or more levelsfreq()
: Frequency of each category across cells of a rasteris.factor()
: Is a raster categorical?levels()
: "Levels" table of a categorical rasterlevels<-
: Set "levels" table of a categorical rastermatch()
, %in%
, and %notin%
: Find which cells of a GRaster
match or do not match certain category labelsminmax()
: "Lowest" and "highest" category values of categorical rasters (when argument levels = TRUE
)missing.cases()
: Find rows of a categorical GRaster
's "levels" table that have at least one NA
in themmissingCats()
: Values that have no category assigned to themnlevels()
: Number of levelssubst()
: Re-assign category levelszonalGeog()
: Geographic statistics (area, perimeter, fractal dimension, etc.) for sets of cells with the same values
Functions for analysis of remote sensing rasters
compositeRGB()
: Combine red, green, and blue color bands to make a composite GRaster
plotRGB()
: Display a multispectral GRaster
using red, blue, green, and alpha channelsvegIndex()
: 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 systemdatatype()
: Data type of fieldsdim()
: Number of geometries and columnsexpanse()
: Area of polygons or length of linesext()
, N()
, S()
, E()
, W()
, top()
, and bottom()
: Spatial extentgeomtype()
: Type of vector (points, lines, polygons)is.2d()
and is.3d()
: Is an object 2- or 3-dimensional?is.lonlat()
: Is an object projected (e.g., in WGS84)?is.points()
, is.lines()
, is.polygons()
: Does a GVector
represent points, lines, or polygons?names()
: Names of GVector
fieldsncol()
: Number of fieldsngeom()
: Number of geometries (points, lines, polygons)nrow()
: Number of rows in a vector data tablensubgeom()
: Number of subgeometries (points, lines, polygons that make up single- and multipart geometries)sources()
: Name of the vector in GRASStopology()
: Dimensionality (2D or 3D)zext()
: Vertical extent
Functions that operate on or create GVector
s
The [
operator can be used to subset geometries of a GVector
.
The $ and [[
operators can be used to get columns of a GVector
's data table.
The $<-
operator can be used to replace specific columns of a GVector
's data table or to add columns.addTable<-
: Add a data table to a GVector
aggregate()
: Combine GVector
geometriesas.data.frame()
: Convert a GVector
's attribute table to a data.frame
as.data.table()
: Convert a GVector
's attribute table to a data.table
as.points()
: Extract vertex coordinates from a "lines" or "polygons" GVector
buffer()
: Create a polygon around/inside a GVector
clusterPoints()
: Identify clusters of pointscolbind()
: Add columns to the data table of a GVector
complete.cases()
: Find rows of a GVector
's data table that have no NA
s in themconnectors()
: Create lines connecting nearest features of two GVector
sconvHull()
: Minimum convex hullcrds()
: Extract coordinates of a GVector
crop()
: Remove parts of a GVector
delaunay()
: Delaunay triangulationdisagg()
: Separate multipart geometries into singlepart geometriesdistance()
: Distance between geometries in two GVector
, or from a GVector
to cells of a GRaster
dropTable()
: Remove the data table from a GVector
erase()
or -
: Remove part of a GVector
that overlaps with anotherexpanse()
: Area of polygons or length of linesextract()
: Extract values from a GVector
at specific pointsgrid()
: Create a grid GVector
head()
: First rows of a GVector
's data tablehexagons()
: Create a hexagonal gridinterpIDW()
: Interpolate values at points to a GRaster
using inverse-distance weightinginterpSplines()
: Interpolate values at points to a GRaster
using splinesintersect()
or *
: Intersection of two GVectors
.kernel()
: Kernel density estimator of points.missing.cases()
: Find rows of a GVector
's data table that have at least NA
in themnames<-
: Assign names to columns of a GVector
s data tableproject()
: Change coordinate reference systemrasterize()
: Convert a GVector
to a GRaster
rbind()
: Combine GVectors
simplifyGeom()
: Remove verticessmoothGeom()
: Remove "angular" aspects of featuresst_as_sf()
: Convert a GVector
to a sf
vectorst_buffer()
: Create a polygon around/inside a GVector
tail()
: Last rows of a GVector
's data tablethinPoints()
: Reduce number of points in same raster cellunion()
or +
: Combine two GVector
sxor()
or /``: Select parts of polygons not shared by two
GVector`s
Functions for fixing issues with GVector
s
(See also tools that can be used during GVector
creation/loading in fast()
.)
breakPolys()
: Break topologically clean areasfillHoles()
: Fill "holes" of a GVector
fixBridges()
: Change "bridges" to "islands"fixDangles()
: Change "dangles" hanging off boundaries to linesfixLines()
: Break lines at intersections and lines that form closed loopsremove0()
: Remove all boundaries and lines with a length of 0removeAngles()
: Collapse lines that diverge at an angle that is computationally equivalent to 0removeBridges()
: Remove "bridges" to "islands"removeDangles()
: Remove "dangling" linesremoveDupCentroids()
: Remove duplicated area centroidsremoveDups()
: Remove duplicated features and area centroidsremoveSmallPolys()
: Remove small polygonssnap()
: Snap lines/boundaries to each other
Converting between data types
as.contour()
: Convert a GRaster
to a GVector
representing contour linesas.doub()
: Convert a GRaster
to a double-floating point raster (GRASS data type DCELL
)as.data.frame()
: Convert GVector
to a data.frame
as.data.table()
: Convert GVector
to a data.table
as.float()
: Convert a GRaster
to a floating-point raster (GRASS data type FCELL
)as.int()
: Convert a GRaster
to an integer raster (GRASS data type CELL
)as.points()
, as.lines()
, and as.polygons()
: Convert a GRaster
to a GVector
fast()
: Convert a SpatRaster
to a GRaster
; a SpatVector
, sf
vector, numeric vector, matrix
, data.frame
, or data.table
to a GVector
; or load a vector or raster from a filecategories()
and levels<-: Convert an integer raster to a categorical ("factor") raster.
rast()
: Convert a GRaster
to a SpatRaster
rasterize()
: Convert a GVector
to a GRaster
st_as_sf()
: Convert a GVector
to a sf
vectorvect()
: Convert a GVector
to a SpatVector
General purpose functions
compareGeom()
: Determine if geographic metadata is same between GRaster
s and/or GVector
sdropRows()
: Remove rows from a data.frame
or data.table
grassInfo()
: GRASS version and citationmow()
: Remove unused rasters and vectors from the GRASS cachereorient()
: Convert degrees between 'north-orientation' and 'east orientation'replaceNAs()
: Replace NA
s in columns of a data.table
or data.frame
, or in a vectorseqToSQL()
: Format a numeric series into an SQL value callupdate()
: Refresh metadata in a GRaster
or GVector
object
Data objects
appFunsTable (see also appFuns()
): Functions usable by the app()
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.
Tutorial on GRASS regions
Tutorial on GRASS projects/locations and mapsets
Hidden functions of fasterRaster: Useful for power users and developersgrassStarted()
: Has a connection GRASS been made within the current R session?