Learn R Programming

flownet (version 0.2.1)

linestrings_from_graph: Convert Graph to Linestrings

Description

Convert a graph data frame with node coordinates to an sf object with LINESTRING geometries.

Usage

linestrings_from_graph(graph_df, crs = 4326)

Value

An sf data frame with LINESTRING geometry, containing all columns from

graph_df except FX, FY, TX, and TY. Each row represents an edge as a LINESTRING connecting the from-node (FX, FY) to the to-node (TX, TY).

Arguments

graph_df

A data frame representing a graph with columns: FX, FY, TX, TY (starting and ending node coordinates), and optionally other columns to preserve.

crs

Numeric or character (default: 4326). Coordinate reference system to assign to the output sf object.

Details

This function is the inverse operation of linestrings_to_graph. It:

  • Creates LINESTRING geometries from node coordinates (FX, FY, TX, TY)

  • Removes the coordinate columns from the output

  • Preserves all other columns from the input graph data frame

  • Returns an sf object suitable for spatial operations and visualization

See Also

linestrings_to_graph flownet-package

Examples

Run this code
library(flownet)
library(sf)

# Convert segments data frame to sf LINESTRING object
segments_sf <- linestrings_from_graph(africa_segments)
class(segments_sf)
head(segments_sf)

# \donttest{
# Plot segments colored by route importance
plot(segments_sf["passes"])
# }

Run the code above in your browser using DataLab