Connect coordinates to the nearest nodes in the road network
coords_to_node can be used to find the nearest nodes in the Norwegian road network (in meters) for chosen coordinates.
coords_to_node( coords, nodes_object = nodes, edges_object = edges, direction = "from", ID_col = "ID", crs_out = 25833, knn = 1, membership = FALSE )
sfobject with the coordinates that should be connected to the road network.
sfobject with the nodes of the road network. This can be created with the function
A data frame with the edges of the road network. This can be created with the function
Character vector with
fromif the points should be from nodes or
toif the points should be to nodes.
Character vector with the name of the ID column. Default value is set to “ID”.
Numeric vector for the chosen coordinate reference system (CRS).
Numeric vector with the chosen number of nodes that should be returned for each of the coordinates. If
knn = 1only the nearest nodes to the chosen coordinates will be returned. If
knn = 2the two nearest nodes will be returned etc.
TRUEthe search for nodes is limited to nodes that belong to a road network that is connected either to the from or to nodes (only possible for either from or to). E.g. if you only want to search for from nodes that belong to the same road network as the to nodes, membership is set to
FALSEin the search for to nodes and
membership = TRUEfor the from nodes (in that order).
An object (
data.frame) with the following columns;
Before the function can be used, the nodes of the road network must be converted to an
sf object that is called
nodes (or another name supplied to the
nodes_object argument). This can be done with the function
coords <- address_to_coords(zip_code = "0185", address = "Schweigaards gate 10") coords_to_node(coords = coords, direction = "from", nodes_object = nodes_sampledata, edges_object = edges_sampledata) #> from_nodeID membership_from_node coords_google_from_node #> 973 983 187 59.9115557969023, 10.7576325239472 #> knn_from_node ID dist_coord_node_from #> 973 1 1 32.15084