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?
|
Ben Reilly recently posted a link on another question to his utilitynetwork Python package, which uses the OGR bindings to convert data into networkx DiGraphs. |
|||
|
|
|
Judging from the networkx list of importable graph formats and formats supported by GDAL, I doubt such a conversion is possible. |
|||||||||||
|
|
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 The OpenRouter project (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. |
|||
|

GML, the former refers toGeography Markup Languagewhile the latter isGraph Modelling Language. – fmark Aug 5 '10 at 14:57