Convert a simple features object to a rmf_array (rasterize)

# S3 method for sf
rmf_as_array(
  obj,
  dis,
  select,
  na_value = 0,
  prj = rmf_get_prj(dis),
  sparse = TRUE,
  kper = attr(obj, "kper"),
  ...
)

Arguments

obj

sf object

dis

RMODFLOW dis object

select

integer or character specifying which column from obj to rasterize

na_value

value of the cells in the array which are not specified in obj; defaults to 0

prj

RMODFLOw prj object

sparse

logical; should a 2d (TRUE; default) or 3d (FALSE) array be returned

kper

optional integers specifying the stress-periods during which this array is active

...

additional arguments passed to stars::st_rasterize

Value

a rmf_2d_array if sparse = TRUE; a rmf_3d_array if sparse = FALSE

Details

stars::st_rasterize is used to rasterize obj to the MODFLOW grid which calls GDALRasterize. Alternatively, the user can call rmf_as_list on obj and rmf_as_array on the resulting rmf_list. Results may differ.

Examples

sfc <- sf::st_sfc(list(sf::st_point(c(100,200)), sf::st_point(c(750, 800)), sf::st_point(c(700, 850)))) obj <- sf::st_sf(q = c(-500, -400, -300), geom = sfc) dis <- rmf_create_dis() rmf_as_array(obj, dis = dis, select = 'q')
#> RMODFLOW 2d array with 10 rows and 10 columns, representing the i & j dimensions. #> Not representing stress period data #> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 0 0 0 0 0 0 0 0 0 0 #> [2,] 0 0 0 0 0 0 0 -300 0 0 #> [3,] 0 0 0 0 0 0 0 0 0 0 #> [4,] 0 0 0 0 0 0 0 0 0 0 #> [5,] 0 0 0 0 0 0 0 0 0 0 #> [6,] 0 0 0 0 0 0 0 0 0 0 #> [7,] 0 0 0 0 0 0 0 0 0 0 #> [8,] 0 -500 0 0 0 0 0 0 0 0 #> [9,] 0 0 0 0 0 0 0 0 0 0 #> [10,] 0 0 0 0 0 0 0 0 0 0
rmf_as_array(obj, dis = dis, select = 'q', options = c('MERGE_ALG=ADD'))
#> RMODFLOW 2d array with 10 rows and 10 columns, representing the i & j dimensions. #> Not representing stress period data #> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 0 0 0 0 0 0 0 0 0 0 #> [2,] 0 0 0 0 0 0 0 -700 0 0 #> [3,] 0 0 0 0 0 0 0 0 0 0 #> [4,] 0 0 0 0 0 0 0 0 0 0 #> [5,] 0 0 0 0 0 0 0 0 0 0 #> [6,] 0 0 0 0 0 0 0 0 0 0 #> [7,] 0 0 0 0 0 0 0 0 0 0 #> [8,] 0 -500 0 0 0 0 0 0 0 0 #> [9,] 0 0 0 0 0 0 0 0 0 0 #> [10,] 0 0 0 0 0 0 0 0 0 0
# alternative rmf_as_list(obj, dis = dis, select = 'q') %>% rmf_as_array(dis = dis)
#> RMODFLOW 2d array with 10 rows and 10 columns, representing the i & j dimensions. #> Not representing stress period data #> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 0 0 0 0 0 0 0 0 0 0 #> [2,] 0 0 0 0 0 0 -300 -700 0 0 #> [3,] 0 0 0 0 0 0 0 -400 0 0 #> [4,] 0 0 0 0 0 0 0 0 0 0 #> [5,] 0 0 0 0 0 0 0 0 0 0 #> [6,] 0 0 0 0 0 0 0 0 0 0 #> [7,] 0 0 0 0 0 0 0 0 0 0 #> [8,] -500 -500 0 0 0 0 0 0 0 0 #> [9,] -500 -500 0 0 0 0 0 0 0 0 #> [10,] 0 0 0 0 0 0 0 0 0 0