Learn R Programming

RSurvey (version 0.8-3)

CutoutPolygon: Exclude Gridded Data Outside Polygon

Description

This function excludes gridded data located outside 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:
x, y
numeric; a vector of x and y coordinates.
z
matrix; 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
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)})

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

Run the code above in your browser using DataLab