self_union {bcmaps}R Documentation

Union a SpatialPolygons* object with itself to remove overlaps, while retaining attributes

Description

The IDs of source polygons are stored in a list-column called union_ids, and original attributes (if present) are stored as nested dataframes in a list-column called union_df

Usage

self_union(x)

Arguments

x

A SpatialPolygons or SpatialPolygonsDataFrame object

Value

A SpatialPolygons or SpatialPolygonsDataFrame object

Examples

if (require(sp)) {
  p1 <- Polygon(cbind(c(2,4,4,1,2),c(2,3,5,4,2)))
  p2 <- Polygon(cbind(c(5,4,3,2,5),c(2,3,3,2,2)))

  ps1 <- Polygons(list(p1), "s1")
  ps2 <- Polygons(list(p2), "s2")

  spp <- SpatialPolygons(list(ps1,ps2), 1:2)

  df <- data.frame(a = c("A", "B"), b = c("foo", "bar"),
                   stringsAsFactors = FALSE)

  spdf <- SpatialPolygonsDataFrame(spp, df, match.ID = FALSE)

  plot(spdf, col = c(rgb(1, 0, 0,0.5), rgb(0, 0, 1,0.5)))

  unioned_spdf <- self_union(spdf)
  unioned_sp <- self_union(spp)
}

[Package bcmaps version 1.0.2 Index]