Python - Getting "TypeError: argument of type 'CRS' is not iterable" with Osmnx package

Python - Getting "TypeError: argument of type 'CRS' is not iterable" with Osmnx package

我在使用 Osmnx 时遇到一个奇怪的类型错误,我无法找到任何其他主题或信息。我过去在另一台机器上使用过这个库,并且在全新安装 Anaconda 和全新安装 osmnx 时,我在传递 'crs'.

时遇到类型错误

最初我什至在导入包时遇到了问题,正如这位用户所经历的:Cannot import name 'CRS' from 'pyproj' for using the osmnx library

我安装了一个旧的 (.11) 版本和所需的包,现在 osmnx 导入正常,但甚至使用示例代码:

import osmnx as ox
G = ox.graph_from_place('Los Angeles, California', network_type='drive')
ox.plot_graph(G)

报错

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-2b688bf77702> in <module>
      2 graph = ox.gdf_from_place(place_name)
      3 ox.save_gdf_shapefile(city)
----> 4 city = ox.project_gdf(city)
      5 fig, ax = ox.plot_shape(city, figsize=(3,3))

~\Anaconda3\lib\site-packages\osmnx\projection.py in project_gdf(gdf, to_crs, to_latlong)
     98             # else, project the gdf to UTM
     99             # if GeoDataFrame is already in UTM, just return it
--> 100             if (gdf.crs is not None) and ('+proj=utm ' in gdf.crs):
    101                 return gdf
    102 

TypeError: argument of type 'CRS' is not iterable

我想我已经彻底潜伏在足够多的线程中,相信这是一个基于我的安装的新问题,但我们将不胜感激。

相关版本

pyproj 2.4.2.post1
osmnx .11
rtree .9.4
geopandas .7.0

Geopandas 0.7 updated their CRS object type to be a pyproj.CRS instead of a string. The osmnet 库似乎有类似的问题。

您可以通过恢复到旧版本的 geopandas 来解决此问题:

conda install geopandas=0.6.3 -c conda-forge

也许还可以向 osmnx 开发人员提交错误报告!

使用 osmnx==0.14.1 使它对我有用。