Takes an `sf` object of LINESTRING/MULTILINESTRING road geometries and returns a segment-level `sf` with stable segment IDs and metric lengths.
roads_to_segments(
roads,
crs_m = 3857,
keep_attrs = NULL,
drop_zero = TRUE,
split_at_intersections = FALSE,
verbose = FALSE
)An `sf` with columns: * `seg_id` integer 1..n * `length_m` numeric meters * geometry LINESTRING plus kept attributes.
An `sf` object with LINESTRING or MULTILINESTRING geometries.
Metric CRS used for length calculation (and intersection splitting) when `roads` is lon/lat. Default 3857. For best accuracy, pass a local UTM EPSG.
Optional character vector of non-geometry columns to keep. If `NULL`, keeps all attributes.
Logical; drop segments with non-positive length. Default TRUE.
Logical; if TRUE, split lines at all intersections. Implemented via GEOS noding (`sf::st_union` + `sf::st_cast`) Default FALSE.
Logical; emit simple messages about dropped rows. Default FALSE.
v1 behavior: * Drops Z/M dimensions * Casts MULTILINESTRING -> LINESTRING (one row per linestring) * Optionally splits at intersections (noding) when `split_at_intersections=TRUE` * Computes `length_m` in meters (projects if lon/lat) * Drops empty and (optionally) zero-length segments