osmnx 查询 OpenStreetMap

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

我正在使用Python,我正在尝试使用osmnx来查询OpenStreetMap并获取有关意大利城市布雷西亚的数据。

这是我从文档复制的代码。

import osmnx as ox

place = "Brescia, Italy"
osmnx_buffer = 10000 # in metres
g = ox.graph.graph_from_place(place, buffer_dist=osmnx_buffer)
g = ox.projection.project_graph(g)

ox.plot_graph(g)

我唯一改变的是字符串的内容

place

问题是,当我运行脚本时,它永远不会回复(因此,永远不会绘制任何内容)。我尝试阅读文档并更改我的查询,但我不知道它出了什么问题。你能建议我如何让这个脚本工作吗?

我的目标是与

networkx
一起努力。

提前谢谢您。

python graph networkx openstreetmap osmnx
1个回答
0
投票

您的代码似乎一切正常(我刚刚成功运行了它)。但请注意,您传递的

buffer_dist
函数参数已被弃用。另外,如果您想知道 OSMnx 日志记录在做什么,请打开它。构建包含约 250 万个节点和约 500 万条边的完整模型需要几分钟的时间,然后进行所有适当的截断和拓扑校正。

这是示例代码以及日志输出:

import osmnx as ox
ox.settings.log_console = True  # turn on logging
place = "Brescia, Italy"

# buffer the study area by 10 km
geom = ox.geocode_to_gdf(place).iloc[0]["geometry"]
geom_proj, crs = ox.projection.project_geometry(geom)
geom_buff, _ = ox.projection.project_geometry(geom_proj.buffer(10000), crs=crs, to_latlong=True)

# get the graph and plot it
G = ox.graph_from_polygon(geom_buff)
Gp = ox.project_graph(G)
fig, ax = ox.plot_graph(Gp)

和日志输出:

2023-12-20 12:45:56 Retrieved response from cache file 'cache/39adbce181a495e998c06fd21bd65ad28d80e3d3.json'
2023-12-20 12:45:56 Created GeoDataFrame with 1 rows from 1 queries
2023-12-20 12:45:56 Projected GeoDataFrame to 'EPSG:32632 / WGS 84 / UTM zone 32N'
2023-12-20 12:45:56 Projected GeoDataFrame to 'EPSG:4326 / WGS 84'
2023-12-20 12:45:56 Projected GeoDataFrame to 'EPSG:32632 / WGS 84 / UTM zone 32N'
2023-12-20 12:45:56 Projected GeoDataFrame to 'EPSG:4326 / WGS 84'
2023-12-20 12:45:56 Projected GeoDataFrame to 'EPSG:32632 / WGS 84 / UTM zone 32N'
2023-12-20 12:45:56 Projected GeoDataFrame to 'EPSG:4326 / WGS 84'
2023-12-20 12:45:56 Requesting data from API in 6 request(s)
2023-12-20 12:45:57 Retrieved response from cache file 'cache/2e7b530676d51fb707ca5d490cea53497b235300.json'
2023-12-20 12:45:57 Retrieved response from cache file 'cache/ee58a27f7c210838eafe3cc95e2470d884a9582e.json'
2023-12-20 12:45:58 Retrieved response from cache file 'cache/8d11d09ff31df390c9837d54ee33d55d005e8fa5.json'
2023-12-20 12:45:59 Retrieved response from cache file 'cache/9a85fc97fe64f2d6acbdf37b8476f36ed11e98cd.json'
2023-12-20 12:46:00 Retrieved response from cache file 'cache/0636bb65f47203267ae6843d3abd4b2ed812ed9e.json'
2023-12-20 12:46:00 Retrieved response from cache file 'cache/0f4b714e6f9cd7bcabe129c5c6a294fc104b5381.json'
2023-12-20 12:46:00 Retrieved all data from API in 6 request(s)
2023-12-20 12:46:00 Creating graph from 2,465,008 OSM nodes and 271,692 OSM ways...
2023-12-20 12:46:20 Created graph with 2,465,008 nodes and 4,944,897 edges
2023-12-20 12:46:30 Added length attributes to graph edges
2023-12-20 12:46:30 Identifying all nodes that lie outside the polygon...
2023-12-20 12:46:45 Created nodes GeoDataFrame from graph
2023-12-20 12:46:45 Created r-tree spatial index for 2,465,008 geometries
2023-12-20 12:46:46 Identified 2,142,413 geometries inside polygon
2023-12-20 12:47:05 Removed 322,595 nodes outside polygon
2023-12-20 12:47:05 Truncated graph by polygon
2023-12-20 12:47:05 Begin topologically simplifying the graph...
2023-12-20 12:47:27 Identified 283,430 edge endpoints
2023-12-20 12:48:19 Simplified graph: 2,142,413 to 283,430 nodes, 4,294,956 to 686,891 edges
2023-12-20 12:48:19 Identifying all nodes that lie outside the polygon...
2023-12-20 12:48:21 Created nodes GeoDataFrame from graph
2023-12-20 12:48:21 Created r-tree spatial index for 283,430 geometries
2023-12-20 12:48:21 Identified 276,578 geometries inside polygon
2023-12-20 12:48:25 Removed 6,852 nodes outside polygon
2023-12-20 12:48:28 Removed 79 isolated nodes
2023-12-20 12:48:36 Got largest weakly connected component (272,847 of 276,499 total nodes)
2023-12-20 12:48:36 Truncated graph by polygon
2023-12-20 12:48:37 Counted undirected street segments incident on each node
2023-12-20 12:48:38 graph_from_polygon returned graph with 272,847 nodes and 665,586 edges
2023-12-20 12:48:39 Created nodes GeoDataFrame from graph
2023-12-20 12:48:42 Projected GeoDataFrame to 'EPSG:32632 / WGS 84 / UTM zone 32N'
2023-12-20 12:48:46 Created edges GeoDataFrame from graph
2023-12-20 12:48:47 Projected GeoDataFrame to 'EPSG:32632 / WGS 84 / UTM zone 32N'
2023-12-20 12:48:56 Created graph from node/edge GeoDataFrames
2023-12-20 12:48:57 Projected graph with 272847 nodes and 665586 edges
2023-12-20 12:48:57 Begin plotting the graph...
2023-12-20 12:49:06 Created edges GeoDataFrame from graph
2023-12-20 12:49:15 Created nodes GeoDataFrame from graph
2023-12-20 12:49:19 Finished plotting the graph
© www.soinside.com 2019 - 2024. All rights reserved.