
"fasterRaster": Faster raster and spatial vector processing using "GRASS"
Source:R/fasterRaster.r
fasterRaster.RdfasterRaster: 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
GRasters: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, orsfvector to fasterRaster's raster format (GRasters) or vector format (GVectors), or load one from a filerast(),vect(), andst_as_sf(): ConvertGRasters andGVectors toSpatRasters,SpatVectors, orsfvectorswriteRaster()andwriteVector(): SaveGRasters orGVectors to disk
Properties of GRasters
crs(): Coordinate reference systemcoordRef(): Coordinate reference systemdatatype(): Data typeext(),N(),S(),E(),W(),top(), andbottom(): Spatial extentfreq(): Frequencies of cell values in a rasteris.int(),is.cell(),is.float(),is.doub():GRasterdata 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 categoricalGRasterminmax(): Minimum and maximum values across all non-NAcellsnames():GRasternamesncol(): Number of columnsnacell(): Number ofNAcellsncell(): Number of cellsncell3d(): Number of cells of a 3DGRasterndepth(): Number of depths of a 3DGRasternlyr(): Number of layersnonnacell(): Number of non-NAcellsnrow(): Number of rowsnlevels(): Number of categoriesres(),res3d(),xres(),yres(), andzres(): Spatial resolutionsources(): Name of the raster file in the GRASS cachetopology(): Dimensionally (2D or 3D)zext(): Vertical extentzres(): Vertical resolution
Functions that operate on or create GRasters
Arithmetic: Mathematical operations on
GRasters:+,-,*,/,^,%%(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 GRasters:
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 aGRasteradd<-: Replace specific layers of aGRaster
Operations on GRasters
as.int(),as.float(),as.doub(): Change data type (integer/float/double)as.lines(): Convert aGRasterto a "lines" vectoras.points(): Convert aGRasterto a "points" vectoras.polygons(): Convert aGRasterto a "polygons" vectoraggregate(): Aggregate values ofGRastercells into larger cellsbioclims(): BIOCLIM rasters (classic set and extended set)buffer(): Create a buffer around non-NAcellsapp(): Apply a user-defined function to multiple layers of aGRaster(with helper functionsappFuns()andappCheck())c(): "Stack" two or more rasterscellSize(): Cell areaclassify(): Partition cell values into strataclump(): Group adjacent cells with similar valuescombineLevels(): Combine the "levels" tables of two or more categoricalGRastersconcats(): Combine values from two or more categorical and/or integer rasters by concatenating themcrop(): Remove parts of aGRasterdenoise(): Remove "noise" from aGRasterusing a principal components analysis (PCA)distance(): Distance to non-NAcells, or vice versaextend(): Add rows and columns to aGRasterextract(): Extract values from aGRasterat locations of aGVectorfillNAs(): FillNAcellsfocal(): Calculate cell values based on values of nearby cellsfragmentation(): Landscape fragmentation class from Riitters et al. (2020)global(): Summary statistics across cells of eachGRasterlayerhist(): Histogram ofGRastervaluesinterpIDW(): Interpolate values at points to aGRasterkernel(): Kernel density estimator of pointslayerCor(): Correlation or covariance between two or moreGRasterlayersmask(): Remove values in aGRasterbased on values in anotherGRasteror vectormaskNA(): Mask all non-NA cells or all NA cellsmatch(),%in%, and%notin%: Find which cells of aGRastermatch or do not match certain valuesmerge(): Combine two or more rasters with different extents and fill inNAsmultivarEnvSim(): Multivariate environmental similarity surface (MESS)names<-: Assign names to aGRasternoise(): Remove coarse-scale trends from aGRaster, leaving just fine-scale "noise"pairs(): Plot correlations betweenGRasterlayerspcs(): Retrieve a principal components model from a PCAGRastergenerated usingprincomp()plot(): Display aGRasterproject(): Change coordinate reference system and cell sizepredict(): Make predictions to aGRasterfrom a linear model or generalized linear modelprincomp(): Apply a principal components analysis (PCA) to aGRasterregress(): Regression intercept, slope, r2, and t-value across each set of cellsresample(): Change cell sizereorient(): Convert degrees between 'north-orientation' and 'east orientation'sampleRast(): Randomly sample cells from aGRasterscale(),scalepop(), andunscale(): Subtract means and divide by standard deviations, or inverse of thatselectRange(): Select values from rasters in a stack based on values in anotherGRasterspatSample(): Randomly points from aGRasterstretch(): Rescale values in a GRastersubst(): Re-assign cell valuesthinLines(): Reduce linear features on aGRasterso linear features are 1 cell widetiles(): Divide aGRasterinto spatially exclusive subsets (though with possible overlap)trim(): Remove rows and columns from aGRasterthat are allNAzonal(): Statistics (mean, sum, etc.) on areas of aGRasterdefined by sets of cells with the same values in anotherGRaster, or by geometries in aGVectorzonalGeog(): Geographic statistics (area, perimeter, fractal dimension, etc.) for sets of cells with the same values
Creating GRasters de novo
fractalRast(): Create a fractalGRasterinit(): GRaster with values equal to row, column, coordinate, regular, or "chess"longlat(): Create longitude/latitude rastersrNormRast(): A randomGRasterwith values drawn from a normal distributionrSpatialDepRast(): Create a randomGRasterwith or without spatial dependencerUnifRast(): A randomGRasterwith values drawn from a uniform distributionrWalkRast(): Paths of random walkerssineRast(): Sine wave rasters
Analysis of terrain and hydrology
as.contour(): Contour lines from aGRasterflow(): Identify watershed basins and direction and accumulation of flowflowPath(): Path of water flow across a landscapegeomorphons(): Identify terrain feature typeshillshade(): Create a hillshadeGRasterhorizonHeight(): Horizon heightsun(): Solar radiance and irradianceruggedness(): Terrain Ruggedness Indexstreams(): Create stream networkterrain(): Slope, aspect, curvature, and partial slopeswetness(): Topographic wetness index
Operations on categorical (factor) GRasters
%in%, and%notin%: Mask cells that match or do not match a given categoryactiveCat()andactiveCats(): 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 rastercombineLevels(): Combine the "levels" tables of two or more categoricalGRasterscomplete.cases(): Find rows of a categoricalGRaster's "levels" table that have noNAs in themconcats(): Combine categories from two or more categorical rasters by concatenating 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 aGRastermatch or do not match certain category labelsminmax(): "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 oneNAin themmissingCats(): Values that have no category assigned to themnlevels(): Number of levelssegregate(): Create one GRaster layer per unique value in a GRastersubst(): Re-assign category levelszonalGeog(): 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 compositeGRasterplotRGB(): Display a multispectralGRasterusing red, blue, green, and alpha channelsvegIndex(): 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
crs(): Coordinate reference systemcoordRef(): Coordinate reference systemdatatype(): Data type of fieldsdim(): Number of geometries and columnsexpanse(): Area of polygons or length of linesext(),N(),S(),E(),W(),top(), andbottom(): Spatial extentgeomtype(): Type of vector (points, lines, polygons)is.lonlat(): Is an object projected (e.g., in WGS84)?is.points(),is.lines(),is.polygons(): Does aGVectorrepresent points, lines, or polygons?names(): Names ofGVectorfieldsncol(): Number of fieldsngeom(): Number of geometries (points, lines, polygons)nrow(): Number of rows in a vector data tablensubgeom(): Number of sub-geometries (points, lines, polygons that make up single- and multipart geometries)sources(): Name of the vector file in the GRASS cachetopology(): Dimensionally (2D or 3D)zext(): Vertical extent
Subsetting and assigning geometries or rows and columns of GVectors
$<-: Replace specific columns of aGVector's data table or add columnsaddTable<-: Add a data table to aGVectordropTable(): Remove aGVectors data table
Operations on GVectors
aggregate(): CombineGVectorgeometriesas.data.frame(): Convert aGVector's attribute table to adata.frameas.data.table(): Convert aGVector's attribute table to adata.tableas.points(): Extract vertex coordinates from a "lines" or "polygons"GVectorbuffer(): Create a polygon around/inside aGVectorclusterPoints(): Identify clusters of pointscentroids(): Centroid(s) of aGVectorcolbind(): Add columns to the data table of aGVectorcomplete.cases(): Find rows of aGVector's data table that have noNAs in themconnectors(): Create lines connecting nearest features of twoGVectorsconvHull(): Minimum convex hullcrds(): Extract coordinates of aGVectorcrop(): Remove parts of aGVectordelaunay(): Delaunay triangulationdisagg(): Separate multipart geometries into singlepart geometriesdistance(): Distance between geometries in twoGVector, or from aGVectorto cells of aGRastererase()or-: Remove part of aGVectorthat overlaps with anotherexpanse(): Area of polygons or length of linesextract(): Extract values from aGVectorat specific pointsgrid(): Create a gridGVectorhead(): First rows of aGVector's data tablehexagons(): Create a hexagonal gridinterpIDW(): Interpolate values at points to aGRasterusing inverse-distance weightinginterpSplines(): Interpolate values at points to aGRasterusing splinesintersect()or*: Intersection of twoGVectorskernel(): Kernel density estimator of pointsmissing.cases(): Find rows of aGVector's data table that have at leastNAin themnames<-: Assign names to columns of aGVectors data tableneighborhoodMatrix()andneighbourhoodMatrix(): Neighborhood matrix of a polygonsGVectorproject(): Change coordinate reference systemrasterize(): Convert aGVectorto aGRasterrbind(): CombineGVectorssimplifyGeom(): Remove verticessmoothGeom(): Remove "angular" aspects of featuresst_as_sf(): Convert aGVectorto asfvectorst_buffer(): Create a polygon around/inside aGVectortail(): Last rows of aGVector's data tablethinPoints(): Reduce number of points in same raster cellunion()or+: Combine twoGVectorsvoronoi(): Voronoi tessellationxor()or/: Select parts of polygons not shared by twoGVectors
Creating GVectors de novo
rvoronoi(): Random Voronoi tesselation
Fixing issues with GVectors
(See also Details fast().)
breakPolys(): Break topologically clean areasfillHoles(): Fill "holes" of aGVectorfixBridges(): 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 aGRasterto aGVectorrepresenting contour linesas.doub(): Convert aGRasterto a double-floating point raster (GRASS data typeDCELL)as.data.frame(): ConvertGVectorto adata.frameas.data.table(): ConvertGVectorto adata.tableas.float(): Convert aGRasterto a floating-point raster (GRASS data typeFCELL)as.int(): Convert aGRasterto an integer raster (GRASS data typeCELL)as.points(),as.lines(), andas.polygons(): Convert aGRasterto aGVectorcategories()andlevels<-: Convert an integer raster to a categorical ("factor") raster.fast(): Convert aSpatRasterto aGRaster; aSpatVector,sfvector, numeric vector,matrix,data.frame, ordata.tableto aGVector; or load a vector or raster from a filerast(): Convert aGRasterto aSpatRasterrasterize(): Convert aGVectorto aGRasterst_as_sf(): Convert aGVectorto asfvectorvect(): Convert aGVectorto aSpatVector
General purpose functions
addons(): Show installed GRASS addonscompareGeom(): Determine if geographic metadata is same betweenGRasters and/orGVectorsdropRows(): Remove rows from adata.frameordata.tablegrassGUI(): Start the GRASS GUI (not recommended for most users!!!)grassHelp(): Open the help page for a GRASS tool.grassInfo(): GRASS version and citationgrassStarted(): Has a connection GRASS been made within the current R session?installAddon(): Install a GRASS addonmow(): Remove unused rasters and vectors from the GRASS cachereorient(): Convert degrees between 'north-orientation' and 'east orientation'replaceNAs(): ReplaceNAs in columns of adata.tableordata.frame, or in a vectorremoveAddon(): Delete GRASS addon from your systemseqToSQL(): Format a numeric series into an SQL value callupdate(): Refresh metadata in aGRasterorGVectorobject
Data objects
fastData(): Helper function to quickly obtain example rasters and vectorsappFunsTable (see also
appFuns()): Functions usable by theapp()functionmadChelsa: 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
GRegions 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
GRasters andGVectors:vignette("three_d_objects", package = "fasterRaster")Vignette on fasterRaster hidden functions:
vignette("hidden_functions", package = "fasterRaster")