goulu / Goulib

library of useful Python code for scientific + technical applications
GNU Lesser General Public License v3.0
42 stars 6 forks source link

GeoGraph to NetworkX #12

Closed 168-B closed 4 years ago

168-B commented 4 years ago

I tried to transform GeoGraph object result from graph.euclidean_minimum_spanning_tree to NetworkX but error has shown.

Euclidean Minimum Spanning Tree (EMST)

from Goulib import graph
points_emst = graph.euclidean_minimum_spanning_tree(points_array)
print(type(points_emst))

Convert GeoGraph to NetworkX object

graph.to_networkx_graph(points_emst, create_using='Geograph')

I found error "Input is not a correct NetworkX graph" when converting

Is there something I miss? Thanks in advance.

goulu commented 4 years ago

Hi !

the EMST part looks correct. What do you get as type printed by the last line ? It should be a Goulib.graph.GeoGraph

so you don't need to use to_networkx_graph, since your points_emst is actually already a GeoGraph, which is already a descendant class of networkx.MultiGraph.

Moreover, the correct syntax to "cast" the result to a regular nx graph would be :

g=graph.to_networkx_graph(points_emst, create_using=nx.Graph()) # not a string, nor class

I just pushed a new version in 'develop' branch with tests that clarify (and check) this.

168-B commented 4 years ago

Thank you for clarifying.