Grid cell operators

grd_cell(grid, point, ..., snap = grd_snap_next)

grd_cell_range(
  grid,
  bbox = wk_bbox(grid),
  ...,
  step = 1L,
  snap = grd_snap_next
)

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

# S3 method for wk_grd_rct
grd_cell_rct(grid, i, j = NULL, ..., out_of_bounds = "keep")

# S3 method for wk_grd_xy
grd_cell_rct(grid, i, j = NULL, ..., out_of_bounds = "keep")

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

# S3 method for wk_grd_rct
grd_cell_xy(grid, i, j = NULL, ..., out_of_bounds = "keep")

# S3 method for wk_grd_xy
grd_cell_xy(grid, i, j = NULL, ..., out_of_bounds = "keep")

Arguments

grid

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

point

A handleable of points.

...

Unused

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.

bbox

An rct() object.

step

The difference between adjascent indices in the output

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.

out_of_bounds

One of 'keep', 'censor', 'discard', or 'squish'

Value

  • grd_cell(): returns a list(i, j) of index values corresponding to the input points and adjusted according to snap. Index values will be outside dim(grid) for points outside wk_bbox(grid) including negative values.

  • grd_cell_range() returns a slice describing the range of indices in the i and j directions.

  • grd_cell_rct() returns a rct() of the cell extent at i, j.

  • grd_cell_xy() returns a xy() of the cell center at i, j.

Examples

grid <- grd(nx = 3, ny = 2)
grd_cell(grid, xy(0.5, 0.5))
#>   i j
#> 1 2 1
grd_cell_range(grid, grid$bbox)
#> $i
#> start  stop  step 
#>     0     3     1 
#> 
#> $j
#> start  stop  step 
#>     0     4     1 
#> 
grd_cell_rct(grid, 1, 1)
#> <wk_rct[1]>
#> [1] [0 1 1 2]
grd_cell_xy(grid, 1, 1)
#> <wk_xy[1]>
#> [1] (0.5 1.5)