R/spatial.R
rmf_as_sf.Rd
Functions to convert rmf_array and rmf_list objects to simple features
rmf_as_sf(...) # S3 method for 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 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 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 rmf_list rmf_as_sf(obj, dis, prj = rmf_get_prj(dis), as_points = FALSE, 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 sf object. Defaults to |
as_points | logical; should returned sf object represent cell-centered nodal points (TRUE) or cell polygons (FALSE, default) |
id | either |
obj |
|
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
.
The returned z coordinate when as_points = TRUE
reflects the cell node.
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_sf(r, dis = dis)#> Simple feature collection with 100 features and 2 fields #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1000 ymax: 1000 #> CRS: NA #> First 10 features: #> value id geometry #> 1 10 10 POLYGON ((0 0, 100 0, 100 1... #> 2 20 20 POLYGON ((100 0, 200 0, 200... #> 3 30 30 POLYGON ((200 0, 300 0, 300... #> 4 40 40 POLYGON ((300 0, 400 0, 400... #> 5 50 50 POLYGON ((400 0, 500 0, 500... #> 6 60 60 POLYGON ((500 0, 600 0, 600... #> 7 70 70 POLYGON ((600 0, 700 0, 700... #> 8 80 80 POLYGON ((700 0, 800 0, 800... #> 9 90 90 POLYGON ((800 0, 900 0, 900... #> 10 100 100 POLYGON ((900 0, 1000 0, 10...rmf_as_sf(r, dis = dis, as_points = TRUE)#> Simple feature collection with 100 features and 2 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 50 ymin: 50 xmax: 950 ymax: 950 #> CRS: NA #> First 10 features: #> value id geometry #> 1 10 10 POINT (50 50) #> 2 20 20 POINT (150 50) #> 3 30 30 POINT (250 50) #> 4 40 40 POINT (350 50) #> 5 50 50 POINT (450 50) #> 6 60 60 POINT (550 50) #> 7 70 70 POINT (650 50) #> 8 80 80 POINT (750 50) #> 9 90 90 POINT (850 50) #> 10 100 100 POINT (950 50)# 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')#> Simple feature collection with 300 features and 4 fields #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1000 ymax: 1000 #> CRS: NA #> First 10 features: #> id value top botm geometry #> 1 91 10 0 -10 POLYGON ((0 0, 100 0, 100 1... #> 2 291 210 -20 -30 POLYGON ((0 0, 100 0, 100 1... #> 3 191 110 -10 -20 POLYGON ((0 0, 100 0, 100 1... #> 4 192 120 -10 -20 POLYGON ((100 0, 200 0, 200... #> 5 92 20 0 -10 POLYGON ((100 0, 200 0, 200... #> 6 292 220 -20 -30 POLYGON ((100 0, 200 0, 200... #> 7 93 30 0 -10 POLYGON ((200 0, 300 0, 300... #> 8 293 230 -20 -30 POLYGON ((200 0, 300 0, 300... #> 9 193 130 -10 -20 POLYGON ((200 0, 300 0, 300... #> 10 194 140 -10 -20 POLYGON ((300 0, 400 0, 400...rmf_as_sf(r, dis = dis, as_points = TRUE)#> Simple feature collection with 300 features and 5 fields #> Geometry type: POINT #> Dimension: XY #> Bounding box: xmin: 50 ymin: 50 xmax: 950 ymax: 950 #> CRS: NA #> First 10 features: #> id value z top botm geometry #> 1 10 10 -5 0 -10 POINT (50 50) #> 2 210 210 -25 -20 -30 POINT (50 50) #> 3 110 110 -15 -10 -20 POINT (50 50) #> 4 120 120 -15 -10 -20 POINT (150 50) #> 5 20 20 -5 0 -10 POINT (150 50) #> 6 220 220 -25 -20 -30 POINT (150 50) #> 7 30 30 -5 0 -10 POINT (250 50) #> 8 230 230 -25 -20 -30 POINT (250 50) #> 9 130 130 -15 -10 -20 POINT (250 50) #> 10 140 140 -15 -10 -20 POINT (350 50)# 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)#> Warning: ts_time is TRUE but the array contains less time steps than specified by dis. Please consider setting ts_time = FALSE#> Simple feature collection with 600 features and 5 fields #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 0 xmax: 1000 ymax: 1000 #> CRS: NA #> First 10 features: #> value top botm time nstp geometry #> 1 210 -20 -30 1 1 POLYGON ((0 0, 100 0, 100 1... #> 4 110 -10 -20 1 1 POLYGON ((0 0, 100 0, 100 1... #> 6 10 0 -10 1 1 POLYGON ((0 0, 100 0, 100 1... #> 9 120 -10 -20 1 1 POLYGON ((100 0, 200 0, 200... #> 10 220 -20 -30 1 1 POLYGON ((100 0, 200 0, 200... #> 11 20 0 -10 1 1 POLYGON ((100 0, 200 0, 200... #> 13 230 -20 -30 1 1 POLYGON ((200 0, 300 0, 300... #> 17 30 0 -10 1 1 POLYGON ((200 0, 300 0, 300... #> 18 130 -10 -20 1 1 POLYGON ((200 0, 300 0, 300... #> 21 140 -10 -20 1 1 POLYGON ((300 0, 400 0, 400...# 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)#> Simple feature collection with 2 features and 4 fields #> Geometry type: POLYGON #> Dimension: XY #> Bounding box: xmin: 0 ymin: 900 xmax: 200 ymax: 1000 #> CRS: NA #> id q top botm geom #> 1 201 -500 -10 -20 POLYGON ((0 900, 0 1000, 10... #> 2 111 -400 -20 -30 POLYGON ((100 900, 100 1000...