Skip to contents

Returns a list the same length as the input, where each element is an array of that geometry's constituent parts. ga_explode() turns a multipolygon of three polygons into 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

ga_explode() returns the singular form of the input geometry type:

inputelement type
multipoint, pointpoint
multilinestring, linestringlinestring
multipolygon, polygonpolygon

ga_explode() decides the element type from the array's declared type, not from its contents, so it still returns polygons for an array of multipolygons that all happen to hold one part. ga_explode() raises an error for a mixed geometry array, which has no single singular type; narrow it with ga_downcast_geometry() first.

ga_explode() returns an element of length one for a singular geometry, so it handles any input. For a null geometry, it returns a null element, which is distinct from an empty one.

Because ga_explode() preserves length, you can keep the result alongside the other columns of a table, each element in line with its source row. 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