Extract parts of one type from geometry collections
Source:R/extendr-wrappers.R
ga_collection_extract.RdGathers the points, lines, or polygons of each geometry into a single
multipoint, multilinestring, or multipolygon. ga_collection_extract()
flattens nested collections and multi part members in order.
Details
Unlike sf::st_collection_extract(), ga_collection_extract() keeps one
row per input row. It returns a null for a geometry with no parts of
geometry_type, such as a linestring when you ask for polygons, and for a
null geometry.
Examples
gc <- sf::st_geometrycollection(list(
sf::st_point(c(5, 5)),
sf::st_polygon(list(rbind(c(0, 0), c(1, 0), c(1, 1), c(0, 0))))
))
g <- geoarrow::as_geoarrow_array(sf::st_sfc(gc, sf::st_point(c(0, 0))))
# the point has no polygons, so its row is null
as.vector(ga_geometry_type(ga_collection_extract(g, "POLYGON")))
#> [1] "MULTIPOLYGON" NA