linestrings_to_graph: Convert Linestring to Graph

View source: R/utils.R

linestrings_to_graphR Documentation

Convert Linestring to Graph

Description

Convert Linestring to Graph

Usage

linestrings_to_graph(
  lines,
  digits = 6,
  keep.cols = is.atomic,
  compute.length = TRUE
)

Arguments

lines

An sf data frame of LINESTRING geometries.

digits

Numeric rounding applied to coordinates (to ensure that matching points across different linestrings is not impaired by numeric precision issues). Set to NA/Inf/FALSE to disable.

keep.cols

Character vector of column names to keep from the input data frame.

compute.length

Applies st_length() to and saves it as an additional column named ".length".

Value

A data.frame representing the graph with columns:

  • edge - Edge identifier

  • from - Starting node ID

  • FX - Starting node X-coordinate (longitude)

  • FY - Starting node Y-coordinate (latitude)

  • to - Ending node ID

  • TX - Ending node X-coordinate (longitude)

  • TY - Ending node Y-coordinate (latitude)

See Also

simplify_network flownet-package

Examples

library(flownet)
library(sf)

# Load existing network edges (exclude proposed new links)
africa_net <- africa_network[!africa_network$add, ]

# Convert network LINESTRING geometries to graph
graph <- linestrings_to_graph(africa_net)
head(graph)

# Graph contains edge, from/to nodes, and coordinates
names(graph)


flownet documentation built on March 22, 2026, 9:06 a.m.