The sfnetwork method for as_tibble
is conceptually
different. Whenever a geometry list column is present, it will by default
return what we call a 'spatial tibble'. With that we mean an object of
class c('sf', 'tbl_df')
instead of an object of class
'tbl_df'
. This little conceptual trick is essential for how
tidyverse functions handle sfnetwork
objects, i.e. always
using the corresponding sf
method if present. When using
as_tibble
on sfnetwork
objects directly
as a user, you can disable this behaviour by setting spatial = FALSE
.
# S3 method for class 'sfnetwork'
as_tibble(x, active = NULL, spatial = TRUE, ...)
An object of class sfnetwork
.
Which network element (i.e. nodes or edges) to activate before
extracting. If NULL
, it will be set to the current active element of
the given network. Defaults to NULL
.
Should the extracted tibble be a 'spatial tibble', i.e. an
object of class c('sf', 'tbl_df')
, if it contains a geometry list
column. Defaults to TRUE
.
Arguments passed on to as_tibble
.
The active element of the network as an object of class
tibble
.
library(tibble, quietly = TRUE)
net = as_sfnetwork(roxel)
# Extract the active network element as a spatial tibble.
as_tibble(net)
#> Simple feature collection with 701 features and 0 fields
#> Geometry type: POINT
#> Dimension: XY
#> Bounding box: xmin: 7.522622 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#> Geodetic CRS: WGS 84
#> # A tibble: 701 × 1
#> geometry
#> <POINT [°]>
#> 1 (7.533722 51.95556)
#> 2 (7.533461 51.95576)
#> 3 (7.532442 51.95422)
#> 4 (7.53209 51.95328)
#> 5 (7.532709 51.95209)
#> 6 (7.532869 51.95257)
#> 7 (7.540063 51.94468)
#> 8 (7.53822 51.94546)
#> 9 (7.537673 51.9475)
#> 10 (7.537614 51.94562)
#> # ℹ 691 more rows
# Extract any network element as a spatial tibble.
as_tibble(net, "edges")
#> Simple feature collection with 851 features and 4 fields
#> Geometry type: LINESTRING
#> Dimension: XY
#> Bounding box: xmin: 7.522594 ymin: 51.94151 xmax: 7.546705 ymax: 51.9612
#> Geodetic CRS: WGS 84
#> # A tibble: 851 × 5
#> from to name type geometry
#> <int> <int> <chr> <fct> <LINESTRING [°]>
#> 1 1 2 Havixbecker Strasse residential (7.533722 51.95556, 7.533461 5…
#> 2 3 4 Pienersallee secondary (7.532442 51.95422, 7.53236 51…
#> 3 5 6 Schulte-Bernd-Strasse residential (7.532709 51.95209, 7.532823 5…
#> 4 7 8 NA path (7.540063 51.94468, 7.539696 5…
#> 5 9 10 Welsingheide residential (7.537673 51.9475, 7.537614 51…
#> 6 11 12 NA footway (7.543791 51.94733, 7.54369 51…
#> 7 13 14 NA footway (7.54012 51.94478, 7.539931 51…
#> 8 8 10 NA path (7.53822 51.94546, 7.538131 51…
#> 9 7 15 NA track (7.540063 51.94468, 7.540338 5…
#> 10 16 17 NA track (7.5424 51.94599, 7.54205 51.9…
#> # ℹ 841 more rows
# Extract the active network element as a regular tibble.
as_tibble(net, spatial = FALSE)
#> # A tibble: 701 × 1
#> geometry
#> <POINT [°]>
#> 1 (7.533722 51.95556)
#> 2 (7.533461 51.95576)
#> 3 (7.532442 51.95422)
#> 4 (7.53209 51.95328)
#> 5 (7.532709 51.95209)
#> 6 (7.532869 51.95257)
#> 7 (7.540063 51.94468)
#> 8 (7.53822 51.94546)
#> 9 (7.537673 51.9475)
#> 10 (7.537614 51.94562)
#> # ℹ 691 more rows