I am trying to use networkx for analysing networks which I represented in QGIS as a line shapefile and a point shapefile. If I import only the lines shapefile using networkx.read_shp('lines.shp') I can already do some of the analysis I want, but I cannot figure out how to do import also the point shapefile with the nodes. I need that because in some of my networks not all the edges go in a straight line from one node to the other and converting only the lines.shp networkx creates a node for each "bending" of the lines, and also because I would like to store in networkx both the coordinates and the attributes given to the points in the shapefile attribute table (exactly as when reading the lines.shp).

Both if I try networkx.read_shp('lines.shp','points.shp') or networkx.read_shp('points.shp') alone, I get the same error: "add_node() takes exactly 2 arguments (3 given)" referring to line 88 in https://networkx.github.io/documentation/stable/_modules/networkx/readwrite/nx_shp.html#read_shp ( net.add_node((g.GetPoint_2D(0)), attributes ).

Does anyone have suggestions on how to correctly read a point shapefile?

(In case that matters, I am using QGIS 2.18.17 with Python 2.7 and networkx 2.0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.