I have a shapefile of all street segments in Los Angeles County that I have made sure is clean. I am able to use the QGIS Road Graph plugin to calculate various shortest paths, see attached as my first example.
I am getting an error when trying to use the NetworkX shortest_path on my network. I am loading a shapefile (roughly 410,000 edges). My route start and end points are well known and ON the network. There are probably better data structures, but i have created a dictionary of Points with values of what i believe to be the street segment keys, though not sure (from docs: Coordinate tuples are used as keys).
Error:
.... weighted.py", line 359, in _dijkstra
for u, e in G_succ[v].items():
KeyError: ((-118.3162743390968, 34.25880839639892), (-118.31575202245774, 34.25880723483486))
I verified that this street segment listed in the KeyError is in the edges list as I wrote all edges to file.
I am now going to start diagnosing the weighted.py code.
Core code snippets:
def InitRoadGraph():
self.roadGraph = nx.read_shp(self.roadsrc)
self.StreetNodeFromDict = {}
for edge in self.roadGraph.edges(data=True):
self.StreetNodeFromDict[edge[0]] = (edge[0], edge[1])
def GetStreetIDFromNodeSimple(self, geometry_point):
return self.StreetNodeFromDict[geometry_point]
def GetShortestRoute(self, srcPoint, dstStreetSegmentID):
srcSegmentID = self.GetStreetIDFromNodeSimple(srcPoint, "FNODE_")
shortestRoute = nx.shortest_path(self.roadGraph, srcSegmentID, dstStreetSegmentID)[![enter image description here][1]][1]