spatial_morphers {sfnetworks}R Documentation

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_contracted(
  x,
  ...,
  simplify = FALSE,
  summarise_attributes = "ignore",
  store_original_data = FALSE
)

to_spatial_directed(x)

to_spatial_explicit(x, ...)

to_spatial_neighborhood(x, node, threshold, weights = NULL, from = TRUE, ...)

to_spatial_shortest_paths(x, ...)

to_spatial_simple(
  x,
  remove_multiple = TRUE,
  remove_loops = TRUE,
  summarise_attributes = "first",
  store_original_data = FALSE
)

to_spatial_smooth(
  x,
  protect = NULL,
  summarise_attributes = "ignore",
  require_equal = FALSE,
  store_original_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.

simplify

Should the network be simplified after contraction? This means that multiple edges and loop edges will be removed. Multiple edges are introduced by contraction when there are several connections between the same groups of nodes. Loop edges are introduced by contraction when there are connections within a group. Note however that setting this to TRUE also removes multiple edges and loop edges that already existed before contraction. Defaults to FALSE.

summarise_attributes

Whenever multiple features (i.e. nodes and/or edges) are merged into a single feature during morphing, how should their attributes be combined? Several options are possible, see igraph-attribute-combination for details.

store_original_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.

node

The geospatial point for which the neighborhood will be calculated. Can be an integer, referring to the index of the node for which the neighborhood will be calculated. Can also be an object of class sf or sfc, containing a single feature. In that case, this point will be snapped to its nearest node before calculating the neighborhood. When multiple indices or features are given, only the first one is taken.

threshold

The threshold distance to be used. Only nodes within the threshold distance from the reference node will be included in the neighborhood. Should be a numeric value in the same units as the weight values used for distance calculation.

weights

The edge weights used to calculate distances on the network. Can be a numeric vector giving edge weights, or a column name referring to an attribute column in the edges table containing those weights. If set to NULL, the values of a column named weight in the edges table will be used automatically, as long as this column is present. If not, the geographic edge lengths will be calculated internally and used as weights.

from

Should distances be calculated from the reference node towards the other nodes? Defaults to TRUE. If set to FALSE, distances will be calculated from the other nodes towards the reference node instead.

remove_multiple

Should multiple edges be merged into one. Defaults to TRUE.

remove_loops

Should loop edges be removed. Defaults to TRUE.

protect

Nodes to be protected from being removed, no matter if they are a pseudo node or not. Can be given as a numeric vector containing node indices or a character vector containing node names. Can also be a set of geospatial features as object of class sf or sfc. In that case, for each of these features its nearest node in the network will be protected. Defaults to NULL, meaning that none of the nodes is protected.

require_equal

Should nodes only be removed when the attribute values of their incident edges are equal? Defaults to FALSE. If TRUE, only pseudo nodes that have incident edges with equal attribute values are removed. May also be given as a vector of attribute names. In that case only those attributes are checked for equality. Equality tests are evaluated using the == operator.

subset_by

Whether to create subgraphs based on nodes or edges.

Details

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

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

See Also

The vignette on spatial morphers.

Examples

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)


[Package sfnetworks version 0.6.4 Index]