Learn R Programming

trafficCAR (version 0.1.0)

build_adjacency: Build segment adjacency from segment geometries

Description

Constructs an undirected adjacency matrix `A` where segments are neighbors if they share a node (endpoint). Intended to be used after `roads_to_segments()`.

Usage

build_adjacency(segments, crs_m = 3857, tol = 0, verbose = FALSE)

Value

A list with:

A

Sparse symmetric adjacency matrix (`dgCMatrix`).

components

Integer vector component id (length n). Isolates are their own components.

isolates

Logical vector (length n).

Arguments

segments

An `sf` with LINESTRING geometries and (optionally) `seg_id`.

crs_m

Metric CRS used when `segments` is lon/lat (for robust node keys). Default 3857.

tol

Nonnegative numeric tolerance for snapping node coordinates (in meters if projected). If 0, uses exact coordinates. Default 0.

verbose

Logical; emit simple messages. Default FALSE.

Details

Isolates (degree 0) are kept (all-zero rows/cols). Connected components are returned for ICAR sum-to-zero centering per component.