Learn R Programming

ocean (version 0.1-0)

find.elem: Finds the element number for a point in a grid

Description

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

Usage

find.elem(x, y, grid, units='ll')

Arguments

x
x coordinates
y
y coordinates
grid
The grid to search for these points.
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 vector with the element number for points on the grid, or -1 for points not on the grid.

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 <- find.elem(lattice.grid$x, lattice.grid$y, grid, units='m')
elems
## Plot the result, but only points in the grid
elems[elems == -1] <- NA
plot(lattice.grid$x, lattice.grid$y, pch=15,
     col=heat.colors(max(elems, na.rm=TRUE) + 2)[elems+2])

Run the code above in your browser using DataLab