build_graph_directed {spNetwork} | R Documentation |
Directed network generation
Description
Generate a directed igraph object from a feature collection of linestrings
Usage
build_graph_directed(lines, digits, line_weight, direction, attrs = FALSE)
Arguments
lines |
A feature collection of linestrings |
digits |
The number of digits to keep from the coordinates |
line_weight |
The name of the column giving the weight of the lines |
direction |
A column name indicating authorized travelling direction on lines. if NULL, then all lines can be used in both directions. Must be the name of a column otherwise. The values of the column must be "FT" (From - To), "TF" (To - From) or "Both" |
attrs |
A boolean indicating if the original lines' attributes should be stored in the final object |
Details
This function can be used to generate a directed graph object (igraph object). It uses the coordinates of the linestrings extremities to create the nodes of the graph. This is why the number of digits in the coordinates is important. Too high precision (high number of digits) might break some connections. The column used to indicate directions can only have the following values: "FT" (From-To), "TF" (To-From) and "Both".
Value
A list containing the following elements:
graph: an igraph object;
linelist: the dataframe used to build the graph;
lines: the original feature collection of lines;
spvertices: a feature collection of points representing the vertices of the graph;
digits : the number of digits kept for the coordinates.
Examples
data(mtl_network)
mtl_network$length <- as.numeric(sf::st_length(mtl_network))
mtl_network$direction <- "Both"
mtl_network[6, "direction"] <- "TF"
mtl_network_directed <- lines_direction(mtl_network, "direction")
graph_result <- build_graph_directed(lines = mtl_network_directed,
digits = 2,
line_weight = "length",
direction = "direction",
attrs = TRUE)