fm_pixels {fmesher} | R Documentation |
Generate lattice points covering a mesh
Description
Generate terra
, sf
, or sp
lattice locations
Usage
fm_pixels(
mesh,
dims = c(150, 150),
xlim = NULL,
ylim = NULL,
mask = TRUE,
format = "sf",
minimal = TRUE,
nx = deprecated(),
ny = deprecated()
)
Arguments
Value
sf
, SpatRaster
, or SpatialPixelsDataFrame
covering the mesh or
mask.
Author(s)
Finn Lindgren finn.lindgren@gmail.com
Examples
if (require("ggplot2", quietly = TRUE)) {
dims <- c(50, 50)
pxl <- fm_pixels(
fmexample$mesh,
dims = dims,
mask = fmexample$boundary_sf[[1]],
minimal = TRUE
)
pxl$val <- rnorm(NROW(pxl)) +
fm_evaluate(fmexample$mesh, pxl, field = 2 * fmexample$mesh$loc[, 1])
ggplot() +
geom_tile(
data = pxl,
aes(geometry = geometry, fill = val),
stat = "sf_coordinates"
) +
geom_sf(data = fm_as_sfc(fmexample$mesh), alpha = 0.2)
}
if (require("ggplot2", quietly = TRUE) &&
require("terra", quietly = TRUE) &&
require("tidyterra", quietly = TRUE)) {
pxl <- fm_pixels(fmexample$mesh,
dims = c(50, 50), mask = fmexample$boundary_sf[[1]],
format = "terra"
)
pxl$val <- rnorm(NROW(pxl) * NCOL(pxl))
pxl <-
terra::mask(
pxl,
mask = pxl$.mask,
maskvalues = c(FALSE, NA),
updatevalue = NA
)
ggplot() +
geom_spatraster(data = pxl, aes(fill = val)) +
geom_sf(data = fm_as_sfc(fmexample$mesh), alpha = 0.2)
}
[Package fmesher version 0.1.7 Index]