longLatRasts | R Documentation |
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.
longLatRasts(x, m = TRUE, filePath = NULL, ...)
x |
|
m |
Any of:
|
filePath |
String or |
... |
Arguments to pass to |
Object of class SpatRaster
.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.