Skip to contents

Returns a list the same length as the input, where each element is an array of that geometry's constituent parts. A multipolygon of three polygons becomes one element holding a polygon array of length three.

Usage

ga_explode(x)

Arguments

x

a GeoArrow geometry array

Value

a list array of the same length as x, whose elements are GeoArrow arrays

Details

The output geometry type is the singular form of the input:

inputelement type
multipoint, pointpoint
multilinestring, linestringlinestring
multipolygon, polygonpolygon

The element type is decided by the array's declared type, not by its contents, so an array of multipolygons that all happen to hold one part still explodes to polygons. A mixed geometry array has no single singular type and errors; narrow it with ga_downcast_geometry() first.

A singular geometry yields an element of length one, so the operation is well defined for any input. A null geometry yields a null element, which is distinct from an empty one.

Because the length is preserved, the result lines up with the row it came from and can sit alongside the other columns of a table. Use ga_flatten() to collapse it into a single array with one row per part.

Examples

fp <- system.file("shape/nc.shp", package = "sf")
nc <- as.data.frame(read_shapefile(fp))

# one list element per county, holding that county's polygon parts
parts <- ga_explode(nc$geometry)
parts$length
#> [1] 100
head(lengths(as.vector(parts)))
#> [1] 1 1 1 3 1 1