从0.5.1升级到0.8.2后,图\u中的osmnx TypeError from \u polygon

2024-06-01 01:59:01 发布

您现在位置:Python中文网/ 问答频道 /正文

去年在osmnx完成了我的论文工作之后,我又回到了Python的PTSD中。但随着2017年ACS 5年期估计数据的发布,我还有一些新的数据分析要做。所以我把我的osmnx更新到了0.8.2,做了conda更新--all-c conda forge,然后启动了我的旧笔记本。你知道吗

它主要工作,但我得到一个错误的图形从\ u多边形函数。你知道吗

TypeError                                 Traceback (most recent call last)
<ipython-input-60-96e1e789c1a5> in <module>()
---> 58     network, network_stats, tract_polygon = load_network(optimal_tracts, utm_crs)
     59 

<ipython-input-56-3036c449a01f> in load_network(opt_tracts, my_crs)
     34 
---> 35     net = ox.core.graph_from_polygon(projected_circle,network_type='bike')
     36 

/Users/tom/anaconda/lib/python2.7/site-packages/osmnx/core.pyc in 
graph_from_polygon(polygon, network_type, simplify, retain_all, 
truncate_by_edge, name, timeout, memory, max_query_area_size, 
clean_periphery, infrastructure, custom_filter)
   1741    max_query_area_size=max_query_area_size,
   1742    infrastructure=infrastructure, custom_filter=custom_filter)
-> 1743         G_buffered = create_graph(response_jsons, name=name, 
retain_all=True, network_type=network_type)
   1744         G_buffered = truncate_graph_polygon(G_buffered, 
polygon_buffered, retain_all=True, truncate_by_edge=truncate_by_edge)
   1745 

/Users/tom/anaconda/lib/python2.7/site-packages/osmnx/core.pyc in 
create_graph(response_jsons, name, retain_all, network_type)
   1358     # add length (great circle distance between nodes) attribute to each edge to
   1359     # use as weight
-> 1360     if len(G.edges) > 0:
   1361         G = add_edge_lengths(G)
   1362 

TypeError: object of type 'instancemethod' has no len()

到目前为止,这些软件包仍然很好地配合在一起。projected_circle似乎被正确地创建为UTM lat long多边形(电子邮政编码:32617,北卡罗来纳州夏洛特市)。这是相关代码。(opt_tracts是一组普查区域的地理数据框架)。你知道吗

def load_network(opt_tracts,my_crs):    

 tract_poly=opt_tracts.unary_union

 projected_circle,projection = ox.projection.project_geometry(tract_poly,crs={'init': my_crs}, to_latlong=True)

 net = ox.core.graph_from_polygon(projected_circle,network_type='bike')

 net_stats = ox.stats.basic_stats(net,area=8047)

 return (net, net_stats, tract_poly)

下面是控制台输出:

Got all network data within polygon from API in 1 request(s) and 0.61 seconds
Creating networkx graph from downloaded OSM data...
Created graph with 11,371 nodes and 22,550 edges in 1.10 seconds

Tags: infromnetstatstypenetworkallgraph
1条回答
网友
1楼 · 发布于 2024-06-01 01:59:01

您安装了什么版本的networkx?你知道吗

我建议您创建一个新的虚拟环境,在其中安装OSMnx,然后从那里运行您的jupyter笔记本,如:

conda create -c conda-forge -n OX python=3 osmnx notebook

另见:https://osmnx.readthedocs.io/en/stable/#installation

相关问题 更多 >