Learn R Programming

sfnetworks (version 0.4.1)

spatial_morphers: Spatial morphers for sfnetworks

Description

Spatial morphers form spatial add-ons to the set of morphers provided by tidygraph. These functions are not meant to be called directly. They should either be passed into morph to create a temporary alternative representation of the input network. Such an alternative representation is a list of one or more network objects. Single elements of that list can be extracted directly as a new network by passing the morpher to convert instead, to make the changes lasting rather than temporary. Alternatively, if the morphed state contains multiple elements, all of them can be extracted together inside a tbl_df by passing the morpher to crystallise.

Usage

to_spatial_directed(x)

to_spatial_explicit(x, ...)

to_spatial_shortest_paths(x, ...)

to_spatial_simple(x, remove_parallels = TRUE, remove_loops = TRUE)

to_spatial_smooth(x, store_orig_data = FALSE)

to_spatial_subdivision(x)

to_spatial_subset(x, ..., subset_by = NULL)

to_spatial_transformed(x, ...)

Arguments

x

An object of class sfnetwork.

...

Arguments to be passed on to other functions. See the description of each morpher for details.

remove_parallels

Should parallel edges be removed. Defaults to TRUE.

remove_loops

Should loops be remove. Defaults to TRUE.

store_orig_data

Whenever multiple features (i.e. nodes and/or edges) are merged into a single feature during morphing, should the data of the original features be stored as an attribute of the new feature, in a column named .orig_data. This is in line with the design principles of tidygraph. Defaults to FALSE.

subset_by

Whether to create subgraphs based on nodes or edges.

Value

Either a morphed_sfnetwork, which is a list of one or more sfnetwork objects, or a morphed_tbl_graph, which is a list of one or more tbl_graph objects. See the description of each morpher for details.

Functions

  • to_spatial_directed: Make a network directed in the direction given by the linestring geometries of the edges. Differs from to_directed, which makes a network directed based on the node indices given in the from and to columns. In undirected networks these indices may not correspond with the endpoints of the linestring geometries. Returns a morphed_sfnetwork containing a single element of class sfnetwork. This morpher requires edges to be spatially explicit. If not, use to_directed.

  • to_spatial_explicit: Create linestring geometries between source and target nodes of edges. If the edges data can be directly converted to an object of class sf using st_as_sf, extra arguments can be provided as ... and will be forwarded to st_as_sf internally. Otherwise, straight lines will be drawn between the source and target node of each edge. Returns a morphed_sfnetwork containing a single element of class sfnetwork.

  • to_spatial_shortest_paths: Limit a network to those nodes and edges that are part of the shortest path between two nodes. ... is evaluated in the same manner as st_network_paths with type = 'shortest'. Returns a morphed_sfnetwork that may contain multiple elements of class sfnetwork, depending on the number of requested paths. When unmorphing only the first instance of both the node and edge data will be used, as the the same node and/or edge can be present in multiple paths.

  • to_spatial_simple: Remove loops and parallel edges. Returns a morphed_sfnetwork containing a single element of class sfnetwork.

  • to_spatial_smooth: Construct a smoothed version of the network by iteratively removing pseudo nodes, while preserving the connectivity of the network. In the case of directed networks, pseudo nodes are those nodes that have only one incoming and one outgoing edge. In undirected networks, pseudo nodes are those nodes that have two incident edges. Connectivity of the network is preserved by concatenating the incident edges of each removed pseudo node. Returns a morphed_sfnetwork containing a single element of class sfnetwork.

  • to_spatial_subdivision: Construct a subdivision of the network by subdividing edges at each interior point that is equal to any other interior or boundary point in the edges table. Interior points in this sense are those points that are included in their linestring geometry feature but are not endpoints of it, while boundary points are the endpoints of the linestrings. The network is reconstructed after subdivision such that edges are connected at the points of subdivision. Returns a morphed_sfnetwork containing a single element of class sfnetwork. This morpher requires edges to be spatially explicit.

  • to_spatial_subset: Subset the network by applying a spatial filter, i.e. a filter on the geometry column based on a spatial predicate. ... is evaluated in the same manner as st_filter. Returns a morphed_sfnetwork containing a single element of class sfnetwork. For filters on an attribute column, use to_subgraph.

  • to_spatial_transformed: Transform the geospatial coordinates of the network into a different coordinate reference system. ... is evaluated in the same manner as st_transform. Returns a morphed_sfnetwork containing a single element of class sfnetwork.

Details

It also possible to create your own morphers. See the documentation of morph for the requirements for custom morphers.

See Also

The vignette on spatial morphers.

Examples

Run this code
# NOT RUN {
library(sf, quietly = TRUE)
library(tidygraph, quietly = TRUE)

net = as_sfnetwork(roxel, directed = FALSE) %>%
  st_transform(3035)

# Temporary changes with morph and unmorph.
net %>%
 activate("edges") %>%
 mutate(weight = edge_length()) %>%
 morph(to_spatial_shortest_paths, from = 1, to = 10) %>%
 mutate(in_paths = TRUE) %>%
 unmorph()

# Lasting changes with convert.
net %>%
 activate("edges") %>%
 mutate(weight = edge_length()) %>%
 convert(to_spatial_shortest_paths, from = 1, to = 10)

# }

Run the code above in your browser using DataLab