You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用OSMnx的project_graph方法报错:'DataFrame'无'crs'属性

OSMnx project_graph 调用报错解决

运行代码

# 从地址获取路网,仅包含地址沿路网1km范围内的节点
G = ox.graph_from_address(
    address="350 5th Ave, New York, NY",
    dist=1000,
    dist_type="network",
    network_type="drive",
)

# 将路网投影到UTM(自动计算投影带)
G_projected = ox.project_graph(G)

报错信息

AttributeError                            Traceback (most recent call last)
Cell In [22], line 10
      2 G = ox.graph_from_address(
      3     address="350 5th Ave, New York, NY",
      4     dist=1000,
      5     dist_type="network",
      6     network_type="drive",
      7 )
      9 # you can project the network to UTM (zone calculated automatically)
---> 10 G_projected = ox.project_graph(G)

File ~/opt/anaconda3/envs/ox/lib/python3.11/site-packages/osmnx/projection.py:144, in project_graph(G, to_crs)
    141 if "simplified" in G.graph and G.graph["simplified"]:
    142     # if graph has previously been simplified, project the edge geometries
    143     gdf_edges = utils_graph.graph_to_gdfs(G, nodes=False, fill_edge_geometry=True)
--> 144     gdf_edges_proj = project_gdf(gdf_edges, to_crs=gdf_nodes_proj.crs)
    145 else:
    146     # if not, you don't have to project these edges because the nodes
    147     # contain all the spatial data in the graph (unsimplified edges have
    148     # no geometry attributes)
    149     gdf_edges_proj = utils_graph.graph_to_gdfs(G, nodes=False, fill_edge_geometry=False).drop(
    150         columns=["geometry"]
    151     )
...
   5900 ):
   5901     return self[name]
-> 5902 return object.__getattribute__(self, name)

AttributeError: 'DataFrame' object has no attribute 'crs'

排查结果

已确认 G.graph['crs'] 返回值为 'epsg:4326'

问题根源

通过conda安装的OSMnx版本为1.0.1,与示例文件依赖的1.2.2版本不符,版本差异导致该错误。

解决步骤

通过pip安装指定版本的OSMnx,操作如下:

conda create -n ox_that_work
conda activate ox_that_work
conda install pip
# 安装OSMnx依赖包
pip install -r requirements.txt
# 安装1.2.2版本的OSMnx
pip install osmnx==1.2.2
# 安装依赖列表中未包含的descartes和scikit-learn
pip install descartes scikit-learn

内容的提问来源于stack exchange,提问作者lorenzo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 05:55:30