build_graph: Network generation

View source: R/graph_functions_sf.R

build_graphR Documentation

Network generation

Description

Generate an igraph object from a feature collection of linestrings

Usage

build_graph(lines, digits, line_weight, attrs = FALSE)

Arguments

lines

A feature collection of lines

digits

The number of digits to keep from the coordinates

line_weight

The name of the column giving the weight of the lines

attrs

A boolean indicating if the original lines' attributes should be stored in the final object

Details

This function can be used to generate an undirected 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.

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 linestrings;

  • 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))
graph_result <- build_graph(mtl_network, 2, "length", attrs = TRUE)

JeremyGelb/spNetwork documentation built on May 24, 2024, 7:23 p.m.