R/spatial.R
rmf_as_stars.RdFunctions to convert rmf_array and rmf_list objects to stars objects
rmf_as_stars(...) # S3 method for rmf_2d_array rmf_as_stars( array, dis, mask = array * 0 + 1, prj = rmf_get_prj(dis), name = "value", id = "r", ... ) # S3 method for rmf_3d_array rmf_as_stars( array, dis, mask = array * 0 + 1, prj = rmf_get_prj(dis), name = "value", id = "r", ... ) # S3 method for rmf_4d_array rmf_as_stars( array, dis, mask = array(1, dim = dim(array)[1:3]), prj = rmf_get_prj(dis), name = "value", id = "r", ... ) # S3 method for rmf_list rmf_as_stars( obj, dis, select, prj = rmf_get_prj(dis), name = "value", id = "r", ... )
| ... | additional arguments passed to |
|---|---|
| array |
|
| dis |
|
| mask | a 2d array when |
| prj |
|
| name | character specifying the name of the resulting variable in the stars object. Defaults to |
| id | either |
| obj |
|
| select | integer or character specifying which column of the |
a stars object with x and y dimensions when array is 2d, x, y and layer (integer representing MODFLOW layer; similar to bands) when array is 3d,
x, y, layer and time dimensions when array is 4d. When converting a rmf_list object, it is first converted to a rmf_array using rmf_as_array.
Two variables are present in the returned stars object, one with the array values and on with the cell id (when id is 'r' or 'modflow').
The crs is taken from the prj argument.
dis <- rmf_create_dis() # 2d array r <- rmf_create_array(1:prod(dis$nrow, dis$ncol), dim = c(dis$nrow, dis$ncol)) rmf_as_stars(r, dis = dis)#> stars object with 2 dimensions and 2 attributes #> attribute(s): #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> value 1 25.75 50.5 50.5 75.25 100 #> id 1 25.75 50.5 50.5 75.25 100 #> dimension(s): #> from to offset delta refsys point values x/y #> x 1 10 0 100 NA FALSE NULL [x] #> y 1 10 0 100 NA FALSE NULL [y]# 3d array r <- rmf_create_array(1:prod(dis$nrow, dis$ncol, dis$nlay), dim = c(dis$nrow, dis$ncol, dis$nlay)) rmf_as_stars(r, dis = dis, id = 'modflow')#> stars object with 3 dimensions and 2 attributes #> attribute(s): #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> value 1 75.75 150.5 150.5 225.25 300 #> id 1 75.75 150.5 150.5 225.25 300 #> dimension(s): #> from to offset delta refsys point values x/y #> x 1 10 0 100 NA FALSE NULL [x] #> y 1 10 0 100 NA FALSE NULL [y] #> layer 1 3 NA NA NA NA layer_1, layer_2, layer_3# 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_stars(r, dis = dis, id = FALSE)#> stars object with 4 dimensions and 1 attribute #> attribute(s): #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> value 1 150.75 300.5 300.5 450.25 600 #> dimension(s): #> from to offset delta refsys point values x/y #> x 1 10 0 100 NA FALSE NULL [x] #> y 1 10 0 100 NA FALSE NULL [y] #> layer 1 3 NA NA NA NA layer_1, layer_2, layer_3 #> time 1 2 1 1 NA NA NULL# rmf_list l <- rmf_create_list(data.frame(i = 1, j = 1:2, k = c(3, 2), q = c(-500, -400), d = 35)) rmf_as_stars(l, dis = dis, select = 'q')#> stars object with 3 dimensions and 2 attributes #> attribute(s): #> Min. 1st Qu. Median Mean 3rd Qu. Max. #> value -500 0.00 0.0 -3.0 0.00 0 #> id 1 75.75 150.5 150.5 225.25 300 #> dimension(s): #> from to offset delta refsys point values x/y #> x 1 10 0 100 NA FALSE NULL [x] #> y 1 10 0 100 NA FALSE NULL [y] #> layer 1 3 NA NA NA NA layer_1, layer_2, layer_3