SouthForkResearch / pyGNAT

Geomorphic Network and Analysis Toolbox, redesigned using FOSS python libraries.
MIT License
2 stars 0 forks source link

Calculate branch IDs #9

Open jesselangdon opened 7 years ago

jesselangdon commented 7 years ago

Assign a unique identifier value to stream "branches". Stream branches are determine by a stream name (i.e. GNIS_Name, found in NHD), and then by stream order.

Required for:

Refer to arcpy GNAT Generate Stream Branches tool

MattReimer commented 7 years ago

For this one I would traverse the network graph using NetworkX and augment its attributes

Since NetworkX loads and maintains the attributes from the SHP file we should be able to just read and augment them:

jesselangdon commented 7 years ago

I don't know that get and set edge attributes will work in this case. I think in networkX graphs, different edges can have different attributes, but in the case of graphs coming from shapefiles, each edge has the same set of attributes. So running get_edge_attributes on a stream network graph, and (as an example) selecting every attribute named "GNIS_Name" will return every edge in the graph. I could be wrong though...

jesselangdon commented 7 years ago

You actually use 'add_edge'. Here's a simple solution I came up with:

https://github.com/SouthForkResearch/pyGNAT/commit/05483e6668f4256a34056435ae1a33967772eabc

MattReimer commented 7 years ago

That looks good but I worry that you're adding more edges to the network unnecessarily.

You can select subsets but it means something like this:

collectionofedges = []
for e in G.edges_iter():
   if G.get_edge_data(*e)['OBJECTID'] == id:
        collectionofedges.append(e)

or in one line:

collectionofedges = [e for e in G.edges_iter() if G.get_edge_data(*e)['OBJECTID'] == id]