I have a shapefile representing roads (LineStrings) and I need to transfer it to a networkx type (with the lengths as weights) so I can do some network analysis.

I have used the s2g library to do so and it worked well; but the generated shapegraph has random weights that do not correspond at all with the lengths of the roads (not even the same order of magnitude). I've never used this library before and did not find an answer in the source doc.

Does anyone know how to choose the weights (or how they are generated) using the s2g transform ?

If you know of any other way to get a networkx (or igraph) network from shapefiles that would be of great help. tried the read_shp method from networkx but it only links the edges of the lines and I lose the shape of the roads:

result with nx.read_shp

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.