首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用networkx.algorithms.approximation.steinertree.steiner_tree提取Steiner树时的错误

使用networkx.algorithms.approximation.steinertree.steiner_tree提取Steiner树时的错误
EN

Stack Overflow用户
提问于 2019-08-01 10:13:27
回答 1查看 919关注 0票数 1

我导出了两组数据:

  1. 作为.shp文件从QGIS导出的道路数据。
  2. 从QGIS导出为.shp文件的节点点层(long,lat)

我想使用networkx库来提取连接给定道路上所有节点的Steiner树。为了做到这一点,我在jupyter笔记本上编写了以下代码:

代码语言:javascript
复制
import networkx as nx #importing the NetworkX library
Road = nx.read_shp('proj_data/roads/cmbRoads.shp') #Reading Road Data 
Base = nx.read_shp('proj_data/bs/bsSnapped.shp') #Reading Terminal Node Data
nodes = list(Base.nodes) #Creating list of terminal nodes
from networkx.algorithms import approximation as ax
st_tree = ax.steinertree.steiner_tree(Road,nodes,weight='length')

直到Steiner树提取的所有代码行都已执行,没有任何问题。我收到以下错误消息:

代码语言:javascript
复制
---------------------------------------------------------------------------
NetworkXNotImplemented                    Traceback (most recent call last)
<ipython-input-5-99884445086e> in <module>
      1 from networkx.algorithms import approximation as ax
----> 2 st_tree = ax.steinertree.steiner_tree(Road,nodes,weight='length')

<c:\users\nandula\appdata\local\programs\python\python37\lib\site-packages\decorator.py:decorator-gen-849> in steiner_tree(G, terminal_nodes, weight)

c:\users\nandula\appdata\local\programs\python\python37\lib\site-packages\networkx\utils\decorators.py in _not_implemented_for(not_implement_for_func, *args, **kwargs)
     80             raise nx.NetworkXNotImplemented(msg)
     81         else:
---> 82             return not_implement_for_func(*args, **kwargs)
     83     return _not_implemented_for
     84 

<c:\users\nandula\appdata\local\programs\python\python37\lib\site-packages\decorator.py:decorator-gen-848> in steiner_tree(G, terminal_nodes, weight)

c:\users\nandula\appdata\local\programs\python\python37\lib\site-packages\networkx\utils\decorators.py in _not_implemented_for(not_implement_for_func, *args, **kwargs)
     78         if match:
     79             msg = 'not implemented for %s type' % ' '.join(graph_types)
---> 80             raise nx.NetworkXNotImplemented(msg)
     81         else:
     82             return not_implement_for_func(*args, **kwargs)

NetworkXNotImplemented: not implemented for directed type

任何关于我在这里可能做错了什么的洞察力,或者我可能以一种警觉的方式来完成这件事(可能是地质公园),都是有帮助的。

注意:我没有使用QGIS本身的处理工具箱,因为我需要在CentOS服务器上运行这段代码,因为我的个人计算机内存不足(数据集相当大)。

EN

回答 1

Stack Overflow用户

发布于 2019-08-01 12:01:33

问题是,您从QGIS数据创建的图形似乎是一个有向图,该算法仅用于无向图。

我建议您通过使用Roadnx.is_multigraphical来检查您的nx.is_multigraphical图的哪种类型。

您可以转换为一个无向图undirected_roads = nx.Graph(Road),然后调用算法ax.steinertree.steiner_tree(undirected_roads,nodes,weight='length')。但是,您将根据原始图的不对称程度而松散一些信息。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57306734

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档