Skip to contents

fasterRaster GRasters can represent double-floating point numeric values, integers, or categorical/factor data.

Double-floating point value

Double-floating point values are accurate to about the 15th to 17th decimal place. These are called “double” rasters in fasterRaster and DCELL rasters in GRASS. These rasters typically take the most memory. All numeric values in R are double-floating point values.

Floating point value

Less common that double-floating point rasters, floating point rasters are accurate to about the 7th decimal place. These are called “float” rasters in fasterRaster and FCELL rasters in GRASS. These rasters typically take less memory than double-floating point rasters.

Integer

Rasters that represent integers are called “integer” rasters in fasterRaster and CELL rasters in GRASS. You can force a raster to be an integer using as.int(). Some of the functions in app() function will also return integer-type rasters. Integer rasters typically take the least memory.

Categorical/factor

Categorical rasters (also called “factor” rasters) are actually integer rasters, but have an associated attribute table that maps each integer value to a category label, such as “wetland” or “forest”. The table has at least two columns. The first is integer values, and (by default) the second is category names. This second column is the “active” category column that is used for plotting and in some functions. The active column can be changed using activeCat<-.

Functions relevant to raster data types

Any type of GRaster

Categorical GRasters

  • activeCat(), activeCats(), and activeCat<- can be used to see or assign which column in a “levels” table associated with a categorical raster is used as category labels.
  • addCats() adds information to the “levels” table using data.table::merge() (same as merge()).
  • addCats<- add new levels to a “levels” table.
  • catNames() reports the column names of the “levels” table of each layer of a raster.
  • cats() returns the entire “levels” table of a categorical raster.
  • combineLevels(): Combine the “levels” tables of two or more categorical GRasters.
  • complete.cases() finds rows in the levels table that have no NAs.
  • concats() combines levels of two or more categorical or integer rasters by concatenating them.
  • droplevels() removes “unused” levels in a “levels” table.
  • levels() returns the “levels” table of a categorical raster (just the value column and the active column).
  • levels<- and categories() can be used to assign categories to an integer raster and make it categorical (i.e., a “factor” raster).
  • match(), %in%, and $%notin%$: Find which cells of a GRaster match or do not match certain category labels
  • missing.cases() finds rows in the levels table that have at least one NA.
  • missingCats() finds values in categorical rasters that do not have a category assigned to them.
  • nlevels() returns the number of levels represented by a categorical raster.
  • subst(): Re-assign category levels

Saving rasters to disk

You can potentially save substantial space on disk by setting the datatype argument in writeRaster() to an appropriate value when saving a raster. This argument allows for finer “divisions” than just integer/float/double-float, so depending on the range of values in your raster, you can optimize file size by selecting the one that best matches the values in the raster. See the documentation for writeRaster() for more information.

~ FINIS ~