luukvdmeer / sfnetworks

Tidy Geospatial Networks in R
https://luukvdmeer.github.io/sfnetworks/
Other
345 stars 20 forks source link

Add an `active = NULL` argument to st_coordinates.sfnetwork #215

Closed agila5 closed 2 years ago

agila5 commented 2 years ago

Is your feature request related to a problem? Please describe. I think st_coordinates may adopt the same shortcut as st_geometry or st_as_sf, i.e.

library(sf)
#> Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
library(sfnetworks)

sfc <- st_sfc(st_linestring(rbind(c(0, 0), c(1, 1), c(2, 2), c(3, 3))))
sfn <- as_sfnetwork(sfc)
st_geometry(sfn, "edges") # works
#> Geometry set for 1 feature 
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: 0 ymin: 0 xmax: 3 ymax: 3
#> CRS:           NA
#> LINESTRING (0 0, 1 1, 2 2, 3 3)
st_coordinates(sfn, "edges") # doesn't work since st_coordinates always return the active table
#>   X Y
#> 1 0 0
#> 2 3 3

Created on 2022-06-26 by the reprex package (v2.0.1)

Describe the solution you'd like We could add an active = NULL argument such that a call like st_coordinates(sfn, "edges") returns the coordinates of the edges table.

Describe alternatives you've considered We can just modify the active table, but also this addition shouldn't be really difficult. Moreover, IMO, it's surprising that the same pattern works only for st_geometry and sf_as_sf()

luukvdmeer commented 2 years ago

Added in v0.6.0. Also for st_bbox()