Learn R Programming

flownet (version 0.2.1)

linestrings_to_graph: Convert Linestring to Graph

Description

Convert Linestring to Graph

Usage

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

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)

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".

See Also

simplify_network flownet-package

Examples

Run this code
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)

Run the code above in your browser using DataLab