Union geometries to create MULTI* geometries in the case of different geometries. If geometries are identical, the union returns a single geometry. If you need to preserve all geometries, use sf::st_combine(). This function behaves differently than sf because it strictly returns 1 or length(x) geometries.

st_union(x, y, by_feature = TRUE)

Arguments

x

A geometry or a set of geometries of class sfc to be unioned.

y

(optional). A geometry or a set of geometries of class sfc.

by_feature

default is TRUE. Union each element of x with corresponding y element. If FALSE, all the features are first unioned row-wise, then all unioned together.

See also

Examples

library(tibble) library(dplyr) geom <- tibble( x = 1:3, y = 4:6, origin = st_point(x, y), destin = st_point(x + 1, y + 1) ) geom <- mutate(geom, union = st_union(origin, destin)) geom
#> # A tibble: 3 x 5 #> x y origin destin union #> <int> <int> <POINT> <POINT> <MULTIPOINT> #> 1 1 4 (1 4) (2 5) ((1 4), (2 5)) #> 2 2 5 (2 5) (3 6) ((2 5), (3 6)) #> 3 3 6 (3 6) (4 7) ((3 6), (4 7))
summarise(geom, union = st_union(origin, destin, by_feature = FALSE))
#> # A tibble: 1 x 1 #> union #> <MULTIPOINT> #> 1 ((1 4), (2 5), (3 6), (4 7))