Using GDAL/OGR is there a way to convert an SHP, KML, or PostGIS line layer into a network of nodes and segments so it can be used in packages such as networkx?
5 Answers
Ben Reilly recently posted a link on another question to his utilitynetwork (now nx_spatial) Python package, which uses the OGR bindings to convert data into networkx DiGraphs.
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 http://www.ridethecity.com/
app.
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...)
-
+1 for you. I'm looking at moving away from openstreet and postgis data due to data limitations and the fact that we're ditching postgis for now. We usually provide our own data that is far better than Openstreet, but at the same time we don't want to be limited to pgrouting. The other issue is that let's say we want to implement a pythonic or arcgis-friendly garbage collection or chinese postman or Traveler sales man problems.– dassoukiCommented Aug 5, 2010 at 13:30
-
Have you looked at SpatiaLite? This would give you an OpenSource spatial database that if file-based and platform independent. I haven't used it, but it appears that there is routing capability with SpatiaLite <gaia-gis.it/spatialite/spatialite-network-2.3.1.html>– DavidFCommented Aug 5, 2010 at 13:50
-
Also, thanks for bringing NetworkX to my attention. This looks like are really cool Python module.– DavidFCommented Aug 5, 2010 at 19:39
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).
-
+1 ... I'm not sure what you mean by the wrong platform? I understand your explanation, and it really blows that I can't convert the data into nodes and weights. the only 2 programs that do that from shp files are TransCAD and EMME2/3– dassoukiCommented Aug 13, 2010 at 17:30
-
By "wrong platform" I just meant that Boundary Generator was written for the ArcGIS environment, at least for now. :) It would need some adaptation to work with OGR. (Also needed would be a significant bit of new code to discover coincident endpoints from lines, as opposed to coincident edges from polygons. I might add this to the next version if/when I have the time. It seems like it could be very useful.)– Dan S.Commented Aug 17, 2010 at 22:34
Judging from the networkx list of importable graph formats and formats supported by GDAL, I doubt such a conversion is possible.
-
that's a crappy deal. So How can I do network analysis then?– dassoukiCommented Aug 5, 2010 at 12:53
-
@dassouki - Start an open source project! It's on my list, but way down at the moment. I'd like the opportunity to collaborate on this if other are interested though.– fmarkCommented Aug 5, 2010 at 14:28
-
-
@dassouki - Sounds exciting! What stage is the project at? The homepage says
TranspoTools Will be here shortly
. Is there any code on the google-code repository? Everything I could see was empty.– fmarkCommented Aug 5, 2010 at 14:37 -
@dassouki - Just to confirm, I don't know much about the transport analysis field (my GIS interest lies not much farther beyond calculating network distance at this stage), but would be happy to collaborate on an
ogr2networkx
type tool.– fmarkCommented Aug 5, 2010 at 14:40
There is some geodjango code in MarineMap that might be adaptable for the task.
-
cool we can discuss this to fulfill your goal of ogr2netx ahmed at elegantdesigns.ca– dassoukiCommented Aug 5, 2010 at 14:57
GML
, the former refers toGeography Markup Language
while the latter isGraph Modelling Language
.