SetPolygons: Overlay Multi-Polygon Objects

Description Usage Arguments Details Value Author(s) Examples

View source: R/SetPolygons.R

Description

Calculate the intersection or difference between two multi-polygon objects.

Usage

1
SetPolygons(x, y, cmd = c("gIntersection", "gDifference"), buffer.width = NA)

Arguments

x

'SpatialPolygons*'. Multi-polygon object

y

'SpatialPolygons*' or 'Extent'. Multi-polygon object

cmd

'character' string. Specifying "gIntersection", the default, cuts out portions of the x polygons that overlay the y polygons. If "gDifference" is specified, only those portions of the x polygons falling outside the y polygons are copied to the output polygons.

buffer.width

'numeric' number. Expands or contracts the geometry of y to include the area within the specified width, see gBuffer. Specifying NA, the default, indicates no buffer.

Details

This function tests if the resulting geometry is valid. If invalid, an attempt is made to make the geometry valid by zero-width buffering.

Value

An object of class 'SpatialPolygons*'.

Author(s)

J.C. Fisher, U.S. Geological Survey, Idaho Water Science Center

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
m1a <- rbind(c(17.5, 55.1),
             c(24.7, 55.0),
             c(22.6, 61.1),
             c(16.5, 59.7),
             c(17.5, 55.1))
m1b <- m1a
m1b[, 1] <- m1b[, 1] + 11
p1 <- list(sp::Polygon(m1a, FALSE), sp::Polygon(m1b, FALSE))
p1 <- sp::SpatialPolygons(list(sp::Polygons(p1, 1)))
sp::plot(p1, col = "blue")

m2a <- rbind(c(19.6, 60.0),
             c(35.7, 58.8),
             c(28.2, 64.4),
             c(19.6, 60.0))
m2b <- rbind(c(20.6, 56.2),
             c(30.9, 53.8),
             c(27.3, 51.4),
             c(20.6, 56.2))
p2 <- list(sp::Polygon(m2a, FALSE), sp::Polygon(m2b, FALSE))
p2 <- sp::SpatialPolygons(list(sp::Polygons(p2, 2)))
sp::plot(p2, col = "red", add = TRUE)

p <- SetPolygons(p1, p2, "gIntersection")
sp::plot(p, col = "green", add = TRUE)

p <- SetPolygons(p2, p1, "gDifference")
sp::plot(p, col = "purple", add = TRUE)

inlmisc documentation built on Jan. 25, 2022, 1:14 a.m.