Skip to contents

Combine groups of nodes into a single node per group. The centroid such a group will be used by default as new geometry of the contracted node. If edges are spatially explicit, edge geometries are updated accordingly such that the valid spatial network structure is preserved.

Usage

contract_nodes(
  x,
  groups,
  simplify = TRUE,
  compute_centroids = TRUE,
  reconnect_edges = TRUE,
  attribute_summary = "ignore",
  store_original_ids = FALSE,
  store_original_data = FALSE
)

Arguments

x

An object of class sfnetwork.

groups

A group index for each node in x.

simplify

Should the network be simplified after contraction? Defaults to TRUE. 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.

compute_centroids

Should the new geometry of each contracted group of nodes be the centroid of all group members? Defaults to TRUE. If set to FALSE, the geometry of the first node in each group will be used instead, which requires considerably less computing time.

reconnect_edges

Should the geometries of the edges be updated such they match the new node geometries? Defaults to TRUE. Only set this to FALSE if you know the node geometries did not change, otherwise the valid spatial network structure is broken.

attribute_summary

How should the attributes of contracted nodes be summarized? There are several options, see igraph-attribute-combination for details.

store_original_ids

For each group of contracted nodes, should the indices of the original nodes be stored as an attribute of the new edge, in a column named .tidygraph_node_index? This is in line with the design principles of tidygraph. Defaults to FALSE.

store_original_data

For each group of contracted nodes, should the data of the original nodes be stored as an attribute of the new edge, in a column named .orig_data? This is in line with the design principles of tidygraph. Defaults to FALSE.

Value

The contracted network as object of class sfnetwork.