union: Combine two GVectors

union,GVector,GVector-methodR Documentation

Combine two GVectors

Description

The union() function combines two "polygons" GVectors. The output will have at least as many geometries as both GVectors, plus more if polygons of one divide polygons of the other, and vice versa. You can also use the + operator (e.g., vect1 + vect2).

Usage

## S4 method for signature 'GVector,GVector'
union(x, y)

Arguments

x, y

GVectors representing polygons.

Value

A GVector.

See Also

c(), aggregate(), crop(), intersect(), xor(), erase()

Examples

if (grassStarted()) {

# Setup
library(sf)

# Polygon of coastal Madagascar and Dypsis specimens
madCoast4 <- fastData("madCoast4") # polygons
madDypsis <- fastData("madDypsis") # points

# Convert vectors:
coast4 <- fast(madCoast4)
dypsis <- fast(madDypsis)

# Create another polygons vector from a convex hull around Dypsis points
hull <- convHull(dypsis)

### union()
###########

unioned <- union(coast4, hull)
plot(unioned)

plus <- coast4 + hull # same as union()

### intersect
#############

inter <- intersect(coast4, hull)
plot(coast4)
plot(hull, border = "red", add = TRUE)
plot(inter, border = "blue", add = TRUE)

### xor
#######

xr <- xor(coast4, hull)
plot(coast4)
plot(xr, border = "blue", add = TRUE)

### erase
#########

erased <- erase(coast4, hull)
plot(coast4)
plot(erased, border = "blue", add = TRUE)

minus <- coast4 - hull # same as erase()

}

adamlilith/fasterRaster documentation built on Oct. 26, 2024, 4:06 p.m.