gboeing / osmnx

OSMnx is a Python package to easily download, model, analyze, and visualize street networks and other geospatial features from OpenStreetMap.
https://osmnx.readthedocs.io
MIT License
4.85k stars 824 forks source link

TypeError: unhashable type: 'list' #255

Closed Senousi closed 5 years ago

Senousi commented 5 years ago

This issue tracker is for reporting bugs or proposing new features. Please ask "how-to" questions on https://stackoverflow.com/ instead. Before you proceed, please read the contributing guidelines in this repo's CONTRIBUTING.md.

If you installed OSMnx via conda and are experiencing installation problems, please open an issue at https://github.com/conda-forge/osmnx-feedstock/issues

If you're having trouble with OSMnx, first search the previously opened issues (and Stack Overflow) to see if the problem has already been noted. If not, fill in the template below:

Problem description (what did you do, what did you expect to happen, and what actually happened)

I obtained this error TypeError: unhashable type: 'list' when trying to simplify the network of Beijing city.

The error as follows:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-116aa73ddefd> in <module>()
      3 # simplify network with strict mode turned off
      4 network_walk_projected_simpl = network_walk_projected.copy()
----> 5 network_walk_projected_simpl = ox.simplify_graph(network_walk_projected_simpl, strict=False)
      6 
      7 

~\Anaconda3\lib\site-packages\osmnx\simplify.py in simplify_graph(G, strict)
    237 
    238     # construct a list of all the paths that need to be simplified
--> 239     paths = get_paths_to_simplify(G, strict=strict)
    240 
    241     start_time = time.time()

~\Anaconda3\lib\site-packages\osmnx\simplify.py in get_paths_to_simplify(G, strict)
    155     # first identify all the nodes that are endpoints
    156     start_time = time.time()
--> 157     endpoints = set([node for node in G.nodes() if is_endpoint(G, node, strict=strict)])
    158     log('Identified {:,} edge endpoints in {:,.2f} seconds'.format(len(endpoints), time.time()-start_time))
    159 

~\Anaconda3\lib\site-packages\osmnx\simplify.py in <listcomp>(.0)
    155     # first identify all the nodes that are endpoints
    156     start_time = time.time()
--> 157     endpoints = set([node for node in G.nodes() if is_endpoint(G, node, strict=strict)])
    158     log('Identified {:,} edge endpoints in {:,.2f} seconds'.format(len(endpoints), time.time()-start_time))
    159 

~\Anaconda3\lib\site-packages\osmnx\simplify.py in is_endpoint(G, node, strict)
     82         # if there is more than 1 OSM ID in the list of edge OSM IDs then it is
     83         # an endpoint, if not, it isn't
---> 84         return len(set(osmids)) > 1
     85 
     86     else:

TypeError: unhashable type: 'list'

What operating system, architecture, Python version, and OSMnx version are you using?

windows 10 ram 48 python 3.6 OSMnx last version (0.9)

Complete list of your environment's packages and their versions (for example, run conda list or pip list then paste the output below, between the two "details" tags)

# Paste the output of your Python packages and their versions here, between these two "details" tags ``` # packages in environment at C:\Users\*****\Anaconda3: # # Name Version Build Channel _ipyw_jlab_nb_ext_conf 0.1.0 py36he6757f0_0 affine 2.2.1 pypi_0 pypi alabaster 0.7.10 py36hcd07829_0 altair 2.2.2 py36_1001 conda-forge altgraph 0.16.1 pypi_0 pypi anaconda custom py36h363777c_0 anaconda-client 1.6.5 py36hd36550c_0 anaconda-navigator 1.6.9 py36hc720852_0 anaconda-project 0.8.0 py36h8b3bf89_0 asn1crypto 0.22.0 py36h8e79faa_1 astroid 1.5.3 py36h9d85297_0 astropy 2.0.2 py36h06391c4_4 attrs 18.2.0 pypi_0 pypi auto-py-to-exe 2.4.2 pypi_0 pypi automat 0.7.0 pypi_0 pypi babel 2.5.0 pypi_0 pypi backports 1.0 py36h81696a8_1 backports.shutil_get_terminal_size 1.0.0 py36h79ab834_2 beautifulsoup4 4.6.3 pypi_0 pypi bitarray 0.8.1 py36h6af124b_0 bkcharts 0.2 py36h7e685f7_0 blas 1.0 mkl blaze 0.11.3 py36h8a29ca5_0 bleach 2.0.0 py36h0a7e3d6_0 blosc 1.14.4 h6538335_1000 conda-forge bokeh 0.12.10 py36h0be3b39_0 boost 1.65.1 py36_4 anaconda boost-cpp 1.65.1 hfa6e2cd_4 anaconda boto 2.48.0 py36h1a776d2_1 bottle 0.12.13 pypi_0 pypi bottle-websocket 0.2.9 pypi_0 pypi bottleneck 1.2.1 py36hd119dfa_0 branca 0.3.0 py_0 conda-forge bs4 0.0.1 pypi_0 pypi bzip2 1.0.6 hfa6e2cd_5 anaconda ca-certificates 2018.11.29 ha4d7672_0 conda-forge cachecontrol 0.12.3 py36hfe50d7b_0 certifi 2018.11.29 py36_1000 conda-forge cffi 1.10.0 py36hae3d1b5_1 chardet 3.0.4 py36h420ce6e_1 click 6.7 py36hec8c647_0 click-plugins 1.0.4 py_0 conda-forge cligj 0.5.0 pypi_0 pypi cloudpickle 0.4.0 py36h639d8dc_0 clyent 1.2.2 py36hb10d595_1 colorama 0.3.9 py36h029ae33_0 comtypes 1.1.2 py36heb9b3d1_0 conda 4.6.2 py36_0 conda-forge conda-build 3.0.27 py36h309a530_0 conda-env 2.6.0 0 conda-forge conda-verify 2.0.0 py36h065de53_0 console_shortcut 0.1.1 h6bb2dd7_3 constantly 15.1.0 pypi_0 pypi contextlib2 0.5.5 py36he5d52c0_0 cryptography 2.4.2 py36h7a1dbc1_0 cssselect 1.0.3 pypi_0 pypi curl 7.63.0 h2a8f88b_1000 cycler 0.10.0 py36h009560c_0 cython 0.26.1 py36h18049ac_0 cytoolz 0.8.2 py36h547e66e_0 dask 0.15.3 py36h396fcb9_0 dask-core 0.15.3 py36hd651449_0 datashape 0.5.4 py36h5770b85_0 decorator 4.3.0 pypi_0 pypi descartes 1.1.0 py_2 conda-forge distlib 0.2.5 py36h51371be_0 distributed 1.19.1 py36h8504682_0 docker-py 1.10.6 pypi_0 pypi docker-pycreds 0.3.0 pypi_0 pypi docutils 0.14 py36h6012d8f_0 eel 0.9.10 pypi_0 pypi entrypoints 0.2.3 py36hfd66bb0_2 et_xmlfile 1.0.1 py36h3d2d736_0 expat 2.2.5 he025d50_0 anaconda ez-setup 0.9 pypi_0 pypi fastcache 1.0.2 py36hffdae1b_0 fastparquet 0.2.1 pypi_0 pypi filelock 2.0.12 py36hd7ddd41_0 findspark 1.3.0 pypi_0 pypi fiona 1.7.13 pypi_0 pypi flask 0.12.2 py36h98b5e8f_0 flask-cors 3.0.3 py36h8a3855d_0 folium 0.1.5 pypi_0 pypi freetype 2.8 h51f8f2c_1 anaconda freexl 1.0.5 hfa6e2cd_0 anaconda future 0.17.1 pypi_0 pypi gdal 2.3.2 pypi_0 pypi geographiclib 1.49 py_0 conda-forge geopandas 0.4.0 pypi_0 pypi geopy 1.17.0 py_0 conda-forge geos 3.6.2 he025d50_2 conda-forge geotiff 1.4.2 hd5bfa41_0 anaconda get_terminal_size 1.0.0 h38e98db_0 gevent 1.2.2 py36h342a76c_0 gevent-websocket 0.10.1 pypi_0 pypi glob2 0.5 py36h11cc1bd_1 greenlet 0.4.12 py36ha00ad21_0 h5py 2.8.0 py36hfa6e2cd_0 conda-forge hdf4 4.2.13 h712560f_2 anaconda hdf5 1.10.1 h98b8871_1 anaconda heapdict 1.0.0 py36h21fa5f4_0 html5lib 0.999999999 py36ha09b1f3_0 hyperlink 18.0.0 pypi_0 pypi icc_rt 2017.0.4 h97af966_0 icu 58.2 ha66f8fd_1 anaconda idna 2.6 py36h148d497_1 imageio 2.2.0 py36had6c2d2_0 imagesize 0.7.1 py36he29f638_0 incremental 17.5.0 pypi_0 pypi intel-openmp 2018.0.0 hcd89f80_7 ipykernel 4.6.1 py36hbb77b34_0 ipython 6.1.0 py36h236ecc8_1 ipython_genutils 0.2.0 py36h3c5d0ee_0 ipywidgets 7.0.0 py36h2e74ada_0 isort 4.2.15 py36h6198cc5_0 itsdangerous 0.24 py36hb6c5a24_1 jdcal 1.3 py36h64a5255_0 jedi 0.10.2 py36hed927a0_0 jinja2 2.9.6 py36h10aa3a0_1 jpeg 9c hfa6e2cd_1001 conda-forge jsonschema 2.6.0 py36h7636477_0 jupyter 1.0.0 py36h422fd7e_2 jupyter_client 5.1.0 py36h9902a9a_0 jupyter_console 5.2.0 py36h6d89b47_1 jupyter_core 4.3.0 py36h511e818_0 jupyterlab 0.27.0 py36h34cc53b_2 jupyterlab_launcher 0.4.0 py36h22c3ccf_0 kealib 1.4.7 ha5b336b_5 anaconda kiwisolver 1.0.1 pypi_0 pypi krb5 1.16.1 hc04afaa_7 lazy-object-proxy 1.3.1 py36hd1c21d2_0 leuvenmapmatching 0.5.2 pypi_0 pypi libboost 1.67.0 hd9e427e_4 libcurl 7.63.0 h2a8f88b_1000 libgdal 2.2.2 h2727f2b_1 anaconda libiconv 1.15 h1df5818_7 anaconda libkml 1.3.0 he5f2a48_4 libnetcdf 4.4.1.1 h825a56a_8 anaconda libpng 1.6.36 h7602738_1000 conda-forge libpq 11.1 h3235a2c_0 libspatialindex 1.8.5 h6538335_2 anaconda libspatialite 4.3.0a h383548d_18 anaconda libssh2 1.8.0 h7a1dbc1_4 libtiff 4.0.9 h36446d0_2 anaconda libxml2 2.9.8 hadb2253_1 anaconda libxslt 1.1.32 hf6f1972_0 anaconda llvmlite 0.20.0 py36_0 locket 0.2.0 py36hfed976d_1 lockfile 0.12.2 py36h0468280_0 lxml 4.1.0 py36h0dcd83c_0 lzo 2.10 h6df0209_2 anaconda m2w64-expat 2.1.1 2 m2w64-gcc-libgfortran 5.3.0 6 m2w64-gcc-libs 5.3.0 7 m2w64-gcc-libs-core 5.3.0 7 m2w64-gettext 0.19.7 2 m2w64-gmp 6.1.0 2 m2w64-libiconv 1.14 6 m2w64-libwinpthread-git 5.0.0.4634.697f757 2 m2w64-xz 5.2.2 2 macholib 1.11 pypi_0 pypi markupsafe 1.0 py36h0e26971_1 matplotlib 3.0.0 pypi_0 pypi mccabe 0.6.1 py36hb41005a_1 menuinst 1.4.14 py36_1000 conda-forge mistune 0.7.4 py36h4874169_0 mkl 2018.0.0 h36b65af_4 mkl-service 1.1.2 py36h57e144c_4 mpmath 0.19 py36he326802_2 msgpack-python 0.4.8 py36h58b1e9d_0 msys2-conda-epoch 20160418 1 multipledispatch 0.4.9 py36he44c36e_0 munch 2.3.2 pypi_0 pypi navigator-updater 0.1.0 py36h8a7b86b_0 nbconvert 5.3.1 py36h8dc0fde_0 nbformat 4.4.0 py36h3a5bc1b_0 networkx 2.2 py_0 conda-forge nltk 3.2.4 py36hd0e0a39_0 nose 1.3.7 py36h1c3779e_2 notebook 5.0.0 py36hd9fbf6f_2 numba 0.35.0 np113py36_10 numexpr 2.6.2 py36h7ca04dc_1 numpy 1.15.2 pypi_0 pypi numpydoc 0.7.0 py36ha25429e_0 odo 0.5.1 py36h7560279_0 olefile 0.44 py36h0a7bdd2_0 openjpeg 2.3.0 h5ec785f_1 anaconda openpyxl 2.4.8 py36hf3b77f6_1 openssl 1.1.1a hfa6e2cd_1000 conda-forge osmnx 0.9 py_0 conda-forge packaging 16.8 py36ha0986f6_1 pandas 0.23.4 py36h830ac7b_1000 conda-forge pandoc 1.19.2.1 hb2460c7_1 pandocfilters 1.4.2 py36h3ef6317_1 parsel 1.5.0 pypi_0 pypi partd 0.3.8 py36hc8e763b_0 path.py 10.3.1 py36h3dd8b46_0 pathlib2 2.3.0 py36h7bfb78b_0 patsy 0.4.1 py36h42cefec_0 pcre 8.42 hd6b2f15_0 anaconda pefile 2018.8.8 pypi_0 pypi pep8 1.7.0 py36h0f3d67a_0 pickleshare 0.7.4 py36h9de030f_0 pillow 4.2.1 py36hdb25ab2_0 pip 19.0.1 pypi_0 pypi pkginfo 1.4.1 py36hb0f9cfa_1 ply 3.10 py36h1211beb_0 postgresql 11.1 h3235a2c_0 progress 1.3 py36hbeca8d3_0 proj4 4.9.3 hcf24537_7 anaconda prompt_toolkit 1.0.15 py36h60b8f86_0 psutil 5.4.0 py36h4e662fb_0 psycopg2 2.7.6.1 py36h7a1dbc1_0 py 1.4.34 py36ha4aca3a_1 py-boost 1.67.0 py36h8300f20_4 anaconda py2exe 0.9.2.2 pypi_0 pypi pyasn1 0.4.4 pypi_0 pypi pyasn1-modules 0.2.2 pypi_0 pypi pycodestyle 2.3.1 py36h7cc55cd_0 pycosat 0.6.3 py36_0 conda-forge pycparser 2.18 py36hd053e01_1 pycrypto 2.6.1 py36he68e6e2_1 pycurl 7.43.0.2 py36h7a1dbc1_0 pydispatcher 2.0.5 pypi_0 pypi pyflakes 1.6.0 py36h0b975d6_0 pygments 2.2.0 py36hb010967_0 pyhamcrest 1.9.0 pypi_0 pypi pyinstaller 3.4 pypi_0 pypi pylint 1.7.4 py36ha4e6ded_0 pyodbc 4.0.17 py36h0006bc2_0 pyopenssl 17.2.0 py36h15ca2fc_0 pyparsing 2.2.0 py36h785a196_1 pyproj 1.9.5.1 py36haf3c679_1006 conda-forge pyqt 5.9.2 py36h6538335_2 pyqt5 5.11.3 pypi_0 pypi pyqt5-sip 4.19.13 pypi_0 pypi pyreadline 2.1 py36_1000 conda-forge pysal 1.14.3 pypi_0 pypi pyshp 1.2.12 pypi_0 pypi pysocks 1.6.7 py36h698d350_1 pytables 3.4.4 py36_8 conda-forge pytest 3.2.1 py36h753b05e_1 pytest-runner 4.2 pypi_0 pypi python 3.6.3 h9e2ca53_1 python-dateutil 2.6.1 py36h509ddcb_1 python-snappy 0.5.3 pypi_0 pypi pytz 2017.2 py36h05d413f_1 pywavelets 0.5.2 py36hc649158_0 pywin32 223 py36hfa6e2cd_1 anaconda pywin32-ctypes 0.2.0 pypi_0 pypi pyyaml 3.12 py36h1d1928f_1 pyzmq 16.0.2 py36h38c27d9_2 qt 5.9.7 vc14h73c81de_0 qtawesome 0.4.4 py36h5aa48f6_0 qtconsole 4.3.1 py36h99a29a9_0 qtpy 1.3.1 py36hb8717c5_0 queuelib 1.5.0 pypi_0 pypi rasterio 1.0.9 pypi_0 pypi rasterstats 0.13.0 pypi_0 pypi requests 2.21.0 pypi_0 pypi retrying 1.3.3 pypi_0 pypi rope 0.10.5 py36hcaf5641_0 rtree 0.8.3 py36_1000 conda-forge ruamel_yaml 0.11.14 py36h9b16331_2 scikit-image 0.13.0 py36h6dffa3f_1 scikit-learn 0.19.1 py36h53aea1b_0 scipy 1.0.0 py36h1260518_0 scrapinghub 2.0.3 pypi_0 pypi scrapy 1.5.1 pypi_0 pypi seaborn 0.8.0 py36h62cb67c_0 service-identity 17.0.0 pypi_0 pypi setuptools 39.2.0 pypi_0 pypi shapely 1.6.4 py36hc90234e_1000 conda-forge shub 2.8.1 pypi_0 pypi simplegeneric 0.8.1 py36heab741f_0 simplejson 3.16.0 pypi_0 pypi singledispatch 3.4.0.3 py36h17d0c80_0 sip 4.19.8 py36h6538335_1000 conda-forge six 1.11.0 py36h4db2310_1 snowballstemmer 1.2.1 py36h763602f_0 snuggs 1.4.2 pypi_0 pypi sortedcollections 0.5.3 py36hbefa0ab_0 sortedcontainers 1.5.7 py36ha90ac20_0 sphinx 1.6.3 py36h9bb690b_0 sphinxcontrib 1.0 py36hbbac3d2_1 sphinxcontrib-websupport 1.0.1 py36hb5e5916_1 spyder 3.2.4 py36h8845eaa_0 sqlalchemy 1.1.13 py36h5948d12_0 sqlite 3.26.0 hfa6e2cd_1000 conda-forge statsmodels 0.8.0 py36h6189b4c_0 sympy 1.1.1 py36h96708e0_0 tblib 1.3.2 py36h30f5020_0 testpath 0.3.1 py36h2698cfe_0 thrift 0.11.0 pypi_0 pypi tk 8.6.8 hfa6e2cd_0 anaconda toolz 0.8.2 py36he152a52_0 tornado 4.5.2 py36h57f6048_0 tqdm 4.28.1 pypi_0 pypi traitlets 4.3.2 py36h096827d_0 twisted 18.9.0 pypi_0 pypi typing 3.6.2 py36hb035bda_0 unicodecsv 0.14.1 py36h6450c06_0 unknown 0.0.0 pypi_0 pypi urllib3 1.22 py36h276f60a_0 utm 0.4.2 pypi_0 pypi vc 14.1 h21ff451_3 anaconda vincent 0.4.4 py_1 conda-forge vs2015_runtime 15.5.2 3 anaconda w3lib 1.19.0 pypi_0 pypi wcwidth 0.1.7 py36h3d5aa90_0 webencodings 0.5.1 py36h67c50ae_1 websocket-client 0.53.0 pypi_0 pypi werkzeug 0.12.2 py36h866a736_0 wheel 0.29.0 py36h6ce6cde_1 whichcraft 0.5.2 pypi_0 pypi widgetsnbextension 3.0.2 py36h364476f_1 win_inet_pton 1.0.1 py36he67d7fd_1 win_unicode_console 0.5 py36hcdbd4b5_0 wincertstore 0.2 py36h7fe50ca_0 wrapt 1.10.11 py36he5f5981_0 xarray 0.11.0 pypi_0 pypi xerces-c 3.2.2 ha925a31_0 anaconda xlrd 1.1.0 py36h1cb58dc_1 xlsxwriter 1.0.2 py36hf723b7d_0 xlwings 0.11.4 py36hd3cf94d_0 xlwt 1.3.0 py36h1a4751e_0 xz 5.2.4 h2fa13f4_1001 conda-forge yaml 0.1.7 hc54c509_2 anaconda zict 0.1.3 py36h2d8e73e_0 zlib 1.2.11 h8395fce_2 anaconda zope-interface 4.5.0 pypi_0 pypi ```

Code snippet that independently and completely reproduces the issue

import os

os.environ["PROJ_LIB"] =r'C:\Users\*****\Anaconda3\Library\share'
import osmnx as ox
network_walk = ox.graph_from_place('Beijing, China', network_type='walk', which_result=2)
network_walk_projected = ox.project_graph(network_walk,to_crs={'proj':'longlat','epsg':'32750' ,'ellps':'WGS84', 'datum':'WGS84'}) #wgs 84 50S

ox.config(log_file=True, log_console=True, use_cache=True)
# simplify network with strict mode turned off
network_walk_projected_simpl = network_walk_projected.copy()
network_walk_projected_simpl = ox.simplify_graph(network_walk_projected_simpl, strict=False)

ox.save_graph_shapefile(network_walk_projected,filename='network_walk_projected_simple')
gboeing commented 5 years ago

Do not simplify your graph when you first create it if you want to manually simplify it later:

import osmnx as ox
ox.config(use_cache=True, log_console=True)
G = ox.graph_from_place('Beijing, China', network_type='walk', which_result=2, simplify=False)
G_simpl = ox.simplify_graph(G, strict=False)
G_proj = ox.project_graph(G_simpl,to_crs={'proj':'longlat','epsg':'32750' ,'ellps':'WGS84', 'datum':'WGS84'})
Senousi commented 5 years ago

Firstly thank you very much. I need an illustration of concerning the number of edges. where the number of edge for the original network graph in my code without using the simplfy_graph method is smaller than the simplified network graph for the same region

import geopandas as gpd
Bj_edges_walk_gpd = gpd.read_file(r'****\data\network_walk_projected\edges\edges.shp')

print(Bj_edges_walk_gpd.shape)

Bj_edges_walk_simpl_gpd = gpd.read_file(r'****\data\network_walk_projected_simple\edges\edges.shp')

print(Bj_edges_walk_simpl_gpd.shape)
(125305, 18) #not simplified
(136935, 18) # simplified

Can you help me to understand that?

gboeing commented 5 years ago

Without a standalone complete MWE it's impossible to guess the content of those files or what's going on there. The issue tracker is for reporting bugs in OSMnx or proposing new features. For how-to questions, please ask on StackOverflow.