The grd_subset() method handles the subsetting of a grd() in x-y space. Ordering of indices is not considered and logical indies are recycled silently along dimensions. The result of a grd_subset() is always a grd() of the same type whose relationship to x-y space has not changed.

grd_subset(grid, i = NULL, j = NULL, ...)

grd_crop(grid, bbox, ..., step = 1L, snap = NULL)

grd_extend(grid, bbox, ..., step = 1L, snap = NULL)

# S3 method for wk_grd_rct
grd_crop(grid, bbox, ..., step = 1L, snap = NULL)

# S3 method for wk_grd_xy
grd_crop(grid, bbox, ..., step = 1L, snap = NULL)

# S3 method for wk_grd_rct
grd_extend(grid, bbox, ..., step = 1L, snap = NULL)

# S3 method for wk_grd_xy
grd_extend(grid, bbox, ..., step = 1L, snap = NULL)

grd_data_subset(grid_data, i = NULL, j = NULL)

Arguments

grid

A grd_xy(), grd_rct(), or other object implementing grd_*() methods.

i, j

1-based index values. i indices correspond to decreasing y values; j indices correspond to increasing x values. Values outside the range 1:nrow|ncol(data) will be censored to NA including 0 and negative values.

...

Passed to subset methods

bbox

An rct() object.

step

The difference between adjascent indices in the output

snap

A function that transforms real-valued indices to integer indices (e.g., floor(), ceiling(), or round()). For grd_cell_range(), a list() with exactly two elements to be called for the minimum and maximum index values, respectively.

grid_data

The data member of a grd(). This is typically an array but can also be an S3 object with an array-like subset method. The native raster is special-cased as its subset method requires non-standard handling.

Value

A modified grid whose cell centres have not changed location as a result of the subset.

Examples

grid <- grd_rct(volcano)
grd_subset(grid, 1:20, 1:30)
#> <wk_grd_rct [20 x 30] => [0 67 30 87]>
#> List of 2
#>  $ data: num [1:20, 1:30] 100 101 102 103 104 105 105 106 107 108 ...
#>  $ bbox: wk_rct[1:1] [0 67 30 87]
#>  - attr(*, "class")= chr [1:2] "wk_grd_rct" "wk_grd"
grd_crop(grid, rct(-10, -10, 10, 10))
#> <wk_grd_rct [10 x 10] => [0 0 10 10]>
#> List of 2
#>  $ data: num [1:10, 1:10] 100 100 99 99 99 99 98 98 97 97 ...
#>  $ bbox: wk_rct[1:1] [0 0 10 10]
#>  - attr(*, "class")= chr [1:2] "wk_grd_rct" "wk_grd"
grd_extend(grid, rct(-10, -10, 10, 10))
#> <wk_grd_rct [20 x 20] => [-10 -10 10 10]>
#> List of 2
#>  $ data: num [1:20, 1:20] NA NA NA NA NA NA NA NA NA NA ...
#>  $ bbox: wk_rct[1:1] [-10 -10 10 10]
#>  - attr(*, "class")= chr [1:2] "wk_grd_rct" "wk_grd"