Learn R Programming

RSurvey (version 0.4.5)

polyCutout: Cutout Grid Points within Polygon

Description

This function excludes data points outside a given polygon.

Usage

polyCutout(dat, ply)

Arguments

dat
a list containing x, y, and z components, see Value section.
ply
a polygon of class gpc.poly-class.

Value

  • A list containing the following components:
  • xgrid point locations in the x-direction.
  • ygrid point locations in the y-direction.
  • za matrix of state variable values corresponding to the grid.

Details

Returns NA values for z when points (x, y) are located outside the polygon.

See Also

point.in.polygon, filled.contour

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))

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

dat.new <- polyCutout(dat.old, ply)
filled.contour(dat.new, color.palette = terrain.colors)

Run the code above in your browser using DataLab