如何找到最靠近坐标点的networkx节点-python

时间:2020-10-21 14:58:48

标签: python coordinates networkx

我用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'

有办法吗?

0 个答案:

没有答案
相关问题