as_tibble: Extract the active element of a sfnetwork as spatial tibble

as_tibbleR Documentation

Extract the active element of a sfnetwork as spatial tibble

Description

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.

Usage

## S3 method for class 'sfnetwork'
as_tibble(x, active = NULL, focused = TRUE, spatial = TRUE, ...)

Arguments

x

An object of class sfnetwork.

active

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.

focused

Should only features that are in focus be extracted? Defaults to TRUE. See focus for more information on focused networks.

spatial

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.

Value

The active element of the network as an object of class sf if a geometry list column is present and spatial = TRUE, and object of class tibble otherwise.

Examples

library(tibble, quietly = TRUE)

net = as_sfnetwork(roxel)

# Extract the active network element as a spatial tibble.
as_tibble(net)

# Extract any network element as a spatial tibble.
as_tibble(net, "edges")

# Extract the active network element as a regular tibble.
as_tibble(net, spatial = FALSE)


luukvdmeer/sfnetworks documentation built on Nov. 21, 2024, 4:54 a.m.