4

I'm getting a strange type error with Osmnx that I haven't been able to find any other threads or information on. I have used this library on a different machine in the past, and with a fresh Anaconda install and fresh installation of osmnx, I'm getting a type error over passing 'crs'.

I initially had trouble even importing the package as this user experienced: Cannot import name 'CRS' from 'pyproj' for using the osmnx library

I installed an older (.11) version and the required packages, and now osmnx is importing fine, but using even example code:

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

gives the error

---------------------------------------------------------------------------
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

I like to think I have thoroughly lurked through enough threads to believe this is a novel issue based on my install, but any help would be appreciated.

relevant versions

pyproj 2.4.2.post1
osmnx .11
rtree .9.4
geopandas .7.0
mhansen2
  • 43
  • 4
  • This problem can be avoided by installing OSMnx according to its documented installation [instructions](https://osmnx.readthedocs.io/). See also https://stackoverflow.com/a/62958055/7321942 – gboeing May 13 '21 at 04:06

2 Answers2

2

Looks like Geopandas 0.7 updated their CRS object type to be a pyproj.CRS instead of a string. The osmnet library was having a similar issue.

You can resolve this by reverting to an older version of geopandas:

conda install geopandas=0.6.3 -c conda-forge

And maybe submit a bug report to the osmnx developers as well!

Blake
  • 36
  • 1
  • 2
  • The past couple of releases of OSMnx have [required](https://github.com/gboeing/osmnx/blob/master/requirements.txt) `geopandas>=0.7` – gboeing Jun 15 '20 at 21:34
2

Using osmnx==0.14.1 made it work for me.