maskNA,GRaster-method | R Documentation |
This function converts all non-NA
cells in a GRaster
to a single user-defined value, leaving NA
cells as NA
. Alternatively, it can convert NA
cells to a user-defined value, and all non-NA
cells to NA.
## S4 method for signature 'GRaster'
maskNA(x, value = 1, invert = FALSE, retain = FALSE)
x |
A |
value |
Numeric: Value to which to assign to masked cells. The default is 1. |
invert |
Logical: If |
retain |
Logical: If |
not.na()
, app()
, mask()
if (grassStarted()) {
# Setup
library(terra)
# Elevation raster
madElev <- fastData("madElev")
# Convert a SpatRaster to a GRaster:
elev <- fast(madElev)
# Convert non-NA to 1, NA cells remain NA
elevMask <- maskNA(elev)
elevMask
plot(c(elev, elevMask))
# Convert NA to 1, non-NA cells become NA
elevInvertMask <- maskNA(elev, invert = TRUE)
elevInvertMask
plot(c(elev, elevInvertMask))
# Convert NA to 200, non-NA cells keep their values
elevInvertRetain <- maskNA(elev, value = 200, invert = TRUE, retain = TRUE)
elevInvertRetain
plot(c(elev, elevInvertRetain))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.