Skip to contents

Neighbor lists are sparse adjacency matrices in list format that specify for each node to which other nodes it is adjacent. They occur for example in the sf package as sgbp objects, and are also frequently used in the spdep package.

Usage

nb_to_sfnetwork(
  x,
  nodes,
  directed = TRUE,
  edges_as_lines = TRUE,
  compute_length = FALSE,
  force = FALSE
)

sfnetwork_to_nb(x, direction = "out")

Arguments

x

For the conversion to sfnetwork: a neighbor list, which is a list adjacent to. For the conversion from sfnetwork: an object of class sfnetwork.

nodes

The nodes themselves as an object of class sf or sfc with POINT geometries.

directed

Should the constructed network be directed? Defaults to TRUE.

edges_as_lines

Should the created edges be spatially explicit, i.e. have LINESTRING geometries stored in a geometry list column? Defaults to TRUE.

compute_length

Should the geographic length of the edges be stored in a column named length? Defaults to FALSE.

force

Should validity checks be skipped? Defaults to FALSE, meaning that network validity checks are executed when constructing the network. These checks make sure that the provided neighbor list has a valid structure, i.e. that its length is equal to the number of provided nodes and that its values are all integers referring to one of the nodes.

direction

The direction that defines if two nodes are neighbors. Defaults to 'out', meaning that the direction given by the network is followed and node j is only a neighbor of node i if there exists an edge i->j. May be set to 'in', meaning that the opposite direction is followed and node j is only a neighbor of node i if there exists an edge j->i. May also be set to 'all', meaning that the network is considered to be undirected. This argument is ignored for undirected networks.

Value

For the conversion to sfnetwork: An object of class sfnetwork. For the conversion from sfnetwork: a neighbor list, which is a list with one element per node that holds the integer indices of the nodes it is adjacent to.