Pragmatic Geographer

SOFTWARE GEOGRAPHY ECONOMICS HISTORY

Introducting (Belatedly) Nx_spatial

It’s been more or less done a while, but here is finally a blog post about it.

nx_spatial is a collection of addon functions for the networkx python graph library. What can you do with it?

  1. Load GIS formats into networkx graphs (where you can do all sorts of crazy analytics on them)
  2. Perform upstream and downstream traces with stopping points.
  3. Set sources and find/repair edges that don’t have the correct to/from nodes.

Example from the wiki:

1
2
3
4
5
6
7
import nx_spatial as ns
net = ns.read_shp('/shapes/lines.shp')
net.edges() [[(1.0, 1.0), (2.0, 2.0)], [(2.0, 2.0), (3.0, 3.0)], [(0.9, 0.9), (4.0, 2.0)]]
net.nodes() [(1.0, 1.0), (2.0, 2.0), (3.0, 3.0), (0.9, 0.9), (4.0, 2.0)]
source = (2.0, 2.0)
ns.setdirection(net, source)
net.edges() [[(2.0, 2.0), (1.0, 1.0)], [(2.0, 2.0), (3.0, 3.0)], [(0.9, 0.9), (4.0, 2.0)]]

Available on pypi or bitbucket. Eventually I want to integrate it with networkx trunk (loading shapefiles is already in 1.4).

Posted via email from The Pragmatic Geographer

Comments