longLatRasts {enmSdmX} | R Documentation |
Generate rasters with cell values equal to cell longitude or latitude
Description
This function generates a raster stack with two rasters, one with cell values equal to the cell's longitude and the other with cell values equal to the cell's latitude.
Usage
longLatRasts(x, m = TRUE, filePath = NULL, ...)
Arguments
x |
|
m |
Any of:
|
filePath |
String or |
... |
Arguments to pass to |
Value
Object of class SpatRaster
.
Examples
library(terra)
# generate long/lat rasters for the world
x <- rast() # raster with 1 deg resolution and extent equal to entire world
x[] <- 1:ncell(x)
longLat <- longLatRasts(x)
plot(longLat)
# demonstrate masking
# randomly force some cells to NA
v <- 1:ncell(x)
n <- 10000
v[sample(v, n)] <- NA
x[] <- v
longLatTRUE <- longLatRasts(x, m = TRUE)
longLatFALSE <- longLatRasts(x, m = FALSE)
rasts <- c(x, longLatTRUE, x, longLatFALSE)
names(rasts) <- c('x', 'long_m_TRUE', 'lat_m_TRUE',
'x', 'long_m_FALSE', 'lat_m_FALSE')
plot(rasts)