通过 OSMnx 覆盖整个城市的行人过路处

问题描述 投票:0回答:1

我有兴趣提取整个城市(例如芝加哥)的所有人行横道(包括有标记和无标记的人行横道)。到目前为止,以下代码产生了我想要的许多交叉点,但许多交叉点似乎被遗漏了,而我可以在 OSM 中看到它们被映射到有问题的交叉点。我不知道我的列表中缺少什么而忽略了这些交叉点。我确实知道并非每个人行横道都在芝加哥的 OSM 中进行了映射,但我想知道如何修改此代码以确保捕获 OSM 中的每个人行横道功能。

import osmnx as ox

# Set console logging to True
ox.settings.log_console = True

# Set useful tags for walking network
useful_tags = ox.settings.useful_tags_way + [
    'crossing', 'crossing:uncontrolled', 'crossing:zebra', 'crossing:marked',
    'crossing:traffic_signals', 'crossing:school', 'crossing:island',
    'crossing:refuge_island', 'crossing:island:central',
    'crossing:island:central:traffic_signals', 'crossing:island:central:marked',
    'crossing:island:central:zebra', 'crossing:unmarked', 'highway:crossing',
    'pedestrian'
]

ox.config(use_cache=True, log_console=True, useful_tags_way=useful_tags)

# Download the network with specified tags
G = ox.graph_from_place(query='Chicago, Illinois, USA', network_type='walk', simplify=False, retain_all=True)

# Identify and remove non-walk edges
non_walk = []
for u, v, k, d in G.edges(keys=True, data=True):
    is_walk = "walk" in d and d["walk"] == "designated"
    is_crossing = (
        d.get("highway") in ["crossing", "pedestrian"] or
        "crossing" in d or
        "crossing:uncontrolled" in d or
        "crossing:raised" in d or
        "crossing:speed_table" in d or
        "crossing:hump" in d or
        "crossing:zebra" in d or
        "crossing:marked" in d or
        "crossing:traffic_signals" in d or
        "crossing:school" in d or
        "crossing:island" in d or
        "crossing:refuge_island" in d or
        "crossing:island:central" in d or
        "crossing:island:central:traffic_signals" in d or
        "crossing:island:central:marked" in d or
        "crossing:island:central:zebra" in d or
        "crossing:unmarked" in d or
        "highway:crossing" in d or
        "pedestrian" in d
    )

    # Include pedestrian crossings at intersections without traffic signals
    is_intersection = "highway" in d and d["highway"] == "uncontrolled_intersection"
    if is_intersection and not is_crossing:
        is_crossing = True

    # Exclude pedestrian sidewalks
    is_sidewalk = "sidewalk" in d
    if not is_walk and not is_crossing and not is_sidewalk:
        non_walk.append((u, v, k))

G.remove_edges_from(non_walk)
G = ox.utils_graph.remove_isolated_nodes(G)
G = ox.simplify_graph(G)

# Calculate and print total edge length
stats = ox.stats.basic_stats(G)
print("Total Edge Length:", stats["edge_length_total"])

# Plot the graph
ox.plot_graph(G, node_color="w", node_size=15, edge_color="b", edge_linewidth=0.5, figsize=(20, 20))

What I want (intersections on the right), and what's missing (intersections on the left)

我已经尝试了上面的代码,并在我的结果中看到(并在另一个窗口中查看地理包时),即使我知道某些人行横道位于十字路口的 OSM 中,它们也丢失了。

OSMnx Graph of Pedestrian Crossings in Chicago

openstreetmap osmnx
1个回答
0
投票

您说节点

9934869727
在 OSMnx 模型中缺失,但存在于 OSM 本身上。但是,您的代码似乎可以很好地捕获和建模它。如果您在代码执行过程中检查它在图表中的存在
G
,您可以准确地看到丢失它的位置:

import osmnx as ox
ox.settings.log_console = True
ox.settings.useful_tags_way += [
    'crossing', 'crossing:uncontrolled', 'crossing:zebra', 'crossing:marked',
    'crossing:traffic_signals', 'crossing:school', 'crossing:island',
    'crossing:refuge_island', 'crossing:island:central',
    'crossing:island:central:traffic_signals', 'crossing:island:central:marked',
    'crossing:island:central:zebra', 'crossing:unmarked', 'highway:crossing',
    'pedestrian'
]

G = ox.graph_from_place(query='Chicago, Illinois, USA', network_type='walk', simplify=False, retain_all=True)

node = 9934869727
node in G  # True

non_walk = []
for u, v, k, d in G.edges(keys=True, data=True):
    is_walk = "walk" in d and d["walk"] == "designated"
    is_crossing = (
        d.get("highway") in ["crossing", "pedestrian"] or
        "crossing" in d or
        "crossing:uncontrolled" in d or
        "crossing:raised" in d or
        "crossing:speed_table" in d or
        "crossing:hump" in d or
        "crossing:zebra" in d or
        "crossing:marked" in d or
        "crossing:traffic_signals" in d or
        "crossing:school" in d or
        "crossing:island" in d or
        "crossing:refuge_island" in d or
        "crossing:island:central" in d or
        "crossing:island:central:traffic_signals" in d or
        "crossing:island:central:marked" in d or
        "crossing:island:central:zebra" in d or
        "crossing:unmarked" in d or
        "highway:crossing" in d or
        "pedestrian" in d
    )

    # Include pedestrian crossings at intersections without traffic signals
    is_intersection = "highway" in d and d["highway"] == "uncontrolled_intersection"
    if is_intersection and not is_crossing:
        is_crossing = True

    # Exclude pedestrian sidewalks
    is_sidewalk = "sidewalk" in d
    if not is_walk and not is_crossing and not is_sidewalk:
        non_walk.append((u, v, k))

G.remove_edges_from(non_walk)
node in G  # True

G = ox.utils_graph.remove_isolated_nodes(G)
node in G  # True

G2 = ox.simplify_graph(G)
node in G2  # False

您的过滤器和图形简化正在删除您希望保留的功能。如果您将图表加载到 QGIS 中以直观地探索它,您可以看到发生了什么。这会将

graph_from_place
代码(蓝色)之后的图表与
remove_isolated_nodes
代码(红色)之后剩余的图表进行比较:

图中包含节点

9934869727
的部分仍然是一个断开的平凡环(红色)。当您简化图形时,默认情况下会删除这个琐碎的环。您可以以不同的方式参数化它:

G3 = ox.simplify_graph(G, remove_rings=False)
node in G3  # True

所以你的节点在简化后仍然存在。但考虑到图表的外观,我不确定您是否按照您想要的方式对其进行过滤。虽然我不确定您的用例和目标,所以我不能肯定地说。

无论哪种方式,这都是节点丢失的原因的答案。 OSMnx 正在正确地对所有内容进行建模:您只是过滤掉该节点周围的内容,从而产生一个在简化过程中被删除的微不足道的环。

© www.soinside.com 2019 - 2024. All rights reserved.