Learn R Programming

sfnetworks (version 0.2.0)

as_sfnetwork: Convert a foreign object to an sfnetwork object

Description

sfnetwork is a tidy data structure for spatial networks. It extends the graph manipulation functionalities of the tidygraph-package package into the domain of geospatial networks, where nodes are embedded in geographical space. It subclasses tbl_graph, and therefore all of tidygraphs functions should work as expected, without any conversion. Just as with a tbl_graph, the nodes are activated by default. The context can be changed using the activate verb and affects all subsequent operations. In sfnetworks, the nodes are handled as being an sf object with only POINT geometries, and can always be extracted with st_as_sf when activated. The edges can be handled as being an sf object with only LINESTRING geometries, but this is optional. When the edges do not have an explicit spatial component, they can always be extracted with as_tibble when activated.

Usage

as_sfnetwork(x, ...)

# S3 method for default as_sfnetwork(x, directed = TRUE, ...)

# S3 method for sf as_sfnetwork(x, directed = TRUE, edges_as_lines = TRUE, ...)

# S3 method for tbl_graph as_sfnetwork(x, ...)

Arguments

x

object to be converted into an sfnetwork object.

...

arguments passed on to construction function.

directed

Should the constructed network be directed? Defaults to TRUE.

edges_as_lines

Should the edges be spatially explict (i.e. have a LINESTRING geometries stored in a geometry list column)? Defaults to TRUE.

Value

An object of class sfnetwork.

Details

If an object can be read by as_tbl_graph and the nodes can be read by st_as_sf, it is automatically supported by sfnetworks.