【问题标题】:Python - Getting "TypeError: argument of type 'CRS' is not iterable" with Osmnx packagePython - 使用 Osmnx 包获取“TypeError:'CRS' 类型的参数不可迭代”
【发布时间】:2020-06-04 07:31:28
【问题描述】:

我在使用 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

【问题讨论】:

标签: python osmnx


【解决方案1】:

看起来 Geopandas 0.7 updated 他们的 CRS 对象类型是 pyproj.CRS 而不是字符串。 osmnet 库也有类似的问题。

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

conda install geopandas=0.6.3 -c conda-forge

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

【讨论】:

  • OSMnx 过去的几个版本有requiredgeopandas&gt;=0.7
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-26
    • 1970-01-01
    • 2022-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-23
    相关资源
    最近更新 更多