I created a Graph
with Networkx
and its nodes look like the following:
dict(itertools.islice(H.nodes.items(), 3))
> {{'node1': 'lon': coordx_1,
'lat': coordy_1,
'name': 'Road1'},
{'node2': 'lon':coordx_2,
'lat': coordy_2,
'name': 'Road2'}, ...}
I also have a serie of individual points with their respective coordinates:
lon1, lat1 = coordx_3, coordy_3 #let's name it 'PointA'
lon2, lat2 = coordx_4, coordy_4 #let's name it 'PointB'
Coordinates from the Graph
and from the individual points are in EPSG:4326
.
I am trying to identify which node in the Graph
is the closest to each set of coordinates.
E.g: Which node is the closest to PointA
and which one is the closest to PointB
I found some codes online that allow the computation of the shortest distance between two points but I can't seem to manage to apply it to the Graph
I'm working with as I keep getting :
AttributeError: 'tuple' object has no attribute 'items'
Is there a way to do that?