st_check_junctions: Check for missing road junctions

View source: R/check_topology.R

st_check_junctionsR Documentation

Check for missing road junctions

Description

Check if some road endings are close enough to be considered as being potentially part of a junction. Road endings that are actually touching are not considered. Fixing can be done by running st_snap_lines with the same tolerance value and the same road network.

Usage

st_check_junctions(roads, tolerance = 8)

Arguments

roads

multiples lines (sf format)

tolerance

numeric (distance unit). Tolerance value used to check if some road endings should have been snapped together.

Value

Polygon object (sf format) corresponding to circles of tolerance radius around the locations where junctions might be missing.

Examples

library(sf)

network   <- system.file("extdata", "j53e_network.gpkg", package="ALSroads")
network   <- st_read(network, "invalid_topology")
junctions <- st_check_junctions(network)

plot(st_geometry(network), axes = TRUE)
plot(st_geometry(junctions), add = TRUE, border = "red")

par(mfrow = c(1,2))
for (k in 1:2)
{
  junc <- junctions[k,]
  bbox <- st_bbox(junc)
  xlim <- bbox[c("xmin", "xmax")]
  ylim <- bbox[c("ymin", "ymax")]
  sub  <- paste0("Connected: ", junc[["nb_connected"]], "\nUnconnected: ", junc[["nb_unconnected"]])
  plot(st_geometry(junctions), col = "cyan", xlim = xlim, ylim = ylim, axes = TRUE)
  plot(st_geometry(network), col = "red", lwd = 3, add = TRUE)
  title(main = k, sub = sub)
}

# simple snapping (see ?st_snap_lines)
network <- st_snap_lines(network)$roads

par(mfrow = c(1,2))
for (k in 1:2)
{
  junc <- junctions[k,]
  bbox <- st_bbox(junc)
  xlim <- bbox[c("xmin", "xmax")]
  ylim <- bbox[c("ymin", "ymax")]
  sub  <- paste0("Connected: ", junc[["nb_connected"]], "\nUnconnected: ", junc[["nb_unconnected"]])
  plot(st_geometry(junctions), col = "cyan", xlim = xlim, ylim = ylim, axes = TRUE)
  plot(st_geometry(network), col = "red", lwd = 3, add = TRUE)
  title(main = k, sub = sub)
}

Jean-Romain/MFFProads documentation built on Nov. 19, 2024, 5:12 p.m.