首页 文章

OSMnx在基本使用时给出“TypeError:query必须是字符串或查询字符串列表”

提问于
浏览
0

按照安装OSMnx(包括显式安装 spatialindex )的说明进行操作后

brew install spatialindex
pip install osmnx

运行第一个基本的例子

import osmnx as ox
G = ox.graph_from_place('Manhattan Island, New York City, New York, USA', network_type='drive')
ox.plot_graph(ox.project_graph(G))

在项目的readme中,我明白了

Traceback (most recent call last):
  File "/Users/Rax/Documents/Projects/Coding/Python/maps/test.py", line 23, in <module>
    G = ox.graph_from_place('Manhattan Island, New York City, New York, USA', network_type='drive')
  File "/usr/local/lib/python2.7/site-packages/osmnx/core.py", line 1850, in graph_from_place
    raise TypeError('query must be a string or a list of query strings')
TypeError: query must be a string or a list of query strings

如何让OSMnx运行此错误?

2 回答

  • 0

    这可能是因为有了

    from __future__ import unicode_literals
    

    在你的代码中,since包括它将所有字符串转换为 unicode 类型,而API需要类型为 string 的参数 . 如果存在,删除它将防止发生错误 .

  • 0

    另见:https://github.com/gboeing/osmnx/issues/185

    OSMnx与Python 2和3兼容,因此您无需从将来的包中导入即可使用它 . 如果您将来使用Python 2并导入unicode_literals,则所有字符串都将是unicode类型 . 正如您在文档中看到的那样,graph_from_place要求查询的类型为字符串,而不是类型为unicode .

相关问题