Hi,
You are correct. You need to find the closest node and create a
new edge between the beginning of your route and the graph. More
knowledgeable people tell you what functions to use in NetworkX.
If I recall, you are doing this with geographic data. You may
chose to use Geopandas to introduce new nodes and edges to the
graph.
I created a tie_outside_node()
function. This will not find the nearest node but will find
the nearest edge (a road, a river...), split it in two edges,
calculate the new lengths,and add the appropriate nodes to the
graph. Is a bit complicated because I modify the graph on the
fly in order to keep the smallest graph possible. This has
the advantage of tying the source node (where you start the
trip) to the nearest "road" or "river" that may be very close.
If you connect only to the closest node, the entire length of
the road will be added to the calculation.
This paper explains the algorithm.
https://www.mdpi.com/2306-5729/5/1/8
Nicolas
From what I understand, Dijkstra's algorithm can only find routes to and from nodes. However, I may need to trace paths to objects that are near edges, but not near existing nodes. Is there a way, in Networkx, to add a new node near an object onto the nearest edge?
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/networkx-discuss/ba6988e8-6bfa-48d1-9bf7-00dd571ca5ean%40googlegroups.com.
-- Nicolas Cadieux https://gitlab.com/njacadieux