Learn R Programming

stplanr (version 0.4.0)

rnet_breakup_vertices: Break up an sf object with LINESTRING geometry by vertex/nodes intersections

Description

Break up an sf object with LINESTRING geometry by vertex/nodes intersections

Usage

rnet_breakup_vertices(rnet, breakup_internal_vertex_matches = TRUE)

Arguments

rnet

An sf LINESTRING object representing a route network.

breakup_internal_vertex_matches

Should breaks be made at internal vertex matches? TRUE by default. Internal vertices are vertices (but not start or end points) of two or more different linestrings that meet at the same point.

Value

The same sf LINESTRING object with more rows (the result of the splitting) when there are intersecting (and internal) vertices.

Examples

Run this code
# NOT RUN {
library(sf)
par(mar = rep(0, 4))

# Check for roundabout
plot(rnet_roundabout$geometry, lwd = 2, col = rainbow(nrow(rnet_roundabout)))

rnet_roundabout_clean <- rnet_breakup_vertices(rnet_roundabout)
plot(rnet_roundabout_clean$geometry, lwd = 2, col = rainbow(nrow(rnet_roundabout_clean)))
# Check for overpasses
plot(rnet_overpass$geometry, lwd = 2, col = rainbow(nrow(rnet_overpass)))

rnet_overpass_clean <- rnet_breakup_vertices(rnet_overpass)
plot(rnet_overpass_clean$geometry, lwd = 2, col = rainbow(nrow(rnet_overpass_clean)))
# }
# NOT RUN {
# mapview(rnet_overpass_clean)
# }
# NOT RUN {
# Check for intersection with no node
plot(rnet_cycleway_intersection$geometry, lwd = 2,
     col = rainbow(nrow(rnet_cycleway_intersection)))

rnet_cycleway_intersection_clean <- rnet_breakup_vertices(rnet_cycleway_intersection)
plot(rnet_cycleway_intersection_clean$geometry,
     lwd = 2, col = rainbow(nrow(rnet_cycleway_intersection_clean)))

# Bigger example
# }
# NOT RUN {
u <- "https://download.geofabrik.de/europe/great-britain/england/isle-of-wight-latest.osm.pbf"
iow <- sf::st_read(u)

key_roads_text = "primary|secondary|tertiary|cycleway|trunk|motorway"
iow_small <- iow[grepl(pattern = key_roads_text, x = iow$highway), ]
system.time(iow_clean <- rnet_breakup_vertices(iow_small))
# Should be quite faster than the old version we could always profile it.

plot(iow_small$geometry)
plot(iow_clean$geometry)
# }

Run the code above in your browser using DataLab