caesar0301 / s2g

(S)hapefile to(2) (G)raph/network converter in Python
https://pypi.python.org/pypi/s2g
MIT License
24 stars 8 forks source link

New to python, do we have to save the graph and if so how? #11

Open IssBjorn opened 1 year ago

IssBjorn commented 1 year ago

I've had my computer running for seven days converting a shapefile to a graph, I used this code:

from s2g import ShapeGraph
import fiona
from shapely.geometry import shape, LineString

shp = r"C:\Users\Tom\Documents\NorthAmerica.shp"

with fiona.open(shp) as source:
    geoms = []
    for r in source:
        s = shape(r['geometry'])
        if isinstance(s, LineString):
            geoms.append(s)

# create ShapeGraph object from a list of lines
sg = ShapeGraph(geoms, to_graph=False)

# detect major components
mc = sg.gen_major_components()
# major components are mc[2]

# convert the largest component to networkx Graph
graph = sg.to_networkx()  # equivalently sg.graph
plt.savefig(r"C:\Users\Tom\Documents\graph.png")

was I supposed to save it to somewhere because it's finished but I don't see any kind of output in the command line.