Skip to contents

Calculate centrality indexes from a directed stream network graph. By switching the mode to either "in", "out" or "all", only the upstream, downstream or all connected segments will be considered, respectively. The function read_geopackage() can be used to create the input network graph.

Usage

get_centrality(g, index = "all", mode = NULL)

Arguments

g

igraph object. A directed graph.

index

character. One of "all", "closeness", "farness", "betweenness", "degree", "eccentricity". See @Details

mode

character. One of "in", "out" or "all". Defines whether the shortest paths to (upstream) or from (downstream) the given segments/sub-catchments should be calculated. If "out", then only downstream segments will be considered. If "in", then only upstream segments will be considered. If "all", then the flow direction will be ignored and all streams will be considered.

Value

A data.table that reports all subc_id and their centrality values.

Details

The degree of a node is the number of its adjacent edges. Closeness centrality measures how many steps are required to access every other node from a given node Farness centrality is the sum of the length of the shortest paths between the node and all other nodes. It is the reciprocal of closeness (Altermatt, 2013). The eccentricity of a node is its shortest path distance from the farthest other node in the graph (West, 1996). The node betweenness is (roughly) defined by the number of geodesics (shortest paths) going through a node.

References

Csardi G, Nepusz T: The igraph software package for complex network research, InterJournal, Complex Systems 1695. 2006. https://igraph.org

See also

read_geopackage() to create a network graph.

Author

Afroditi Grigoropoulou

Examples

# Download test data into the temporary R folder
# or define a different directory
my_directory <- tempdir()
download_test_data(my_directory)

# Load stream network as a graph
my_graph <- read_geopackage(gpkg = paste0(my_directory,
                                         "/hydrography90m_test_data",
                                         "/order_vect_59.gpkg"),
                           import_as = "graph")

# Get the all the centrality indexes
centrality <- get_centrality(g = my_graph, index = "all", mode = "in")

# Load stream network as a vector
stream_vect <- read_geopackage(gpkg = paste0(my_directory,
                                             "/hydrography90m_test_data",
                                             "/order_vect_59.gpkg"),
                               import_as = "SpatVect")

# Merge the centrality table with the vector
stream_vect <- terra::merge(stream_vect, centrality,
                            by.x = c('stream'), by.y="subc_id")

# Write out the stream network vector including the centrality indices
writeVector(stream_vect, paste0(my_directory,
                                "/hydrography90m_test_data",
                                "/order_vect_59_centr.gpkg"))