osmnx 调用 graph_from_bbox() 报告它需要 1 个位置参数,但是,help(ox.graph.graph_from_bbox) 似乎需要 4 个

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

我正在编写一个简单的测试驱动程序来生成一个 html 文件,为非常有限的区域显示两条可能的真实路线。当我运行 python 脚本时,我得到了一个我认为很容易解决的错误:“第 12 行,在 graph = ox.graph.graph_from_bbox(*bbox, network_type="drive") 类型错误:graph_from_bbox() 需要 1 个位置参数,但给出了 4 个位置参数(和 1 个仅关键字参数)”。

这是使用该函数的代码:

import osmnx as ox
import networkx as nx
import folium

# Configure timeout for HTTP requests
ox.settings.timeout = 180  # Set timeout to 180 seconds

# Define the bounding box as (north, south, east, west)
bbox = (37.5, 32.0, -94.0, -104.0)  # Approximate bounding box for OK, TX, KS

# Create the graph using the bounding box
graph = ox.graph.graph_from_bbox(*bbox, network_type="drive")

# Define start and end points (Oklahoma City to Dallas)
start_point = (35.4676, -97.5164)  # Oklahoma City
end_point = (32.7767, -96.7970)    # Dallas

# Find the nearest nodes in the road network
start_node = ox.distance.nearest_nodes(graph, X=start_point[1], Y=start_point[0])
end_node = ox.distance.nearest_nodes(graph, X=end_point[1], Y=end_point[0])

# Calculate the shortest path using Dijkstra's algorithm
shortest_path = nx.shortest_path(graph, source=start_node, target=end_node, weight='length')

# Create a map centered between the start and end points
route_map = folium.Map(location=[(start_point[0] + end_point[0]) / 2, (start_point[1] + end_point[1]) / 2], zoom_start=7)

# Extract route geometry and plot it on the map
route_coords = [(graph.nodes[node]['y'], graph.nodes[node]['x']) for node in shortest_path]
folium.PolyLine(route_coords, color="blue", weight=5, opacity=0.8).add_to(route_map)

# Add markers for start and end points
folium.Marker(location=start_point, popup="Start: Oklahoma City").add_to(route_map)
folium.Marker(location=end_point, popup="End: Dallas").add_to(route_map)

# Save the map to an HTML file
route_map.save("real_world_route_map.html")

由于这是我第一次使用 osmnx,我想我应该通过键入以下内容来检查该函数所需的详细信息:help(ox.graph.graph_from_bbox) 这是我看到的用法文本:

This function uses filters to query the Overpass API: you can either
specify a pre-defined `network_type` or provide your own `custom_filter`
with Overpass QL.

Use the `settings` module's `useful_tags_node` and `useful_tags_way`
settings to configure which OSM node/way tags are added as graph node/edge
attributes. You can also use the `settings` module to retrieve a snapshot
of historical OSM data as of a certain date, or to configure the Overpass
server timeout, memory allocation, and other custom settings.

Parameters
----------
bbox
    Bounding box as `(left, bottom, right, top)`. Coordinates should be in
    unprojected latitude-longitude degrees (EPSG:4326).
network_type
    {"all", "all_public", "bike", "drive", "drive_service", "walk"}
    What type of street network to retrieve if `custom_filter` is None.
simplify
    If True, simplify graph topology via the `simplify_graph` function.
retain_all
    If True, return the entire graph even if it is not connected. If
If
    False, retain only the largest weakly connected component.
truncate_by_edge
    If True, retain nodes outside bounding box if at least one of node's
    neighbors is within the bounding box.
custom_filter
    A custom ways filter to be used instead of the `network_type` presets,
    e.g. `'["power"~"line"]' or '["highway"~"motorway|trunk"]'`. If `str`,
    the intersection of keys/values will be used, e.g., `'[maxspeed=50][lanes=2]'`
    will return all ways having both maxspeed of 50 and two lanes. If
    `list`, the union of the `list` items will be used, e.g.,
    `['[maxspeed=50]', '[lanes=2]']` will return all ways having either
    maximum speed of 50 or two lanes. Also pass in a `network_type` that
    is in `settings.bidirectional_network_types` if you want the graph to
    be fully bidirectional.
    
    Returns
-------
    G

我收到的错误似乎表明只有 1 个位置,而不是函数帮助指示的 4 个。我错过了什么?

python geospatial osmnx
1个回答
0
投票

不客气,请随时向我寻求帮助

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