Skip to contents

Reduce GEOMETRYCOLLECTION geometries to their polygon parts

Usage

extract_polygon_collection(layer)

Arguments

layer

An sf object that may contain GEOMETRYCOLLECTION geometries.

Value

The sf object with each GEOMETRYCOLLECTION replaced by its combined polygon parts (empty polygon if it has none).

Examples

polygon <- sf::st_polygon(list(rbind(
  c(0, 0), c(1, 0), c(1, 1), c(0, 0)
)))
collection <- sf::st_geometrycollection(list(polygon))
layer <- sf::st_sf(
  name = "Example",
  geometry = sf::st_sfc(collection, crs = 4326)
)
extract_polygon_collection(layer)
#> Simple feature collection with 1 feature and 1 field
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 0 ymin: 0 xmax: 1 ymax: 1
#> Geodetic CRS:  WGS 84
#>      name                       geometry
#> 1 Example MULTIPOLYGON (((0 0, 1 0, 1...