【问题标题】:KeyError when finding culdesacs查找 culdesacs 时出现 KeyError
【发布时间】:2021-11-24 10:37:17
【问题描述】:

我有以下功能可以在给定位置查找 culdesacs

def find_culdesacs(graph):
    """
    Culdesacs are nodes with only one edge connection and which are not on the boundary of the OpenStreetMap.

    Parameters
    ----------
    :param graph: object: OGraph object from osm_request

    Returns
    -------
    :return culdesacs: list of node IDs

    """
    streets_per_node = graph.G.graph['streets_per_node']
    # parse out the data structure provided by OSM
    # nodes = streets_per_node.split(',')
    # streets_per_node = {node.split(':')[0][1:]: node.split(':')[1][1:].replace('}', '') for node in nodes}
    culdesacs = [key for key, value in streets_per_node.items() if int(value) == 1]
    return culdesacs

但是,运行代码时出现以下错误:

streets_per_node = graph.G.graph['streets_per_node']

KeyError: 'streets_per_node'

有人能帮忙弄清楚如何解决这个错误吗?

【问题讨论】:

  • 您需要提供完整的最小可重现代码 sn-p 以供其他人重现和解决此问题。

标签: python-3.x networkx osmnx


【解决方案1】:

尝试替换这个:

streets_per_node = graph.G.graph['streets_per_node']

与:

streets_per_node = graph.graph['streets_per_node']

或者以不同的方式命名函数变量。 检查这里的评论部分: https://geoffboeing.com/2016/11/osmnx-python-street-networks/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-25
    • 2015-09-12
    • 2014-09-09
    • 2016-03-18
    • 2021-02-18
    • 2013-05-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多