init,GRaster-method | R Documentation |
This function can be used to make a GRaster
with cell values equal to the cell center's longitude, latitude, row, or column, or in a "chess"-like or "regular" pattern.
## S4 method for signature 'GRaster'
init(x, fun, odd = TRUE, vals = c(0, 1))
x |
A |
fun |
Character: Any of:
|
odd |
Logical: If |
vals |
Vector of two numeric values: If |
A GRaster
with as many layers as x
.
terra::init()
, longlat()
if (grassStarted()) {
# Setup
library(terra)
# Elevation raster, rivers vector
madElev <- fastData("madElev")
# Convert to a GRaster
elev <- fast(madElev)
# Cell coordinates
init(elev, "x")
init(elev, "y")
# Cell row or column
init(elev, "row")
init(elev, "col")
# Chess
elevAgg <- aggregate(elev, 32) # make cells bigger so we can see them
chessOdd <- init(elevAgg, "chess")
chessEven <- init(elevAgg, "chess", odd = FALSE)
chess <- c(chessOdd, chessEven)
names(chess) <- c("odd", "even")
plot(chess)
# Chess with user-defined values
elevAgg <- aggregate(elev, 32) # make cells bigger so we can see
chessOdd13 <- init(elevAgg, "chess", vals = c(0, 13))
chessEven13 <- init(elevAgg, "chess", odd = FALSE, vals = c(0, 13))
chess13 <- c(chessOdd13, chessEven13)
names(chess13) <- c("odd", "even")
plot(chess13)
# Regular
elevAgg <- aggregate(elev, 32) # make cells bigger so we can see
regOdd <- init(elevAgg, "regular")
regEven <- init(elevAgg, "regular", odd = FALSE)
reg <- c(regOdd, regEven)
names(reg) <- c("odd", "even")
plot(reg)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.