Learn R Programming

spNetwork (version 0.4.3)

split_lines_at_vertex: Split lines at vertices in a feature collection of linestrings

Description

Split lines (feature collection of linestrings) at their nearest vertices (feature collection of points), may fail if the line geometries are self intersecting.

Usage

split_lines_at_vertex(lines, points, nearest_lines_idx, mindist)

Arguments

lines

The feature collection of linestrings to split

points

The feature collection of points to add to as vertex to the lines

nearest_lines_idx

For each point, the index of the nearest line

mindist

The minimum distance between one point and the extremity of the line to add the point as a vertex.

Value

A feature collection of linestrings

Examples

Run this code
# NOT RUN {
# reading the data
networkgpkg <- system.file("extdata", "networks.gpkg", package = "spNetwork", mustWork = TRUE)
mtl_network <- sf::st_read(networkgpkg,layer="mtl_network")
eventsgpkg <- system.file("extdata", "events.gpkg", package = "spNetwork", mustWork = TRUE)
bike_accidents <- sf::st_read(eventsgpkg,layer="bike_accidents")
# aggregating points within a 5 metres radius
bike_accidents$weight <- 1
agg_points <- aggregate_points(bike_accidents, 5)
mtl_network$LineID <- 1:nrow(mtl_network)
# snapping point to lines
snapped_points <- snapPointsToLines2(agg_points,
    mtl_network,
    "LineID"
)
# splitting lines
new_lines <- split_lines_at_vertex(mtl_network, snapped_points,
    snapped_points$nearest_line_id, 1)
# }

Run the code above in your browser using DataLab