st_snap_lines: Snap road endings

View source: R/snap_tools.R

st_snap_linesR Documentation

Snap road endings

Description

Snap road endings together, with or without prior knowledge on road connections, to post-process and correct inaccuracies generated by measure_roads and ensure getting topologically valid network. If argument 'ref' is missing the method is very basic. The method using a reference map is more advanced.

Usage

st_snap_lines(roads, ref, tolerance = 30, field = NULL, updatable = NULL)

Arguments

roads

multiple lines (sf format). Corrected but unconnected roads.

ref

multiple lines (sf format). Original non-corrected but connected roads. Can be missing.

tolerance

numeric (distance unit). Tolerance value used to snap the road endings.

field

character. Unique identifier field in both road datasets. Relevant only if 'ref' is not missing.

updatable

logical. Vector identifing which road segments need to be snapped (default is all segments). Relevant only if 'ref' is not missing.

Value

Named list with roads being the same object as roads but with corrected endings such that roads are connected and warnings being either NULL or a sf POINT identifying nodes with issues.

Examples

f <- system.file("extdata", "j53e_network.gpkg", package="ALSroads")

ref <- sf::st_read(f, layer = "original")  # input of measure_roads
cor <- sf::st_read(f, layer = "corrected") # output of measure_roads
res <- st_snap_lines(cor, ref, field = "OBJECTID")

plot(sf::st_geometry(ref), xlim = c(260800, 261000), ylim = c(5250400, 5250650), col = "red")
plot(sf::st_geometry(cor), col = "blue", add = TRUE)
plot(sf::st_geometry(res$roads), col = "green", add = TRUE, lwd = 2)

domain <- "https://servicesmatriciels.mern.gouv.qc.ca:443"
path <- "/erdas-iws/ogc/wmts/Inventaire_Ecoforestier/Inventaire_Ecoforestier/default/"
tiles <- "GoogleMapsCompatibleExt2:epsg:3857/{z}/{y}/{x}.jpg"
url <- paste0(domain, path, tiles)
m = mapview::mapview(list(ref, cor, res$roads),
  layer.name = c("Inaccurate", "Corrected", "Snapped"),
  color = c("red", "blue", "green"), map.type = "Esri.WorldImagery")
leaflet::addTiles(m@map, url)

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