spatial_node_types: Query spatial node types

spatial_node_typesR Documentation

Query spatial node types

Description

These functions are a collection of node type queries that are commonly used in spatial network analysis, and form a spatial extension to node type queries in tidygraph.

Usage

node_is_pseudo()

node_is_dangling()

Details

Just as with all query functions in tidygraph, these functions are meant to be called inside tidygraph verbs such as mutate or filter, where the network that is currently being worked on is known and thus not needed as an argument to the function. If you want to use an algorithm outside of the tidygraph framework you can use with_graph to set the context temporarily while the algorithm is being evaluated.

Value

A logical vector of the same length as the number of nodes in the network, indicating if each node is of the type in question.

Functions

  • node_is_pseudo(): Pseudo nodes in directed networks are those nodes with only one incoming and one outgoing edge. In undirected networks pseudo nodes are those nodes with only two incident edges, i.e. nodes of degree 2.

  • node_is_dangling(): Dangling nodes are nodes with only one incident edge, i.e. nodes of degree 1.

Examples

library(sf, quietly = TRUE)
library(tidygraph, quietly = TRUE)

# Create a network.
net = as_sfnetwork(mozart, "mst", directed = FALSE)

# Use query function in a filter call.
pseudos = net |>
  activate(nodes) |>
  filter(node_is_pseudo())

danglers = net |>
  activate(nodes) |>
  filter(node_is_dangling())

oldpar = par(no.readonly = TRUE)
par(mar = c(1,1,1,1), mfrow = c(1,2))
plot(net, main = "Pseudo nodes")
plot(st_geometry(pseudos), pch = 20, cex = 1.2, col = "orange", add = TRUE)
plot(net, main = "Dangling nodes")
plot(st_geometry(danglers), pch = 20, cex = 1.2, col = "orange", add = TRUE)
par(oldpar)

# Use query function in a mutate call.
net |>
  activate(nodes) |>
  mutate(pseudo = node_is_pseudo(), dangling = node_is_dangling())

# Use query function directly.
danglers = with_graph(net, node_is_dangling())
head(danglers)


luukvdmeer/sfnetworks documentation built on Nov. 21, 2024, 4:54 a.m.