using Gdal/ OGR is there a way to convert a shp, kml, or PostGIS line layer into a network of nodes and segments so it can be used in packages such as networkx?
You haven't mentioned specifically what kind of network analysis you want to do, but if you are interested in routing, there are a couple of options:
PgRouting http://pgrouting.postlbs.org/ works with data in PostGIS to do routing analysis. It supports the Shortest Path Dijkstra, Shortest Path A*, Shortest Path Shooting Star and Traveling Salesperson (TSP) algorithms. It also does driving distance calculations. A list of example apps using PgRouting can be found at
http://pgrouting.postlbs.org/wiki/pgRoutingDemo PgRouting drives the Ride the City
The OpenRouter project
http://wiki.osgeo.org/wiki/OpenRouter. This project looks interesting, but not particularly mature at this point.
(Apologies for the quoted URLs, but I don't have enough cred to post >1 URl...)
I think the answer depends. Most GIS formats do not explicitly include adjacency information (e.g. there are no indicators in a .shp full of simple line features to indicate that two features share a common endpoint), which is a deal-breaker for reading them directly into a network.
From a cursory peek at the code, it looks like the utilitynetwork package linked by scw will re-discover that information only if the endpoints are bit-for-bit identical. This might be good enough for most needs, including yours! (I could be wrong about this, since it was indeed only a cursory peek.)
For something more robust -- for example, you may wish to create new nodes in the network where two edges cross, or you'd like to handle perturbations that make overlapping endpoints very slightly different -- you'll have to look for an approach that inspects the geometry more deeply.
I have done something similar with Boundary Generator to recover network adjacency information from polygons: wrong platform, language and geometric primitive for you, unfortunately. However, it may be insightful as to how to approach robustness issue(s).
There is some geodjango code in MarineMap that might be adaptable for the task.