Learn R Programming

RSurvey (version 0.6-0)

CutoutPolygon: Determine Grid Points within Polygon

Description

This function excludes gridded data lying outside of a given polygon.

Usage

CutoutPolygon(dat, ply = NULL)

Arguments

dat
list; with components x, y, and z, see Value.
ply
gpc.poly; the polygon defining the crop region for the gridded data.

Value

  • Returns a list containing the following components:
  • xnumeric; a vector of x coordinates.
  • ynumeric; a vector of y coordinates.
  • zmatrix; the state variable corresponding to coordinates in the grid.

Details

Values of z corresponding to coordinates (x, y) located outside the polygon will be set to NA.

See Also

point.in.polygon

Examples

Run this code
x11()

ply <- as(cbind(c(2, 8, 9, 6, 3), c(3, 1, 4, 8, 6)), "gpc.poly")
x <- seq(0, 10, 0.1)
y <- seq(0, 10, 0.1)
z <- matrix(runif(length(x) * length(y)), nrow = length(y), 
            ncol = length(x))

d <- list(x = x, y = y, z = z)
filled.contour(d, plot.axes = {axis(1); axis(2); plot(ply, add = TRUE)})

d <- CutoutPolygon(d, ply)
filled.contour(d, color.palette = terrain.colors)

Run the code above in your browser using DataLab