I have a set of origin-destination coordinates that I want to calculate the shortest paths between them.
My origin-destination coordinates are sometimes located in the middle of a long straight-line road. However, the shortest path calculated by OSMnx/networkx will not consider that mid-edge to nearest-node path.
Is there any ready function in OSMnx or networkx that I can use to find shortest path that originates/ends in the middle of the road?
If there is no such function, I am thinking of using the following steps.
- Get nearest edges of origin and destination
- Get nodes of those nearest edges: let's say (a,b) for origin, and (c,d) for destination
- Calculate distance of 4 possible combinations: a->c, a->d, b->c, b->d
- Project origin/destination onto their nearest edges: let's call them o1 and e1
- Calculate distance o1->a, o1->b, e1->c, e1->d
- Add (5) distance to (3): to get
- o1->a->c->e1
- o1->a->d->e1
- o1->b->c->e1
- o1->b->d->e1
- Select path with smallest distance