我用Graph
创建了一个Networkx
,其节点如下所示:
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'}, ...}
我还有一系列带有各自坐标的点:
lon1, lat1 = coordx_3, coordy_3 #let's name it 'PointA'
lon2, lat2 = coordx_4, coordy_4 #let's name it 'PointB'
Graph
和各个点的坐标在EPSG:4326
中。
我正在尝试确定Graph
中的哪个节点最接近每组坐标。
例如:哪个节点最接近PointA
,哪个节点最接近PointB
我在网上发现some codes可以计算两点之间的最短距离,但是随着我不断获得,我似乎无法设法将其应用于我正在使用的Graph
上:
AttributeError: 'tuple' object has no attribute 'items'
有办法吗?