Skip to contents

The function coords_to_node can be used to find the nearest nodes in the Norwegian road network (in meters) for chosen coordinates.


  nodes_object = nodes,
  edges_object = edges,
  direction = "from",
  ID_col = "ID",
  crs_out = 25833,
  knn = 1,
  membership = FALSE



An sf object with the coordinates that should be connected to the road network.


An sf object with the nodes of the road network. This can be created with the function vegnett_to_R().


A data frame with the edges of the road network. This can be created with the function vegnett_to_R().


Character vector with from if the points should be from nodes or to if 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 = 1 only the nearest nodes to the chosen coordinates will be returned. If knn = 2 the two nearest nodes will be returned etc.


Logical. If TRUE the 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 FALSE in the search for to nodes and membership = TRUE for the from nodes (in that order).


An object (data.frame) with the following columns; from_nodeID/to_nodeID, membership_from_node/membership_to_node, coords_google_from_node/coords_google_to_node, knn_from_node/knn_to_node, and ID.


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 vegnett_to_R().


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