Learn R Programming

ocean (version 0.2-4)

find.elem: Checks if the points (xy$x, xy$y) are in the fvcom.grid grid.

Description

Given a grid and a point or set of points, find.elem returns the element number of each point in the grid. NA is returned for any point that does not lie within the grid. x and y must be the same length.

Arguments

grid
A fvcom.grid instance.
xy
A data.frame with components x and y with the x and y locations of the points.
units
Either 'll' for latitude and longitude or 'm' for meters.

Value

A vector of integer values of length nrow(xy). The values are indexes into the elements of grid.

Examples

Run this code
{
# Create a regular matrix grid
nodes = get.nodes(ocean.demo.grid)
lattice.grid = expand.grid(x=seq(min(nodes$x), max(nodes$x), len=50),
                           y=seq(min(nodes$y), max(nodes$y), len=50))
elems = find.elem(ocean.demo.grid, lattice.grid, units="m")
# Plot the result
plot(lattice.grid$x, lattice.grid$y, pch=15,
     col=jet.colors(max(elems, na.rm=TRUE) + 2)[elems+2])
}

Run the code above in your browser using DataLab