【问题标题】:Get nearest node along nearest edge沿最近边获取最近节点
【发布时间】:2020-09-17 07:27:26
【问题描述】:

我正在关注 gboeing 在这篇帖子中的回复 https://github.com/gboeing/osmnx/issues/269 并使用 osmnx Docker 映像,但我收到了错误 AttributeError: module 'osmnx' has no attribute 'great_circle_vec'

Docker 似乎确实有最新的 0.16 osmnx 版本,并且当前的文档没有提到这个功能被弃用或私有。建议的代码已有一年半的历史,所以可能发生了一些变化。有没有人有一个当前的解决方案来沿着最近的边缘获取最近的节点?

【问题讨论】:

    标签: python osmnx


    【解决方案1】:

    【讨论】:

    • 感谢您指出这一点。事后看来应该是显而易见的。但是我确实对您对原始问题的回答有疑问,即在最近的边缘上找到最近的点。我看到您的内置解决方案找到了最近边缘的最近节点。 osmnx中是否有内置方法来获取最近边缘上最近点的坐标?
    • 不,不是内置的。
    • 谢谢。我能够使用原始帖子中的部分代码来做到这一点。我会在这里发布以防万一有人感兴趣。
    【解决方案2】:

    如果有人感兴趣,我可以根据原始 github 问题编写一些代码,以在最近的边缘上获得最近的 lat/lng。它看起来像这样:

    def nearest_point_on_edge(G, lat, lng, edge):
        ''' Return nearest point to lat/lng on edge 
        '''
        orig_point = Point(lng, lat)
        a_point = Point(G.nodes[edge[0]]['x'], G.nodes[edge[0]]['y'])
        b_point = Point(G.nodes[edge[1]]['x'], G.nodes[edge[1]]['y'])
        a_latlng = (G.nodes[edge[0]]['y'], G.nodes[edge[0]]['x'])
        b_latlng = (G.nodes[edge[1]]['y'], G.nodes[edge[1]]['x'])
        dist_ab = LineString([a_point, b_point]).project(orig_point)
        projected_orig_point = list(LineString([a_point, b_point]).interpolate(dist_ab).coords)
        nearest_latlng = (projected_orig_point[0][1], projected_orig_point[0][0])
        return nearest_latlng
    

    【讨论】:

      猜你喜欢
      • 2021-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多