Sunday, February 27, 2011

Introducing (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:

>>> 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


Michele said...

I'm sure that is all very helpful and cool and interesting but seriously could you get just a little bit more nerdy? :)

unmitigated me said...

Yeah. I am a damn bright woman, and I have NO clue what that is. Maybe I can just scold you for taking so long to post it?

Sprite's Keeper said...

Your mother would be so proud.. :-)

Captain Dumbass said...

I'm not a bright woman like Unmitigated so I have no idea what you're talking about either, but your mom said to come check out your blog and you should always listen to your mother.

Ben Reilly said...

Gah, it helps the code came over all wonky. It is autoposted from here. Anyway, it is really just adding some stuff to a library build by people way, way smarter than I.

Funny enough, I'm actually working on cooler stuff at work at the moment (real time power outage viewer for the public). And also my more next post all about conservation.

Thanks for visiting all!

Jenni said...

I though I was a nerd with my Jedi knowledge. Well done.

gretchen said...

Well put. Nx_spatial is one of my favorite subjects, and of all the blogs I've read which discuss it, yours is by far the most engrossing. Okay, I'm lying, I don't have a clue. I'm just here because your mother told me to come here. She's very persuasive. You're very smart.