I am using the sfnetworks package of R to find the shortest path between points on a street network. The street network is imported from a shapefile and converted to a graph (using 'as_sfnetwork'). The output of my script is a dataframe (that I'm writing to a csv) which has a row for each pair of points that I am routing between.
The columns of the output dataframe are: | ID_from | ID_to | used_edges | used_nodes |
The script works and I'm getting the correct output (checked by plotting). used_edges gives me a list of the edges' ids that are part of the shortest path (as shown in the screenshot below). used_nodes works similarly but is not important to me.
Current output of the script with the graph's edges' id instead of the ids from the shapefile.
So, to get to my problem: the used_edges column contains information on the graph's edges' IDs while I actually require information on the edges' ID in the original shapefile. In the shapefile (my_shp.shp) the IDs I require are stored in the attribute 'LINK_ID'.
Is there a way I can replace the edges' ids from the graph with those from the shapefile? Might be a relatively simple thing, but I'm really biting my teeth out here.
Any help would be very welcome!