st_snap_lines | R Documentation |
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.
st_snap_lines(roads, ref, tolerance = 30, field = NULL, updatable = NULL)
roads |
multiple lines ( |
ref |
multiple lines ( |
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. |
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.