cellref.loc: Find grid reference of point in grid

Description Usage Arguments Value Examples

Description

Find column, row or other discrete divider reference in a grid, from its co-ordinate. May also be used in the time dimension. Vectorised in x.

Usage

1

Arguments

x

numeric []; locations in relevant dimension

gcs

numeric []; grid line co-ordinates in relevant dimension. Must have length one more than the number of discretised units in the relevant dimension. For example, when finding the column reference, the length of gcs must be one more than the number of columns, including the left and right edges of the model grid.

rev

logical [1]; whether the grid lines are numbered in reverse order of co-ordinate. Generally FALSE for column references and TRUE for row references. See the examples for more guidance on usage with MODFLOW grids.

Value

An integer vector of the same length as x, showing which grid cell reference the values of x are found in. NA shows that values of x are outside the grid boundaries.

Values of x that are exactly on the grid lines are assigned to the smaller reference (or greater if rev = TRUE, as a side effect of rev).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# some of these values may be outside the grid boundary
x <- sample(seq(0, 11, .1), 20)
# irregular grids are supported, but gcs must be in ascending order
gcs <- sort(sample(seq(0, 10, .5), 11))

cellref.loc(x, gcs)
cellref.loc(x, gcs, TRUE)

# for MODFLOW models:
library("RNetCDF")
mfdata <- open.nc(system.file("rflow_mf_demo.nc", package = "Rflow"))
#
# - example column reference
gccs <- c(var.get.nc(mfdata, "gccs") +
            att.get.nc(mfdata, "NC_GLOBAL", "origin-x"))
(C <- cellref.loc(625, gccs))
#
# - example row reference
#  -- rows are numbered in order of decreasing y, so put rev = TRUE
grcs <- c(var.get.nc(mfdata, "grcs") +
            att.get.nc(mfdata, "NC_GLOBAL", "origin-y"))
(R <- cellref.loc(825, grcs, TRUE))
#
# - example layer reference
#  -- layer divides are in descending order, so reverse the layer
#      divides and also use rev = TRUE
ldivs.cr <- c(var.get.nc(mfdata, "elev", c(C, R, NA), c(1L, 1L, NA)))
(L <- cellref.loc(25, rev(ldivs.cr), TRUE))
#
# - example time step reference
(ts <- cellref.loc(1500, mftstime(mfdata)))

CJBarry/Rflow documentation built on June 16, 2019, 12:35 p.m.