Learn R Programming

ocean (version 0.1-0)

is.in.grid: Checks is a point is within a grid

Description

Given a grid and a point or vector of points, is.in.grid returns a binary vector of length length(x). The vectors x and y must be the same length.

Usage

is.in.grid(x, y, grid, units='ll')

Arguments

x
x coordinates.
y
y coordinates.
grid
The grid to plot the data on.
units
x and y units. If 'm', the x and y coordinates in grid are used. If 'll', the lat and lon variables in grid are used.

Value

  • A binary vector with TRUE if each point is in the grid and FALSE otherwise.

Examples

Run this code
## Use the grid created in the att.plot example
example(att.plot)
## Create a regular matrix grid
lattice.grid <- expand.grid(x=seq(min(grid$nodes$x), max(grid$nodes$x),
                            len=10), y=seq(min(grid$nodes$y),
                            max(grid$nodes$y), len=10))
elems <- is.in.grid(lattice.grid$x, lattice.grid$y, grid, units='m')
## Plot the result, but only points in the grid
plot(lattice.grid$x[elems], lattice.grid$y[elems])

Run the code above in your browser using DataLab