create_raster_from_variables: Fills a raster grid with variable values associated with...

View source: R/functions_raster.R

create_raster_from_variablesR Documentation

Fills a raster grid with variable values associated with geographic locations

Description

Fills a raster grid with variable values associated with geographic locations

Usage

create_raster_from_variables(
  data,
  site_locations,
  grid,
  site_crs = sf::st_crs(site_locations),
  filename = ""
)

Arguments

data

A vector or two-dimensional object. Elements/rows correspond to site_locations; columns (if present) represent variables.

site_locations

An object that described geographic locations of data that can be sent to as_points

grid

A Raster* object used as template.

site_crs

The crs of site_locations passed to as_points.

filename

A character string. Passed to brick.

Value

A raster::RasterLayer (if data is a vector) or raster::RasterBrick (if data is two-dimensional).

Examples

if (requireNamespace("raster")) {
  r <- raster::raster(
    xmn = 0, xmx = 10,
    ymn = 0, ymx = 10,
    crs = "OGC:CRS84",
    resolution = c(1, 1)
  )

  rv <- create_raster_from_variables(
    data = 1:10,
    site_locations = as_points(
      0.5 + cbind(0:9, 0:9),
      crs = "OGC:CRS84",
      to_class = "sf"
    ),
    grid = r
  )
}


DrylandEcology/rSW2st documentation built on Jan. 10, 2024, 6:22 p.m.