rmf_as_sf: Functions to convert rmf_array and rmf_list objects to simple...

View source: R/spatial.R

rmf_as_sfR Documentation

Functions to convert rmf_array and rmf_list objects to simple features

Description

Functions to convert rmf_array and rmf_list objects to simple features

Usage

rmf_as_sf(...)

## S3 method for class 'rmf_2d_array'
rmf_as_sf(
  array,
  dis,
  mask = array * 0 + 1,
  prj = rmf_get_prj(dis),
  name = "value",
  as_points = FALSE,
  id = "r",
  ...
)

## S3 method for class 'rmf_3d_array'
rmf_as_sf(
  array,
  dis,
  mask = array * 0 + 1,
  prj = rmf_get_prj(dis),
  name = "value",
  as_points = FALSE,
  id = "r",
  ...
)

## S3 method for class 'rmf_4d_array'
rmf_as_sf(
  array,
  dis,
  mask = array(1, dim = dim(array)[1:3]),
  prj = rmf_get_prj(dis),
  name = "value",
  as_points = FALSE,
  id = "r",
  ...
)

## S3 method for class 'rmf_list'
rmf_as_sf(obj, dis, prj = rmf_get_prj(dis), as_points = FALSE, id = "r", ...)

Arguments

...

additional arguments passed to rmf_as_tibble when converting a rmf_list object. Otherwise, ignored.

array

rmf_2d_array, rmf_3d_array or rmf_4d_array object

dis

RMODFLOW dis object

mask

a 2d array when array is 2d or a 3d array when array is 3d or 4d that can be coerced to logical. Used to specify which cells to convert to sf. Defaults to all cells.

prj

RMODFLOW prj object

name

character specifying the name of the resulting variable in the sf object. Defaults to 'value'

as_points

logical; should returned sf object represent cell-centered nodal points (TRUE) or cell polygons (FALSE, default)

id

either 'r' (default) or 'modflow'. Specifies which type of cell id is returned. R uses column-major array ordering whereas MODFLOW uses row-major ordering.

obj

rmf_list object

Details

The returned z coordinate when as_points = TRUE reflects the cell node. The crs is taken from the prj argument. Note that in MODFLOW, row indices (i) increase with decreasing Y coordinates, i.e. row 1 - column 1 corresponds to the upperleft cell.

Value

A sf object with point geometries representing the cell-centered nodes when as_points = TRUE. When as_points = FALSE, the geometries are polygons representing the entire cell. When converting a rmf_array, the sf object has following variables: one with the array values per cell/node, one containing the cell id (when id is 'r' or 'modflow'), top and bottom of the cells when the array is 3d or 4d plus the z value of the node when as_points = TRUE. When a 4d array is converted, an additional time column is added as well.

When converting a rmf_list, all variables in the rmf_list object are retained with the addition of the cell id column (when id is 'r' or 'modflow') and top and bottom columns if as_points = FALSE or a z column when as_points = TRUE.

Examples

dis <- rmf_create_dis()

# 2d array
r <- rmf_create_array(1:prod(dis$nrow, dis$ncol), dim = c(dis$nrow, dis$ncol))
rmf_as_sf(r, dis = dis)
rmf_as_sf(r, dis = dis, as_points = TRUE)

# 3d array
r <- rmf_create_array(1:prod(dis$nrow, dis$ncol, dis$nlay), dim = c(dis$nrow, dis$ncol, dis$nlay))
rmf_as_sf(r, dis = dis, id = 'modflow')
rmf_as_sf(r, dis = dis, as_points = TRUE)

# 4d array
r <- rmf_create_array(1:prod(dis$nrow, dis$ncol, dis$nlay, 2), dim = c(dis$nrow, dis$ncol, dis$nlay, 2))
rmf_as_sf(r, dis = dis, id = FALSE)

# rmf_list
l <- rmf_create_list(data.frame(i = 1, j = 1:2, k = c(3, 2), q = c(-500, -400)))
rmf_as_sf(l, dis = dis)

# 2d array with varying cellsize
dis$delr <- c(seq(50, 10, length.out = 7), seq(10, 50, length.out = 3))
dis$delc <- c(seq(100, 20, length.out = 7), seq(30, 100, length.out = 3)) # increasing i with decreasing Y
r <- rmf_create_array(1:prod(dis$nrow, dis$ncol), dim = c(dis$nrow, dis$ncol))
rmf_as_sf(r, dis = dis)


rogiersbart/RMODFLOW documentation built on Jan. 14, 2023, 4:21 a.m.