Learn R Programming

spNetwork (version 0.2.1)

build_graph: Network generation

Description

Generate an igraph object from a SpatialLinesDataFrame.

Usage

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

Arguments

lines

A SpatialLinesDataFrame

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

Value

A list containing the following elements:

  • graph: an igraph object

  • linelist: the dataframe used to build the graph

  • lines: the original SpatialLinesDataFrame

  • spvertices: a SpatialPointsDataFrame representing the vertices of the graph

  • digits : the number of digits kept for the coordinates

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 a precision (high number of digits) might break some connections.

Examples

Run this code
# NOT RUN {
networkgpkg <- system.file("extdata", "networks.gpkg", package = "spNetwork", mustWork = TRUE)
mtl_network <- rgdal::readOGR(networkgpkg,layer="mtl_network", verbose=FALSE)
mtl_network$length <- rgeos::gLength(mtl_network, byid = TRUE)
graph_result <- build_graph(mtl_network, 2, "length", attrs = TRUE)
# }

Run the code above in your browser using DataLab