Skip to content

Feature Request: multiple casts in to argument #2233

Open
@JosiahParry

Description

@JosiahParry

It is common that I will want to expand a multipolygon into its component linestrings. To do this I will have to cast the geometry multiple times. For example:

library(sf)
nc_path <- system.file("shape/nc.shp", package = "sf")

nc <- st_read(nc_path, quiet = TRUE) |> 
  st_geometry()

nc |> 
  st_cast("MULTILINESTRING") |> 
  st_cast("LINESTRING")
#> Geometry set for 108 features 
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965
#> Geodetic CRS:  NAD27
#> First 5 geometries:
#> LINESTRING (-81.47276 36.23436, -81.54084 36.27...
#> LINESTRING (-81.23989 36.36536, -81.24069 36.37...
#> LINESTRING (-80.45634 36.24256, -80.47639 36.25...
#> LINESTRING (-76.00897 36.3196, -76.01735 36.337...
#> LINESTRING (-76.02717 36.55672, -75.99866 36.55...

It would be a quite nice experience to be able to provide a character vector of length 2, 3, etc to specify the casts in order. For example it would be nice to be able to rewrite the above as:

nc |> 
  st_cast(c("MULTILINESTRING", "LINESTRING"))

Created on 2023-09-12 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions