Skip to contents

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:

Properties of GRasters

Functions that operate on or create GRasters

Mathematical functions that are applied to each layer of a GRaster:

Mathematical functions that are applied across layers of multi-layered GRasters:

Subsetting, assigning, and replacing GRaster layers

  • $, [[, or subset(): Subset or remove specific layers of a GRaster

  • [<-: Replace values of cells of a GRaster

  • [[<-: Replace specific layers of a GRaster

  • add<-: Replace specific layers of a GRaster

Operations on GRasters

  • as.int(), as.float(), as.doub(): Change data type (integer/float/double)

  • as.lines(): Convert a GRaster to a "lines" vector

  • as.points(): Convert a GRaster to a "points" vector

  • as.polygons(): Convert a GRaster to a "polygons" vector

  • aggregate(): Aggregate values of GRaster 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 a GRaster (with helper functions appFuns() and appCheck())

  • 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 categorical GRasters

  • concats(): Combine values from two or more categorical and/or integer rasters by concatenating them

  • crop(): 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 versa

  • extend(): Add rows and columns to a GRaster

  • extract(): Extract values from a GRaster at locations of a GVector

  • fillNAs(): Fill NA 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 each GRaster layer

  • hist(): Histogram of GRaster values

  • interpIDW(): Interpolate values at points to a GRaster

  • kernel(): Kernel density estimator of points

  • layerCor(): Correlation or covariance between two or more GRaster layers

  • mask(): Remove values in a GRaster based on values in another GRaster or vector

  • maskNA(): Mask all non-NA cells or all NA cells

  • match(), %in%, and %notin%: Find which cells of a GRaster match or do not match certain values

  • merge(): Combine two or more rasters with different extents and fill in NAs

  • names<-: Assign names to a GRaster

  • noise(): Remove coarse-scale trends from a GRaster, leaving just fine-scale "noise"

  • pairs(): Plot correlations between GRaster layers

  • pcs(): Retrieve a principal components model from a PCA GRaster generated using princomp()

  • plot(): Display a GRaster

  • project(): Change coordinate reference system and cell size

  • predict(): Make predictions to a GRaster from a linear model or generalized linear model

  • princomp(): Apply a principal components analysis (PCA) to a GRaster

  • 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 a GRaster

  • scale(), scalepop(), and unscale(): Subtract means and divide by standard deviations, or inverse of that

  • selectRange(): Select values from rasters in a stack based on values in another GRaster

  • spatSample(): Randomly points from a GRaster

  • stretch(): Rescale values in a GRaster

  • subst(): Re-assign cell values

  • thinLines(): Reduce linear features on a GRaster so linear features are 1 cell wide

  • tiles(): 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

Creating GRasters de novo

  • fractalRast(): Create a fractal GRaster

  • init(): GRaster with values equal to row, column, coordinate, regular, or "chess"

  • longlat(): Create longitude/latitude rasters

  • rnormRast(): A random GRaster with values drawn from a normal distribution

  • rSpatialDepRast(): Create a random GRaster with or without spatial dependence

  • runifRast(): A random GRaster with values drawn from a uniform distribution

  • sineRast(): Sine wave rasters

Analysis of terrain and hydrology

Operations on categorical (factor) GRasters

  • %in%, and %notin%: Mask cells that match or do not match a given category

  • activeCat() and activeCats(): Column(s) that defines category labels activeCat<-: Set column that defines category labels

  • addCats(): Add new columns to a "levels" table addCats<-: 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 categorical GRasters

  • complete.cases(): Find rows of a categorical GRaster's "levels" table that have no NAs 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 a GRaster match or do not match certain category labels

  • minmax(): "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 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 composite GRaster

  • plotRGB(): Display a multispectral GRaster using red, blue, green, and alpha channels

  • vegIndex(): Vegetation indices from surface reflectance

Functions that operate on terra SpatRasters

  • bioclims(): BIOCLIM rasters (classic set and extended set)

  • fragmentation(): Landscape fragmentation class from Riitters et al. (2020)

Properties of GVectors

Subsetting and assigning geometries or rows and columns of GVectors

  • $ or [[: Subset columns of a GVector's data table

  • [ or subset(): Subset geometries of a GVector

  • $<-: Replace specific columns of a GVector's data table or add columns

  • addTable<-: Add a data table to a GVector

  • dropTable(): Remove a GVectors data table

Operations on GVectors

  • aggregate(): Combine GVector geometries

  • as.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 points

  • centroids(): Centroid(s) of a GVector

  • colbind(): Add columns to the data table of a GVector

  • complete.cases(): Find rows of a GVector's data table that have no NAs in them

  • connectors(): Create lines connecting nearest features of two GVectors

  • convHull(): Minimum convex hull

  • crds(): Extract coordinates of a GVector

  • crop(): Remove parts of a GVector

  • delaunay(): Delaunay triangulation

  • disagg(): Separate multipart geometries into singlepart geometries

  • distance(): Distance between geometries in two GVector, or from a GVector to cells of a GRaster

  • erase() or -: Remove part of a GVector that overlaps with another

  • expanse(): Area of polygons or length of lines

  • extract(): Extract values from a GVector at specific points

  • grid(): Create a grid GVector

  • head(): First rows of a GVector's data table

  • hexagons(): Create a hexagonal grid

  • interpIDW(): Interpolate values at points to a GRaster using inverse-distance weighting

  • interpSplines(): Interpolate values at points to a GRaster using splines

  • intersect() 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 them

  • names<-: Assign names to columns of a GVectors data table

  • project(): Change coordinate reference system

  • rasterize(): Convert a GVector to a GRaster

  • rbind(): Combine GVectors

  • simplifyGeom(): Remove vertices

  • smoothGeom(): Remove "angular" aspects of features

  • st_as_sf(): Convert a GVector to a sf vector

  • st_buffer(): Create a polygon around/inside a GVector

  • tail(): Last rows of a GVector's data table

  • thinPoints(): Reduce number of points in same raster cell

  • union() or +: Combine two GVectors

  • voronoi(): Voronoi tessellation

  • xor() or /: Select parts of polygons not shared by two GVectors

Creating GVectors de novo

Fixing issues with GVectors

(See also Details fast().)

Converting between data types

  • as.contour(): Convert a GRaster to a GVector representing contour lines

  • as.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

  • categories() and levels<-: Convert an integer raster to a categorical ("factor") raster.

  • 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 file

  • rast(): Convert a GRaster to a SpatRaster

  • rasterize(): Convert a GVector to a GRaster

  • st_as_sf(): Convert a GVector to a sf vector

  • vect(): Convert a GVector to a SpatVector

General purpose functions

  • compareGeom(): Determine if geographic metadata is same between GRasters and/or GVectors

  • dropRows(): Remove rows from a data.frame or data.table

  • grassGUI(): Start the GRASS GUI (not recommended for most users!!!)

  • grassHelp(): Open the help page for a GRASS module.

  • grassInfo(): GRASS version and citation

  • grassStarted(): Has a connection GRASS been made within the current R session?

  • mow(): Remove unused rasters and vectors from the GRASS cache

  • reorient(): Convert degrees between 'north-orientation' and 'east orientation'

  • replaceNAs(): Replace NAs in columns of a data.table or data.frame, or in a vector

  • seqToSQL(): Format a numeric series into an SQL value call

  • update(): Refresh metadata in a GRaster or GVector object

Data objects

Esoteric tutorials and arcane notes

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

Adam B. Smith